Explore BrainMass
Share

Explore BrainMass

    JavaScript code to find average

    This content was COPIED from BrainMass.com - View the original, and get the already-completed solution here!

    Write a JavaScript code to find average of numbers entered by the user. Ask the user to enter five number. Take each input one at a time. Save them into variables. Find the average and display the following grades: 'The grade is Fail' if the average is below 40, Pass if it's between 40 to 70, distinction if it's above 69, otherwise display an input error message.

    © BrainMass Inc. brainmass.com October 10, 2019, 8:27 am ad1c9bdddf
    https://brainmass.com/computer-science/javascript/javascript-code-average-627044

    Solution Preview

    Open the attached average.html file to see the working solution. The file contains the solution given below.

    <html>
    <body>

    <script type="text/javascript">

    var num1;
    var num2;
    var num3;
    var num4;
    var num5;

    var average =0;

    document.write("<br />");

    document.write("*** Average of Five Numbers ***");

    document.write("<br />");
    document.write("<br />");

    input = window.prompt('Please enter first number', ' ');
    num1 = ...

    Solution Summary

    A very simple and easy to understand javascript code to find average of input numbers. Window.prompt method is used to take five inputs from a user. The inputs are converted into float and the average is computed. The output grade is then displayed using if...else statement.

    $2.19