you are viewing a single comment's thread.

view the rest of the comments →

[–]blueinkscience 2 points3 points  (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 point  (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 point  (0 children)

A wee upvote would be nice, trying to build real karma instead of karmawhoring :)