I overlooked one step in the assignment however.
I need to ask the user for input about how many homework, project, and exam they have completed and then set the array equal to that. I wrote the code based on the number of assignments in class and do not know how to change it to make it work by input. Could someone point me in the right direction please?
<!DOCTYPE HTML PUBLIC >
<html>
<body>
<h1> Project 4 </h1>
<head>
<script type="text/javascript">
function GetValidInput(promptString)
{
var input
input = parseInt( prompt( promptString));
if(input < -1 || isNaN(input) || input > 106)
{
alert("You did not receive that as a grade, Please enter a grade between 0 and 105.");
input = GetValidInput(promptString);
}
return input;
}
function average(number)
{
Sum = 0;
for (var i = 0; i < number.length; i++)
{
Sum += number[i];
}
return (Sum/number.length);
}
var hwArray = new Array();
for(var i=0;i<3;i++)
{
hwArray[i] = GetValidInput("Enter your homework score");
if(hwArray[i]==-1)
break;
}
var hwAverage = average(hwArray);
var projArray = new Array();
for(var i=0;i<4;i++)
{
projArray[i] = GetValidInput("Enter your project score");
if (projArray[i]==-1)break;
}
var projectAverage = average(projArray);
var examArray = new Array ();
for(var i=0;i<3;i++)
{
examArray[i] = GetValidInput("Enter your exam score");
if (examArray[i]==-1)break;
}
var examAverage = average(examArray);
Grade = average([hwAverage,projectAverage,examAverage]);
if(Grade >= 90)
{
alert ("You got a A!");
}
else if(Grade >= 80 && Grade <= 89.99)
{
alert ("You got a B!");
}
else if(Grade >=70 && Grade <= 79.99)
{
alert ("You got a C");
}
else if(Grade >= 60 && Grade <= 69.99)
{
alert ("You got a D");
}
else
{
alert ("You got a F");
}
</script>
</body>
</html>

New Topic/Question
Reply



MultiQuote





|