+ 1
JavaScript Control Flow exercise
Prompt the user for a number that is greater than 100 but less than 2000 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. <---> 1) 2) var message1 = 'You are amazingly correct!'; 3) var message2 = 'Awww, it looks like that number is not correct. Try again!'; 4) // your code below here 5) 6) 7)
5 odpowiedzi
+ 5
You were close, well, as per suggested, use parseInt to convert string input from prompt() into a number.
var user = parseInt(prompt('Enter a number greater than 100 and less than 2000'));
var message1 = 'You are amazingly correct!';
var message2 = 'Awww, it looks like that number is not correct. Try again!';
The input variable was named "user". You were comparing "num" which doesn't exist. The instruction said to assign either "message1" or "message2" to a variable named "result" not to show in JS console.
var result;
if (user>100 && user<2000){
result=message1;
}
else {
result=message2;
}
I'm not so sure what the second suggestion mean here -> "Finish the challenge by passing the true clause."
+ 2
Hey guys!
I am also stuck with this challenge. I have everything checked but the "Finish the challenge by passing the true clause.')
What on earth does this mean?
Any solution?
+ 2
Hi guys! Experiencing the same issue stuck with "Finish the challenge by typing a number that is greater than 100 and less than 2000 into the prompt." I have tested the code and when entered a number, the appropriate message appears. however, I am prompted twice. any solution is greatly appreciated.
Thanks!
+ 1
This is the code that I have so far:
var user = prompt('Enter a number greater than 100 and less than 2000')
var message1 = 'You are amazingly correct!';
var message2 = 'Awww, it looks like that number is not correct. Try again!';
if (num>100&&num<2000){
console.log(message1);
}
else {
console.log(message2);
}
The errors I am getting is: 1) user should be a number, try using the parseInt() function.
and 2) Finish the challenge by passing the true clause.')