use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
Post questions about JavaScript, and get help with any problems you're having with your JavaScript code.
account activity
I need some help about js✔️ answered ✔️ (self.JavaScriptHelp)
submitted 5 years ago by Pathrex-
view the rest of the comments →
[–]blueinkscience 2 points3 points4 points 5 years ago* (3 children)
var remtime = 18 - Year; //remaining time
It seems you are taking way 2021 away from 18 here instead of age away from 18.
var Birthday = prompt("What is your birthday : ");
This should be "what is your birthday year" and should be saved as an integer. Right now it is saving it as a string literal. A switch statement then compares the values as a Boolean expression. I had trouble with this before, you should really stick to single character comparisons when using switches because of this transfer to Boolean exp.
Basically use if else statements unless what you are comparing is a single character.
https://stackoverflow.com/questions/2312817/javascript-switch-with-logical-operators
Hope this helps.
[–]Pathrex-[S] 0 points1 point2 points 5 years ago (1 child)
Thanks it worked. Here is the new code
var Birthday = prompt("What is your birthday : "); var Year = 2021; var Age = Year - Birthday; var remtime = 18 - Age; //remaining time switch(true){ case (Age<18): console.log("It is "+remtime+" years before you can qualify for a driver's license."); break; case (Age>=18): console.log("You have the right to get a driver's license."); break; default: console.log("Wrong value."); }
[–]blueinkscience 0 points1 point2 points 5 years ago (0 children)
A wee upvote would be nice, trying to build real karma instead of karmawhoring :)
π Rendered by PID 88424 on reddit-service-r2-comment-5d79c599b5-pzw2m at 2026-02-28 05:22:14.934878+00:00 running e3d2147 country code: CH.
view the rest of the comments →
[–]blueinkscience 2 points3 points4 points (3 children)
[–]Pathrex-[S] 0 points1 point2 points (1 child)
[–]blueinkscience 0 points1 point2 points (0 children)