PLEASE guys someone modify it i have no idea why all of them false | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

PLEASE guys someone modify it i have no idea why all of them false

// Switch var age = prompt ("Please enter your age."); var age=1000 switch (age) { case age >=12: document.write("You are a child."); break; case age <= 18: document.write("You are a teenager."); break; case age < 98: document.write("You are getting old."); break; default: document.write("You did not enter an age."); }

13th May 2020, 1:35 PM
yassin tafouzert
yassin tafouzert - avatar
7 Answers
+ 3
switch-case cannot be used for relational operators other than == (that too without writing the operator). An example, switch(age){ case 12: document.write("12!");break; case 13: document.write("13!");break; default: document.write("Not 12/13!"); } If you want to check for other relations, use if-else if-else statements.
13th May 2020, 2:07 PM
Nikhil
Nikhil - avatar
+ 3
yassin tafouzert ,thanks for that question and Nikhil thanks for that answer 👌😄. I was also curious about the why after having also issues in setting correctly a valid switch and missed that part with strict equality. Also about your code, don't forget to consider that prompt method return a value of type string (even if you enter a number), so it will also bring you to the default case (originaly I thought it was your only issue there). So you'll need to convert that value with Number() method to check on strict equality or depending on how you'd like to use that value later.
13th May 2020, 3:09 PM
EmmanueLZ.
EmmanueLZ. - avatar
+ 1
thank you so much i really was waiting for explaining like this thank you again
13th May 2020, 2:17 PM
yassin tafouzert
yassin tafouzert - avatar
+ 1
You'r welcome, but just learning as you. Not a professional at all🙂.
13th May 2020, 3:21 PM
EmmanueLZ.
EmmanueLZ. - avatar
+ 1
But basically getting certificate here is only a matter of reading courses untill the end. It gives you overview and starting point but being skillfull is not about the numbers of certificate you got here, so yes i'm still a beginner with little experience 🤷🏻‍♂️.
13th May 2020, 3:35 PM
EmmanueLZ.
EmmanueLZ. - avatar
0
Hmm
14th May 2020, 6:39 PM
Daniel Adombire
Daniel Adombire - avatar
0
Please, I am a beginner I need help
14th May 2020, 6:41 PM
Daniel Adombire
Daniel Adombire - avatar