Wikipedia

Search results

Sunday, July 2, 2023

Conditional expressions in JavaScript | JavaScript Tutorial

 let a = prompt("Hey whats your age?")

a=Number.parseInt (a) //converting string into a number

console.log(typeof a)

if (a<0){

  alert ("this is invalid age")

}

else if(a<9)

{

  alert("You are a kid")

}

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")

}


// Ternary Operator


console.log("You can",a<18?"not drive": "drive");




//homework-Explore switch statement and write a basic program.

let b= prompt("Enter the number of the week day:")

b=Number.parseInt(b)

switch(b){

  case 1:

    console.log("Today is Sunday");

    break;

  case 2:

    console.log("Today is Monday")

     break;

  case 3:

    console.log("Today is Tuesday")

     break;

  case 4:

    console.log("Today is Wednesday")

     break;

  case 5:

    console.log("Today is Thursday")

     break;

  case 6:

    console.log("Today is Friday")

     break;

  case 7:

    console.log("Today is Saturday")

     break;

  default :

  console.log(" The value is undefined")

}


No comments:

Post a Comment

Rediscovering Ourselves Through Meditation in the Fast Lane

 Rediscovering Ourselves Through Meditation in the Fast Lane In the hustle and bustle of our speedy lives, it's easy to get lost in the ...