Javascript Check Number Help

Chris S

Retired
Messages
2,055
Reaction score
1
Points
38
I need some help checking a number and seeing if it is between two numbers and if it is, continue, if not, ask for another number.

I don't have much to start with, but I do have this


Code:
var num = prompt("Enter number to view more information about an album 1-6 Only");
  var num = parseInt(num);
 
Last edited:

blobtech

New Member
Prime Account
Messages
17
Reaction score
0
Points
1
This should work...

Code:
var num = parseInt(prompt("Enter number to view more information about an album 1-6 Only"));
while(num < 1 || num > 6)
{
     num = parseInt(prompt("Enter a valid number between 1 and 6 to view more information about the album"));
}

What the code does:
It first asks for a number, and then keeps repeating to ask while the condition "num is smaller then 1 or bigger then 6" is still true.
 

Chris S

Retired
Messages
2,055
Reaction score
1
Points
38
that's what I was missing...thanks. I kept on trying to do and if else statement...I had a general idea of what I was trying to achieve but wasn't sure how to go about doing it.

Nothing like going above and beyond. This was kind of for a homework assignment. The original assignment was have a box pop up and ask for a number. when the number is given...display the array corresponding to that number. Well, I wanted to do the check against that. Once again thanks for helping me.
 
Top