Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

NOTE - if using a while loop or a do while loop - the test in parenthesis needs

ID: 3730495 • Letter: N

Question

NOTE- if using a while loop or a do while loop - the test in parenthesis needs to use a Relational operator. In your book relational operators are listed on page 166. Setting a variable to true (var test = true) before the loop then using a statement like while(test) to start a while loop or end the do while loop is not acceptable.

**********NOTE: You can not use an exit, go to, or break statement to get out of an if statement or loop - this will result in a grade of 0 (zero) for the assignment!!

4.(Chapter #5 Question) Develop an algorithm and write the html and JavaScript that displays a web page titled "Your Last Name - Grade Calculator". This code will allow a student to enter a grade, in integer form ( like 85 or 72), through the prompt statement or a html form. Check the entered value to make sure it is between 0 and 100 inclusive. If it is outside this range print an error message in an Alert box and end the program. If the entered value is within the range of 0 - 100 inclusive then use a series of If/Else statements to classify the grade according to the following range: 0 to 49 = Poor; 50 to 64 = Below Average; 65 to 79= Average; 80 to 89 = Above Average; and 90 or higher as Exceptional. Display the grade entered and the classification in an Alert box. For Example a grade of 55 would be classified as 55 is Below Average while a grade of 95 would be classified as 95 is Exceptional.

Explanation / Answer

HTML And JavaScript Code:

<html>

<head>

  

<title>Your Last Name - Grade Calculator</title>

  

</head>

<body>   

<!-- Taking Input -->

<h2> Your Last Name - Grade Calculator </h2>

<fieldset>

<legend><b>Enter Grade</b></legend>

Integer Grade:<input type="text" id="grade"> </br>

<input type = "submit" value = "Submit">

<script>

function getReport(){

var grade = ""; //declare a variable for grade

//read the marks

var Marks = document.getElementById('grade').value;

  

  

if(Marks < 0 || Marks > 100 )

{

alert('Invalid Input');

return;

}

  

  

//find the grade

if(Marks >= 0 && Marks <=49)

grade = "Poor";

else if(Marks>=50 && Marks <=64)

grade = "Below Average";

else if(Marks>=65 && Marks <=79)

grade = "Average";

else if(Marks>=80 && Marks <=89)

grade = "Above Average";

else if(Marks>=90)

grade = "Exceptional";

//display the results

alert('Grade Entered: ' + Marks + ' ' + 'Class: ' + grade);

}

</script>

</body>

</html>

-----------------------------------------------

Note: Replace "Your Last name" in the <title> tag by your last name and do same in the <h2> tag. Save the file as .html extension.