Conditional Expressions in JavaScript

 console.log("Conditional Expressions in JS");

//"prompt" will always ask and "alert" will tell
const prompt = require("prompt-sync")();
let a = prompt("Hey what's your age ?");    //"prompt" will convert to a string
a = Number.parseInt(a); //Converting the string to a number
console.log(typeof a);
if (a < 0) {
    alert("This is an invalid age");
}
else if (a < 9) {
    alert("You are a kid and you cannot even think of driving");
}
else if (a < 18 && a >= 9) {
    alert("You are a kid and you can think of driving after 18");
}
else {
    alert("You can now drive as you are above 18");
}
console.log("Done");


OUTPUT :
We have to run above code in Google Chrome's Console by inspect
(Don't run above code in Visual Studio Code)
































Comments

Popular posts from this blog

Generators tutorial in Advance JavaScript

Document Object Module DOM querySelector and querySelectorAll tutorial in JavaScript

Find Even and Odd Numbers with Loops tutorial in JavaScript