Ok I have some javascript to find the average of 4 numbers entered into text fields, but I need to add a function to allow me to output a message when a certain grade is achieved like below. I'm not sure how best to tackle this as it is new to me, but I would guess it could be done with an If statement?
Between 90 and 100 inclusive, output: “You got an A”.
Between 80 and 90 inclusive, output: “You got a B”.
Between 70 and 80 inclusive, output: “You got a C”.
Between 60 and 70 inclusive, output: “You got a D”.
Less than 60, output: “You failed”.
This is the code I have so far:
Any help would be much appreciated. Cheers
Between 90 and 100 inclusive, output: “You got an A”.
Between 80 and 90 inclusive, output: “You got a B”.
Between 70 and 80 inclusive, output: “You got a C”.
Between 60 and 70 inclusive, output: “You got a D”.
Less than 60, output: “You failed”.
This is the code I have so far:
Code:
<script language=javascript type=text/javascript>
function calculate(){
var a=eval(document.myform.number1.value);
var b=eval(document.myform.number2.value);
var c=eval(document.myform.number3.value);
var d=eval(document.myform.number4.value);
var e=0;
var e=((a+b+c+d)/4);
document.write("The average is: " + e);
</script>
Any help would be much appreciated. Cheers