Hi, below is the assignment followed by my code.
The two parts I cannot get working are:
[COLOR=”#FF0000″]1)
[COLOR=”#FF0000″]2)
If I delete the nubmer and press OK it returns “Your Grade is: E” and when I click the Cancel button it also returns “Your Grade is: E”. Thank you for your help.
[COLOR=”#0000CD”][B]Assignment:
• Create a JS script code containing a function that inputs a student’s average and returns:
o A if the student’s average is 90-100
o B if the average is 80-89
o C if the average is 70-79
o D if the average is 60-69
o E if the average is 0-59.
o If the average is NOT between 0 and 100, display “invalid input”.
Your code should ask the user to input the student’s average, validate the average (=value should be between 0 – 100), and then:
o If valid, call a function to determine and return A, B, C, D, or E depending on the average.
[COLOR=”#B22222″]o If the average is not valid or if the user pressed Cancel button, display an alert message and exit the program. – not working
[CODE]<script type=”text/javascript”>
function stuAverage(param1, param2, param3, param4, param5, param6)
{
var stuAverage = prompt(“To determine your grade please enter your average”, 60);
if ((isNaN(stuAverage)) || ((stuAverage <0) || (stuAverage >100)))
{
alert(“Invalid input. Exiting program”);
}
else if (stuAverage >= 90 && stuAverage <= 100)
{
return alert(“Your Grade is: ” + param1 + “”)
}
else if (stuAverage >= 80 && stuAverage <= 89)
{
return alert(“Your Grade is: ” + param2 + “”)
}
else if (stuAverage >= 70 && stuAverage <= 79)
{
return alert(“Your Grade is: ” + param3 + “”)
}
else if (stuAverage >= 60 && stuAverage <= 69)
{
return alert(“Your Grade is: ” + param4 + “”)
}
else if (stuAverage >= 0 && stuAverage <= 59)
{
return alert(“Your Grade is: ” + param5 + “”)
}
else if (stuAverage == ” “)
{
return alert(param6 + “”)
}
}
stuAverage (“A”, “B”, “C”, “D”, “E”, “Invalid input. Exiting program”);
</script>