JavaScript Code

How to compare two numbers?

Problem Statement

given two numbers, write a JavaScript program to find a comparison between them: if first number is less than second number, first number is greater than second number, or if the two numbers are equal


to compare two numbers, we can use comparison operators greater than, and less than

we will use the above said operators in conditions of if-else-if statement to draw a comparison between the two given numbers


given two numbers are num1 and num2. draw a comparison between these two numbers

let num1 = 4;
let num2 = 8;

if ( num1 > num2 ) {
    console.log(`${num1} is greater than ${num2}`);
} else if ( num1 < num2 ) {
    console.log(`${num1} is less than ${num2}`);
} else {
    console.log('given numbers are equal');