Webpage and external JavaScript...

profileWizzah82
coinfo762_webscriping_lab6b_loops.pdf

Co Info 762 Web Scriping

Lab6B (Loops) Average Grades:

 Create a Webpage and an external JavaScript file to calculate average grades entered by the

user. For this program you will be using a prompt box. A prompt box is a JavaScript popup box

that gets a value from the user. Allow the user to enter grades one after the other one in the

prompt box. Prompt the user to enter a negative number to stop. Please refer to the

presentation. A sentinel value is a value that stops the loop. After the user stops the loop,

display the total, number of grades, and the average.

First grade

Second grade

Third grade

Negative number

How to do it:

 A prompt box returns a value. You must save the value in a variable to be able to use it. This is

the general syntax for a prompt:

var name = prompt("Please enter your name: ")

 The value returned by a prompt is a string. You must convert it to a number. Use the

parseFloat( ) function to accomplish this task. If you need, you can refer to previous labs for

this function.

 In a loop, as you get the value from the user, add it to the total. You should also have another

variable to keep track of the number of grades. This will be a counter you increment in the

loop.

 The loop stops when the value entered is a negative number.

 Important: Make sure you do not add the negative number to the total. Also, do not increment

the counter when the number is negative. You can use an “if statement” for this purpose.

Requirements:

 Add the usual comments. As you code, add more comments to describe what you have done.

 You do not decide how many grades to accept. The user does.

 Test, test, and test. First test the program with simple numbers. If the average for grades 2,

3, and 4 are 257.980, you know you have done something wrong.

 You must tell user what the program does. Please do not start with “Enter a grade”. If you

wish, you can explain the program to the user in your HTML file.

 You can use any means you wish to display the results. You can use text or an alert box.

How to submit:

 After completing the project, test it in different browsers.

 Call the instructor to view the codes. This is required to receive a grade.

 Correct your errors, if any.

 Show the codes to the instructor again after the corrections.

 Zip your folder with both files in it. Upload the zip folder in Moodle for feature reference.