Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Find the min, max and avg of two numbers in JavaScript
#1
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);
Also follow me on Youtube for videos about video games:
https://www.youtube.com/channel/UCxfkGVU...2mQ/videos
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  JavaScript - Array find() example (returns the value) Qomplainerz 0 541 04-04-2023, 08:12 AM
Last Post: Qomplainerz
  JavaScript exercises and solutions - Swap two numbers Qomplainerz 0 400 04-04-2023, 07:54 AM
Last Post: Qomplainerz
  JavaScript - The find() method Qomplainerz 0 398 04-04-2023, 07:40 AM
Last Post: Qomplainerz

Forum Jump:


Users browsing this thread: 8 Guest(s)