Stuck in a control flow challenge -" Finish the challenge by passing the true clause.')" | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Stuck in a control flow challenge -" Finish the challenge by passing the true clause.')"

Hey there, I'm totally lost with this challenge... 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. My code: var message1 = 'You are amazingly correct!'; var message2 = 'Awww, it looks like that number is not correct. Try again!'; var user = Number('1000'); if (user>100 && user<2000) { console.log('You are amazingly correct!'); } else { console.log('Awww, it looks like that number is not correct. Try again!'); } EVERYTHING runs except I can't figure out the error: Finish the challenge by passing the true clause.') What am I doing wrong?

16th Aug 2018, 6:34 PM
Lu Me
Lu Me - avatar
12 Answers
+ 1
maybe prompt returns a string and so user should store a number bcos u r going to compare it against 100 and 2000 so promptString = prompt(...) and then user=parseInt(promptString) or user=prompt(...) parseInt(user)<100 or user=prompt (...) +user<100 /* bcos prefixing by a + sign tells the compiler to treat it as an integer */ let's squash ur nightmares ;)
16th Aug 2018, 8:32 PM
Harsh
+ 1
take input from user using prompt like so var user=prompt("enter number", "pls"); also, use messageN variables instead of rewriting the strings
16th Aug 2018, 6:40 PM
Harsh
+ 1
THANK YOU Harshvardhan Chawla! This is what I did: var user = prompt('enter number'); if (user>100 && user<2000) { alert('message1'); } else { alert('message2'); But now I get the prompt message1 or message2 instead. And now there's another error message : user should be a number, try using the parseInt() function.
16th Aug 2018, 7:00 PM
Lu Me
Lu Me - avatar
+ 1
message1 is a variable so no quotes, quotes are for strings similarly alert(message2)
16th Aug 2018, 7:01 PM
Harsh
+ 1
it's not about being dumb though, u r still learning and admitting that u need to learn is a positive trait... paste ur codepen link if possible here
16th Aug 2018, 7:51 PM
Harsh
+ 1
Got it!! Makes sense! I've tried alert, console, and even result... but now it worked! Still having the " user should be a number, try using the parseInt() function. I'll have nightmares with this challenge tonight!
16th Aug 2018, 8:22 PM
Lu Me
Lu Me - avatar
+ 1
YEESSSS! MY HERO! The first option worked! JavaScript is giving me a run for my money! I have to re-study conditionals HARD! THANK YOU SOOOO MUCH!
16th Aug 2018, 8:52 PM
Lu Me
Lu Me - avatar
0
Yes! I feel so dumb... but I still get the same errors and now there are no messages at all. UGH! when I try this code on CodePen it shows the messages, but not on the test.
16th Aug 2018, 7:34 PM
Lu Me
Lu Me - avatar
0
or wait, u said it works on codepen but not on test, paste the test code link too then (I think people do that here? I am new here too lol)
16th Aug 2018, 7:52 PM
Harsh
0
Thank you so much again! Here is the link: https://codepen.io/luciane5/pen/djBQVJ?editors=0011
16th Aug 2018, 7:55 PM
Lu Me
Lu Me - avatar
0
ok I re-read the question, it says to assign the result to variable, not to print in console so it should be result=messageN, no need for console.log - which wont be testable by this SL test I wud guess
16th Aug 2018, 7:58 PM
Harsh
0
yaaaay JavaScript is ur hero :p haha ur welcome
16th Aug 2018, 11:46 PM
Harsh