AntonBrock
@AntonBrock
screen light

Правильно ли я делаю сравниваю среди множества переменных?

Гляньте пожалуйста, правильно ли я сравниванию переменные ? Из 5 итемов выбивают по либо 2 либо 3 почти каждый раз, такое ощущение, что я неверно сделал рандом. Сама проверка снизу, спасибо за помощь!

returnItemBoolianFour() {
        let booleanItemFour = [true, false]
        let randomBooleanItemFour = Math.floor(Math.random() * booleanItemFour.length);

        let booleanItemFour_two = [true, false]
        let randomBooleanItemFour_two = Math.floor(Math.random() * booleanItemFour_two.length);

        let booleanItemFour_three = [true, false]
        let randomBooleanItemFour_three = Math.floor(Math.random() * booleanItemFour_three.length);

        let booleanItemFour_four = [true, false]
        let randomBooleanItemFour_four = Math.floor(Math.random() * booleanItemFour_four.length);

        let booleanItemFour_five = [true, false]
        let randomBooleanItemFour_five = Math.floor(Math.random() * booleanItemFour_five.length);

        this.renderItemFour = randomBooleanItemFour
        this.renderItemFour_second = randomBooleanItemFour_two
        this.renderItemFour_three = randomBooleanItemFour_three
        this.renderItemFour_four = randomBooleanItemFour_four
        this.renderItemFour_five = randomBooleanItemFour_five
       
        if (randomBooleanItemFour == randomBooleanItemFour_two && randomBooleanItemFour_three &&  randomBooleanItemFour_four && randomBooleanItemFour_five ) { // сама проверка , тут думаю ошибка
             this.returnItemBoolianFour();
         }
}
  • Вопрос задан
  • 61 просмотр
Пригласить эксперта
Ответы на вопрос 1
Xuxicheta
@Xuxicheta
инженер
Если тебе нужен рандомный boolean, то зачем тут массивы городить
const randomBoolean = Math.random() > 0.5

и у тебя там не булеан выходит, а случайное целое от 0 до 1
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы