JavaScript Code That's Making me Really Mad

Kasdraven

New Member
Could someone tell me what's wrong with this code? I'm trying to get re aquainted with JS after a long break from it adn I cannot find out what's wrong with this code. All I get is a blank page when I open it.

<html>
<head>
<title>Grade Script</title>

<SCRIPT Language="JavaScript">
<!--

function getGrade(name, grade){
var letterGrade
if(grade >= 90){
letterGrade = "A"
}
if(grade <= 89 && >=80){
lettergrade = "B"
}
if(grade <= 79 && >=70){
lettergrade = "C"
}
if(grade <= 69 && >=60){
lettergrade = "D"
}
if(grade < 60){
lettergrade = "Loser"
}
document.write(name + "-" + letterGrade + " (" + grade +")<BR>")
}
//-->
</SCRIPT>

</head>

<body>

<SCRIPT Language="JavaScript">
<!--

getGrade("Maria", "76")
getGrade("Jared", "78")
getGrade("Carrol", "87")
getGrade("Arnold", "86")
getGrade("Derrick", "65")
getGrade("Aricia", "87")
getGrade("Janice", "56")
getGrade("Chris", "93")
getGrade("Sammy", "64")

//-->
</SCRIPT>

</body>
</html>
 

Arkette

New Member
I suggest that you put the second script block inside a function and then call it from the onload event in the body tag as in:

<body onload="init()">

You might also like to consider replacing all the succesive if statements with a switch statement.
http://www.w3schools.com/js/js_switch.asp
 
Last edited:
Top