I need this JS program to get 5 marks from the user using prompt box and calculate the total and average of those marks and display the output. When a user clicks on the grade button the following should execute. """If the average is greater than 30 display an alert box “Congrats! You passed” and if the average is below 30 display an alert box “Better luck next time” """
// JavaScript Document
function sum(){
var mark1,mark2,mark3,mark4,mark5;
mark1=window.prompt("Enter Mark 1");
mark2=window.prompt("Enter Mark 2");
mark3=window.prompt("Enter Mark 3");
mark4=window.prompt("Enter Mark 4");
mark5=window.prompt("Enter Mark 5");
var tot=parseInt(mark1)+parseInt(mark2)+parseInt(mark3)+parseInt(mark4)+parseInt(mark5);
var avg=(tot/5);
document.getElementById("total").innerHTML = "Total: " + tot;
document.getElementById("average").innerHTML = "Average: " + avg;
}
function grade(){
if (avg>30){
window.alert("Congrats, You Passed!");
}
if (avg<30){
window.alert("Better luck next time...")
}
}
button {
height: 100px;
width: 200px;
}
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Q2</title>
<link href="styles.css" type="text/css">
<script src="script.js" type="text/javascript"></script>
</head>
<body onLoad="sum()">
<p id="total"></p>
<p id="average"></p>
<button onClick="grade()">Grade</button>
</body>
</html>