Sure! Here’s a simple program in JavaScript to calculate the average of three numbers:
```javascript // Function to calculate the average of three numbers function calculateAverage(num1, num2, num3) { return (num1 + num2 + num3) / 3; }
// Test the function var number1 = 10; var number2 = 20; var number3 = 30;
var average = calculateAverage(number1, number2, number3); console.log(“The average is: “ + average); ```
In this program, we define a function called calculateAverage that takes three numbers as input parameters. Inside the function, we calculate the sum of the three numbers and divide it by 3 to get the average. The function then returns the average.
We then test the function by assigning three numbers to variables number1, number2, and number3. We call the calculateAverage function with these numbers as arguments and store the returned average in the average variable. Finally, we print the average to the console using console.log.
Loading...