7. More practice with switch


#1


This code always returns the default switch. Why doesn't it return any other if i just put in an integer?


var answer = prompt("What's your age?");

switch(answer) {
  case answer > 18:
    console.log("That's great, in The Netherlands you are allowed to drink alcohol and drive a car!");
    break;
    case answer <= 18:
        console.log("You're still young you will get older adventually!");
        break;
    default:
        console.log("You didn't put any age in!");
        break;
  // Add your code here!
  
}


#2

HI the case doesn't take any conditon you just need to put it like that

var answer = prompt("What's your age?");
switch(answer) {
    case "18":
        console.log("That's great, in The Netherlands you are allowed to drink alcohol and drive a car!");
    break;
    ...

if you need of the codition you will use the if and else statement


#3

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.