QP School

Full Version: Find the min, max and avg of two numbers in JavaScript
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Code:
num1 = 10;
num2 = 20;
const min = (num1 < num2) ? num1 : num2;
const avg = (num1 + num2) / 2;
const max = (num1 > num2) ? num1 : num2;
document.write("Min = ", min);
document.write("<br>");
document.write("Avg = ", avg);
document.write("<br>");
document.write("Max = ", max);