i am tryin to ge this program to provide text boxes to imput a series of grades
ID: 3926318 • Letter: I
Question
i am tryin to ge this program to provide text boxes to imput a series of grades for each category
<html>
<!-- This page computes and displays grades for a course. -->
<!-- ==================================================== -->
<head>
<title> Grade Calculator </title>
</head>
<body>
<script type="text/javascript">
homework = prompt("Enter your homework average", );
homework = parseFloat(homework);
labs = prompt("Enter your lab average", );
labs = parseFloat(labs);
midterm = prompt("Enter your midterm grade",);
midterm = parseFloat(midterm);
exam = prompt("Enter your exam grade", );
exam = parseFloat(exam);
average = homework*0.25 + labs*0.20 + midterm*0.25 + exam*0.30;
document.write("<p>homework average: " + homework + "<br />");
document.write("lab average: " + labs + "<br />");
document.write("midterm grade: " + midterm + "<br />");
document.write("exam grade: " + exam + "</p>");
document.write("<p>overall course average: " + average + "</p>");
</script>
</body>
</html>
Explanation / Answer
Your html code is having design flaw. Even though you have written a java script, it is not invoked from the body.
Also since you are using html, its recommended to use <form> with four different <input> tags for homework, labs, midterm and exam. On clicking submit button you can invoke a javascript which will do your calculation and display output in anothe rinput field (which you will be using as output field).
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.