top of page

If else : Exercise: Practice conditional statements

  • Writer: satyanarayan behera
    satyanarayan behera
  • Aug 25, 2022
  • 1 min read

Complete the following steps to create: Are You Old Enough?

  1. Declare a variable age using the var keyword and set it to the number 10.

  2. Add an if statement that checks if the value of the age variable is greater than or equal to the number 65. Inside the if block, console.log the sentence: "You get your income from your pension".

  3. Add an "else if", where you'll check if the value of the age is less than 65 and greater than or equal to 18. Inside this "else if" block, type "console.log" and then "Each month you get a salary".

  4. Add another "else if", and this time check if the value of the age is under 18. Inside the "else if" block, "type console.log" and then "You get an allowance".

  5. Add an "else" statement to capture any other value. Inside the block, type "console.log" and then "The value of the age variable is not numerical".



var age=10;

if (age>=65){

console.log("You get your income from your pension");

}else if (age < 65 && age >=18){

console.log("Each month you get a salary");

}else if (age < 18){

console.log("You get an allowance");

}else {

console.log("The value of the age variable is not numerical");

}



You get an allowance


Recent Posts

See All
For Loop : Task 1

Write a "for" loop that will perform exactly the same repetitive code as this: console.log(1) console.log(2) console.log(3)...

 
 
 
Task 2: Using the logical || operator

Imagine you are coding a video game. Currently, you’re about to code some snippets related to the game over condition. You need to code a...

 
 
 

Comments


  • alt.text.label.LinkedIn

©2022 by Satya

bottom of page