hy_tek
12-10-2007, 02:43 AM
Hi..I am a 55 year old male who has decided I want to learn how to write JavaScript code. I have been doing online tutorials but I have run into a snag in a lesson. I have tried over and over to get this code to do what the author says it should but I am at a loss as to what I am doing wrong. i am typing it EXACTLY as the author but his code runs and mine does not. Please tell me what I am missing here.
The authors code is supposed to write a series of grades and the appropriate letter grade for each student.
<HTML>
<HEAD>
<TITLE>Grade Script</TITLE>
<SCRIPT language="JavaScript">
<!--
function getGrade(name, grade){
var letterGrade
if(grade >= 90){
letterGrade = "A"
}
if(grade >= 80 && grade < 90){
letterGrade = "B"
}
if(grade >= 70 && grade < 80){
letterGrade = "C"
}
if (grade < 70){
letterGrade = "F"
}
document.write(name + " - " + letterGrade + " (" + grade + ")<BR>" )
}
//-->
</SCRIPT>
</HEAD>
<BODY bgcolor="white">
<P>
<SCRIPT language="JavaScript">
<!--
getGrade("Mary", "94")
getGrade("Jim", "70")
getGrade("Albert", "65")
getGrade("Carroll", "88")
getGrade("Francis", "44")
getGrade("George", "89")
getGrade("Alice", "90")
getGrade("Sam", "79")
getGrade("Pat", "80")
getGrade("Ray", "100")
//-->
</SCRIPT>
</BODY>
</HTML>
The above code which was copy and pasted from the author runs properly.
Below is the code I typed myself in NoteTab Pro. To me it is identical to the code above but it won't run. Is this some rookie keyboard issue per chance? I have only num lock on.
<html>
<head>
<title>Grade Script</title>
<SCRIPT language="JavaScript">
<!--
function getGrade(name, grade){
var letterGrade
if(grade >= 90){
letterGrade = "A"
}
if(grade >= 80 && <90){
letterGrade = "B"
}
if(grade >= 70 && <80){
letterGrade = "B"
}
if(grade , 70){
letterGrade = "C"
}
document.write(name + " - " + letterGrade + "("+ grade + ")<BR>")
}
//-->
</SCRIPT>
</head>
<body bgcolor="white">
<p>
<script language="JavaScript" type="text/javascript">
<!--
getGrade("Mary", "94")
getGrade("Jim", "70")
getGrade("Albert", "65")
getGrade("Carroll", "88")
getGrade("Francis", "44")
getGrade("George", "89")
getGrade("Alice", "90")
getGrade("Sam", "79")
getGrade("Pat", "80")
getGrade("Ray", "100")
//-->
</script></p>
</body>
</html>
The desired output results of this simple script is to print the following:
Mary - A (94)
Jim - C (70)
Albert - F (65)
Carroll - B (88)
Francis - F (44)
George - B (89)
Alice - A (90)
Sam - C (79)
Pat - B (80)
Ray - A (100)
I know this is a really basic problem to an advanced coder but I am just learning and have spent hours trying to figure the problem to no avail. Please can anyone shed some light on what I am doing wrong? :confused:
The authors code is supposed to write a series of grades and the appropriate letter grade for each student.
<HTML>
<HEAD>
<TITLE>Grade Script</TITLE>
<SCRIPT language="JavaScript">
<!--
function getGrade(name, grade){
var letterGrade
if(grade >= 90){
letterGrade = "A"
}
if(grade >= 80 && grade < 90){
letterGrade = "B"
}
if(grade >= 70 && grade < 80){
letterGrade = "C"
}
if (grade < 70){
letterGrade = "F"
}
document.write(name + " - " + letterGrade + " (" + grade + ")<BR>" )
}
//-->
</SCRIPT>
</HEAD>
<BODY bgcolor="white">
<P>
<SCRIPT language="JavaScript">
<!--
getGrade("Mary", "94")
getGrade("Jim", "70")
getGrade("Albert", "65")
getGrade("Carroll", "88")
getGrade("Francis", "44")
getGrade("George", "89")
getGrade("Alice", "90")
getGrade("Sam", "79")
getGrade("Pat", "80")
getGrade("Ray", "100")
//-->
</SCRIPT>
</BODY>
</HTML>
The above code which was copy and pasted from the author runs properly.
Below is the code I typed myself in NoteTab Pro. To me it is identical to the code above but it won't run. Is this some rookie keyboard issue per chance? I have only num lock on.
<html>
<head>
<title>Grade Script</title>
<SCRIPT language="JavaScript">
<!--
function getGrade(name, grade){
var letterGrade
if(grade >= 90){
letterGrade = "A"
}
if(grade >= 80 && <90){
letterGrade = "B"
}
if(grade >= 70 && <80){
letterGrade = "B"
}
if(grade , 70){
letterGrade = "C"
}
document.write(name + " - " + letterGrade + "("+ grade + ")<BR>")
}
//-->
</SCRIPT>
</head>
<body bgcolor="white">
<p>
<script language="JavaScript" type="text/javascript">
<!--
getGrade("Mary", "94")
getGrade("Jim", "70")
getGrade("Albert", "65")
getGrade("Carroll", "88")
getGrade("Francis", "44")
getGrade("George", "89")
getGrade("Alice", "90")
getGrade("Sam", "79")
getGrade("Pat", "80")
getGrade("Ray", "100")
//-->
</script></p>
</body>
</html>
The desired output results of this simple script is to print the following:
Mary - A (94)
Jim - C (70)
Albert - F (65)
Carroll - B (88)
Francis - F (44)
George - B (89)
Alice - A (90)
Sam - C (79)
Pat - B (80)
Ray - A (100)
I know this is a really basic problem to an advanced coder but I am just learning and have spent hours trying to figure the problem to no avail. Please can anyone shed some light on what I am doing wrong? :confused: