DEV Community

Siddharth Kanojiya
Siddharth Kanojiya

Posted on

Conditional Expressions in JavaScript | JavaScript #6

let a = prompt("hey whats is your age?");
a = Number.parseInt(a); // converting number into a string
if (a < 0) {
alert("This is an invalid age");
}
else if (a < 9) {
alert("You are kid and you cannot drive now")
}
else if (a < 18 && a >= 9) {
alert("You are kid and you can think of driving after 18 ")
}

else {
alert("you can drive now as you are above 18");
}

// Ternary operator eg in Js

console.log("you can", (a < 18 ? "not dive" : "drive"))

Top comments (1)

Collapse
 
goku_91 profile image
Si

Perfect explanation for new coder