Programming with JavaScript

⌘K
  1. Home
  2. Docs
  3. Programming with JavaScri...
  4. Example Programs
  5. Greatest of Two Numbers

Greatest of Two Numbers

Example 11

Write a JavaScript to find greatest of two numbers

const prompt = require("prompt-sync")();

let n1 = prompt("Enter the first number");
let n2 = prompt("Enter second number");

n1 = parseInt(n1);
n2 = parseInt(n2);

if (n1 > n2) {
  console.log(`${n1} is greater than ${n2}`);
} else {
  console.log(`${n2} is greater than ${n1}`);
}

Output

Loading

Views: 58

How can we help?

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments