QP School
Find the min, max and avg of two numbers in JavaScript - Printable Version

+- QP School (https://qomplainerzschool.lima-city.de)
+-- Forum: Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=3)
+--- Forum: JavaScript Tutorials (https://qomplainerzschool.lima-city.de/forumdisplay.php?fid=6)
+--- Thread: Find the min, max and avg of two numbers in JavaScript (/showthread.php?tid=4082)



Find the min, max and avg of two numbers in JavaScript - Qomplainerz - 04-04-2023

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);