Find average of two numbers in JavaScript
In this tutorial, you are given two numbers. Write a JavaScript program to find the average of these two numbers.
Solution
To find the average of two numbers, find their sum using addition operator, and then divide the sum by 2 using division operator.
(a + b) / 2
Program
In the following program, we are given numbers in num1
and num2
. We find the average of num1
and num2
.
let num1 = 4;
let num2 = 8;
let sum = num1 + num2;
let average = sum / 2;
console.log(average);