d2jsp
Log InRegister
d2jsp Forums > Off-Topic > Computers & IT > Programming & Development > Help
Add Reply New Topic New Poll
Member
Posts: 1,609
Joined: Aug 13 2009
Gold: Locked
Apr 2 2022 11:09pm
working on switch sattements...
i change the ages to a different number but i only get the default as my output.. why?

let ages= "45"

switch (ages){
case "ages<18":
console.log("cannot party with us");
break;
case "ages >=18":
console.log("party over here");
break;
default:
console.log("I do not recognize your age")

}

Member
Posts: 6,350
Joined: Feb 7 2009
Gold: 33.37
Apr 3 2022 03:36am
I would suggest a if statement instead:

var ages = 45

if (ages < 18) {
console.log("cannot party with us");
} else if (ages >= 18) {
console.log("party over here");
} else {
console.log("I do not recognize your age");
}
Go Back To Programming & Development Topic List
Add Reply New Topic New Poll