jeudi 23 août 2018

How to use prompt, parseInt(), and 'if' and else between a range of numbers

Need help. I am pulling out my hair at this point. I have an exercise I can not get pass. I need to do the following:

'Prompt' the user for a number that is greater than 100 but less than 2,000 and store this as a variable named 'user'.

Write an 'if' statement that checks to see if 'user' is greater than 100 and less than 2000.

If it is then it should assign message1 to a variable named result. If it is not then it should assign message2 instead.

I need to use the following guidelines:
'user' should be a number, try using the 'parseInt()' function make sure you have an 'if' statement

My 'if' statement should have an 'else' attached to it

Finish the challenge by typing a number that is greater than 100 and less than 2000 into the prompt

The below is what I was given by the tutorial to start with:

var message1 = 'You are amazingly correct!';
var message2 = 'Awww, it looks like that number is not correct. Try 
again!';
// your code below here

I understand what I am looking at but I can't wrap my head around what I have been doing wrong. I have only been meeting the first 3 of the 4 guidelines (excluding the 'parseInt' and the 'prompt()'). The final part is just not working and I can't understand why...

Aucun commentaire:

Enregistrer un commentaire