Мой цикл, когда я не работает гладко, где я ошибся?Javascript

Форум по Javascript
Ответить
Anonymous
 Мой цикл, когда я не работает гладко, где я ошибся?

Сообщение Anonymous »


Код: Выделить всё

//  NUMBER GUESSING GAME

// Html dom elements to work with

const rollBtn = document.getElementById("rollBtn");
let guess = document.getElementById("guess");
let display = document.getElementById("display");

// Other variables needed
let running = true;
let attempts = 0;
const minNum = 1;
const maxNum = 100;
const answer = Math.floor(Math.random() * (maxNum - minNum + 1));

rollBtn.onclick = function(){

while(running){
guess = Number(guess.value);
if(isNaN(guess)){
display.textContent = `Please, input a valid number between ${minNum} - ${maxNum}`;
}
else if(guess < minNum || guess > maxNum){
display.textContent = `Please, input a number between ${minNum} - ${maxNum}`;
}else{
attempts++;

if(guess < answer){
display.textContent = "Too Low, Try again";
}
else if(guess > answer){
display.textContent = "Too High, Try again";
}
else{
display.textContent =`Correct! the answer is ${answer}, It took you ${attempts} attempt(s)`;

running = false;
}

}
}
}< /code>





Number Guessing Game



Enter a number:

Roll





Это то, что показывает мне консоль, но не может решить проблему:
Скрипт, завершенная с помощью времени, AT:
rollbtn.onclick@http://127.0.0.0.1:5500/index.jindex.jindex. /> eventhandlernonnull*@http://127.0.0.1:5500/index.js:16:1

Подробнее здесь: https://stackoverflow.com/questions/796 ... i-go-wrong
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Javascript»