Purchase Solution

JavaScript code to find average

Not what you're looking for?

Ask Custom Question

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.

Purchase this Solution

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.

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 = ...

Purchase this Solution


Free BrainMass Quizzes
C# variables and classes

This quiz contains questions about C# classes and variables.

Inserting and deleting in a linked list

This quiz tests your understanding of how to insert and delete elements in a linked list. Understanding of the use of linked lists, and the related performance aspects, is an important fundamental skill of computer science data structures.

Word 2010: Table of Contents

Ever wondered where a Table of Contents in a Word document comes from? Maybe you need a refresher on the topic? This quiz will remind you of the keywords and options used when working with a T.O.C. in Word 2010.

Javscript Basics

Quiz on basics of javascript programming language.

Basic Computer Terms

We use many basic terms like bit, pixel in our usual conversations about computers. Are we aware of what these mean? This little quiz is an attempt towards discovering that.