Checking an if statement to see if a number is greater than another | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Checking an if statement to see if a number is greater than another

I’ve been given an question “write an if statement that checks to see if number is greater than 22. If it is then it should assign ‘This number is greater than 22’ to message. Line 2 is: var number = 29; Line 3 is: var message = ‘this number is smaller than 22’... Every time I write the if statement and change smaller than to greater than as instructed I get an error.. How can I fix this ?

28th Sep 2018, 12:48 AM
Junie B.
18 Answers
+ 2
Nguyễn Văn HoĂ ng wow!! thank you so much . i missed that completely đŸ€ŠđŸŸâ€â™‚ïž
28th Sep 2018, 6:10 AM
Junie B.
+ 2
Nguyễn Văn HoĂ ng your a rockstar . I had everything except for else and the 2nd result . your a rockstar man 😁😁 thank you.
28th Sep 2018, 11:51 AM
Junie B.
+ 2
Nguyễn Văn HoĂ ng I get the same answers but for some reason my time on site brings errors i email them and they told me , im sorry we gonna fix that refresh in another 20 mins. they told me i wasnt the only one having problems. đŸ‘‚đŸŸ
29th Sep 2018, 11:33 AM
Junie B.
+ 1
Your if statement should work when tried it with a different number.') <— thats the error message Nguyễn Văn HoĂ ng
28th Sep 2018, 3:15 AM
Junie B.
+ 1
Junie B. That sounds more like a message from a code-learning site than a message issued by the interpreter. I haven't seen your if statement yet, there is a possibility that you didn't get their assignment right. Sorry I'm still unable to help. Is this a quiz on SoloLearn? If not, would you mind telling me which IDE you were working with and which platform/browser you were testing on?
28th Sep 2018, 3:50 AM
HoĂ ng Nguyễn Văn
HoĂ ng Nguyễn Văn - avatar
+ 1
// your code below here if ('number > 22'); Nguyễn Văn HoĂ ng
28th Sep 2018, 4:29 AM
Junie B.
+ 1
Junie B. there are quotation marks around your condition, which makes it a string, and the block that follows will always be executed. if ('number > 22') // Logical Error if (number > 22) // Correct
28th Sep 2018, 5:20 AM
HoĂ ng Nguyễn Văn
HoĂ ng Nguyễn Văn - avatar
+ 1
Junie B. var number = 28; var message = 'This number is smaller than 22'; // your code below here if (number > 22) message = 'This number is greater than 22';
28th Sep 2018, 6:05 AM
HoĂ ng Nguyễn Văn
HoĂ ng Nguyễn Văn - avatar
+ 1
Nguyễn Văn HoĂ ng sorry but can i trouble you for one more. im studying and i really want to understand
28th Sep 2018, 6:33 AM
Junie B.
+ 1
Junie B. feel free to go.
28th Sep 2018, 8:24 AM
HoĂ ng Nguyễn Văn
HoĂ ng Nguyễn Văn - avatar
+ 1
Junie B. // your code below here if (number > 100 && number < 2000) result = message1; else result = message2;
28th Sep 2018, 11:39 AM
HoĂ ng Nguyễn Văn
HoĂ ng Nguyễn Văn - avatar
+ 1
let basket = ['banana', 'mango', 'cucumber', 'peach', 'apple']; for (let fruit in basket) console.log(fruit); The instructions on the site seems clear to me, which part of it you didn't understand? It would be uneffective if we go on like this. Programming is about the concepts, not the syntax.
29th Sep 2018, 4:57 AM
HoĂ ng Nguyễn Văn
HoĂ ng Nguyễn Văn - avatar
0
Can you provide the full error message or a link to your code? Line 2 and Line 3 contain no error from my observation.
28th Sep 2018, 2:39 AM
HoĂ ng Nguyễn Văn
HoĂ ng Nguyễn Văn - avatar
0
Nguyễn Văn HoĂ ng thank you, but everytime I insert the correct condition it shows im wrong with “your if statement should work when tried it with a different number.’) and when i change my message to “this number is smaller than 22” it say my condition is incorrect. its very confusing. sidenote my number is 28 “Var number = 28;”
28th Sep 2018, 5:36 AM
Junie B.
0
Junie B. sorry for taking your time. Since this is taken out of context, I'd suggest you show the whole program (what the site already done for you and also your solution) or link to where you were having the problem.
28th Sep 2018, 5:48 AM
HoĂ ng Nguyễn Văn
HoĂ ng Nguyễn Văn - avatar