Skip to content
Advertisement

Enter a number within a certain range, and then get the system to prompt me to input names for that number that has been entered?

I am trying to input a number between 1-10, if a number is entered which out of this range 3 consecutive times, the system should terminate. If the number is within the range, it should then prompt the user to enter names, which should match the number that was initially added. (So if 3 was inputted initially, the system to allow for 3 names to be added). May you direct me where I am going wrong?

JavaScript

Advertisement

Answer

You need to have the entire code in a while loop whose condition should depend on number of incorrect attempts ( count). Since you have not mentioned what needs to be done if the user enters the correct input ( say 3) ,i’m assuming it will take 3 names input and end ( in case you want to continue taking the names, remove the break condition mentioned in my code.

JavaScript

and the output is :

JavaScript
Advertisement