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