0
anyone can help me with this code, please?
//once it gets in the loop, it never stops running no matter what number i enter, even if it's the right number let yourNumber = parseInt(prompt("Enter your number")); while (!yourNumber) ( yourNumber = parseInt(prompt("Enter a valid number")) ) const finalNumber = Math.floor(Math.random() + yourNumber * 2); console.log (finalNumber) let game = parseInt(prompt("Enter your first guess")); while (game !== finalNumber) { if (game > finalNumber) { guess = parseInt(prompt("too high, put a new guess")); } else { guess = parseInt(prompt("too low, put a new guess")) } } console.log ("that is correct!")
3 Respostas
+ 6
Why do you copy-paste the code into the description? Simply LINK your code.
+ 2
Debug:
let yourNumber = parseInt(prompt("Enter your number"));
/* BUG
while (!yourNumber) ( // bug, bug
yourNumber = parseInt(prompt("Enter a valid number"))
) // bug
*/
const finalNumber = Math.floor(Math.random() + yourNumber * 2);
console.log (finalNumber)
let guess = parseInt(prompt("Enter your first guess")); //debug 2
while (guess !== finalNumber) { //debug 3
if (guess > finalNumber) { //debug 4
guess = parseInt(prompt("too high, put a new guess"));
} else {
guess = parseInt(prompt("too low, put a new guess"))
}
}
console.log ("that is correct!")
0
i'm using the website version, and still can't figure out where some features exist