V.Vidhya Logo

V.Vidhya

if-else (Conditional Statements)


Q1.

Consider the following program:

let x = 5;

if (x == 6) {
    console.log("Hello");
} 
else {
    console.log("Hi");
}

What will be the output in the console?

You have to predict the output yourself without running/executing the code.


Q2.

Consider the following program:

let x = 10; 
let y = 20;

if (x == 10) {     
    if (y == 20) {   
        console.log("x is 10 and y is 20");     
    }
    else {   
        console.log("x is 10 but y is not 20");     
    } 
}  
else {  
    console.log("x is not 10"); 
}

What will be the output in the console?

You have to predict the output yourself without running/executing the code.


Q3.

Consider the following program:

let age = 25;

if (age > 18)
    console.log("Adult");
else if (age > 12)
    console.log("Teenager");
else if (age > 5)
    console.log("Child");
else
    console.log("Toddler");

What will be the output in the console?

You have to predict the output yourself without running/executing the code.


Q4.

let x = 10;
let y = 20;

if (x > 5)
    console.log("A");
else if (y > 15)
    console.log("B");
else
    console.log("C");

What will be the output?

You have to predict the output yourself without running/executing the code.


Q5.

Create a system to calculate popcorn prices based on the bucket size customer asks for:

Here, the list for price per bucket-size is given -

Expected Output:

Enter the popcorn-bucket size: M

Price: 100

Q6.

Create a program to make a mini-calculator.

Take 2 numbers and the operator sign as input from the user, then give the result based on those taken values.

for e.g.

number1 : 3
number2 : 5

operator : *

// expected output
5 * 3 = 15

All the operators should be covered, i.e. +, -, *, /, %, **.


Prev Post
String Basics
Next Post
Logical Operators