Question: I am trying to make a while loop that checks for a condition from user input. If the user inputs anything except for valid integers,

I am trying to make a while loop that checks for a condition from user input. If the user inputs anything except for valid integers, the while loop requires the user to reenter until a valid integer is input. I have tested this code, but the while loop isn't overwriting the maxNotNumber variable when reentered. Please tell me what I'm doing wrong.

let min = 1;

//minimum number

let score = 0;

let max = Math.ceil(prompt("Enter a maximum number 1 or greater for the guessing game."));//asks for user's max number input and rounds any decimals up

maxNotNumber = Number.isInteger(max);//checks for nonnumbers

console.log(maxNotNumber);

//initial user max number input

let random = Math.ceil(Math.random() * (max - min) + min);

console.log(random);

//randomly generated number between 1 and user max

while (maxNotNumber != true) {//Illegal number check

maxNotNumber = Number.isInteger(max);//checks for nonnumbers

max = prompt("That's not a number. Try again.");

console.log("This is from the while loop for maxNotNumber. " + max);

// while (max < 1) {//Less than 1 check

// max = prompt("Needs to be 1 or greater.");

// }

}//max number parameter check

let guess = parseInt(prompt("Now guess the random number."));//asks user to guess randomly generated number, converts string to integer if necessary

let isNumber = Number.isInteger(guess);//Checks that input from user is integer

while (guess > max) {

let score = score++;//increments score each wrong guess

guess = prompt("Your guess is too high. Try again.");

while (guess < max) {

score = score++;//increments score each wrong guess

prompt("Your guess is too low. Try again.");

console.log("This is the console.log for score. " + score)

}

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!