samedi 29 novembre 2014

Alert Box isn't showing up after clicking button


I'm trying to program an alert box that tells you your letter grade after putting in your numerical grade in an input box and clicking a button. Here's the code so far



<div id ="function0">
grade: <input type="text" id="numGrade"/><br/>
<input type="button" value="Run Function" onClick="clickFunc0()" />
<script>
function letterGrade(grade) {
if (grade >= 90) {
letter = 'A';
}
else if (grade <= 89 && grade >= 80) {
letter = 'B';
}
else if (grade <= 79 && grade >= 70) {
letter = 'C';
}
else if (grade <= 69 && grade >= 60) {
letter = 'D';
}
else if (grade <= 59 && grade >= 0) {
letter = 'F';
}
alert("You got a(n) "+letter);
}

function clickFunc0()
{
var grade = document.getElementById('numGrade').value;
letterGrade(grade);
}
</script>


if I try to put "<= 100 in the first "if" block, the box won't pop up, but if I leave it as the code shown before, the alert box works just fine.





Aucun commentaire:

Enregistrer un commentaire