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) } }

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
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, 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)

}

}

Expert Solution
steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Types of Loop
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-engineering and related others by exploring similar questions and additional content below.
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY