Make a web page that does the following:
•The user enters 5 grades that they've made in a particular class. Grades entered have to be between 0 and 100
•A Javascript function will take the 5 grades, find the average, and display the following in an alert box when the user clicks a button
•If they made an A (90-100): display Excellent! You made an A in the class! Your average grade is: ___
•If they made a B (80-89): display Good Job! You made a B in the class! Your average grade is: ___
•C (70-79): display Not Bad! You made a C in the class! Your average grade is: ___
•D (65-69): display Do better next time, you made a D. Your average grade is: ___
•F(0-64): display Oh no....you made an F. Sorry you didn't pass. Your average grade is: ___
<title>Grade Average Calculator</title>
<script type='text/javascript'>
function calculateAverage() //this is the code for the calculation function
{var a = parseInt(document.getElementById('firstNumber').value);
var b = parseInt(document.getElementById('secondNumber').value);
var c = parseInt(document.getElementById('thirdNumber').value);
var d = parseInt(document.getElementById('fouthNumber').value);
var e = parseInt(document.getElementById('fifthNumber').value); //assigns variables to the five grades
var sum =5*(a+b+c+d+e);
if (sum <= 64){alert ("Oh no....you made an F. Sorry you didn't pass. Your average grade is:")
}else if (sum <= 69){alert ("Do better next time, you made a D. Your average grade is:")
}else if (sum <= 79){alert ("Not Bad! You made a C in the class! Your average grade is:")
}else if (sum <= 89){alert ("Good Job! You made a B in the class! Your average grade is:")
}else if(sum <= 100){alert ("Excellent! You made an A in the class! Your average grade is:")} //else if that decides which message to diplay
document.getElementById('gradePlaceholder').value = sum;}</script>
</head>
<body>
<p>Please enter your five grades and I will display a message with your average.
<br />
Grade one <input type='text' id='firstNumber' /> <br />
Grade two <input type='text' id='secondNumber' /> <br />
Grade three <input type='text' id='thirdNumber' /> <br />
Grade four <input type='text' id='fourthNumber' /> <br />
Grade five <input type='text' id='fifthNumber' /> <br />
<input type='text' id='gradePlaceholder' disabled='disabled'/> <br />
<input type="button" id="calcAverage" value="Compute Average" onclick='calculateAverage()'/>
</p>
</body>
</html>
This post has been edited by Dormilich: 26 January 2013 - 12:55 AM

New Topic/Question
Reply


MultiQuote






|