Nouvelle formation ! Tous les codeurs devraient apprendre l'IA générative !
Essayez une leçon gratuite0
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 ?
18 Réponses
+ 2
Nguyễn Văn Hoàng wow!! thank you so much . i missed that completely 🤦🏾♂️
+ 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.
+ 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. 👂🏾
+ 1
Your if statement should work when tried it with a different number.') <— thats the error message Nguyễn Văn Hoàng
+ 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?
+ 1
// your code below here
if ('number > 22'); Nguyễn Văn Hoàng
+ 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
+ 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';
+ 1
Nguyễn Văn Hoàng sorry but can i trouble you for one more. im studying and i really want to understand
+ 1
Junie B. feel free to go.
+ 1
Junie B.
// your code below here
if (number > 100 && number < 2000)
result = message1;
else
result = message2;
+ 1
Nguyễn Văn Hoàng have anything for this https://foundations.nycda.tools/challenges/required-exercise-looping-part-2
+ 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.
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.
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;”
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.