JavaScript Program to find the largest of three numbers using nested if

In this program, you will learn how to find the largest of three numbers using nested if in JavaScript.


if(condition){
    if(condition){
         //statement
    }
}

JavaScript Program to find the largest of three numbers using nested if

Example: How to find the largest of three numbers using nested if in JavaScript

let x = prompt("Enter first number")
let y = prompt("Enter second number")
let z = prompt("Enter third number")

if (x > y) {
  if (x > z) {
    console.log("x is largest:" + x)
  }

} else if (y > z) {
  console.log("y is largest:" + y)
} else {
  console.log("z is largest:" + z)
}

Output:

Enter first number> 20
Enter second number> 30
Enter third number> 10
y is largest:30