Kasdraven Posted February 1, 2006 Share Posted February 1, 2006 What's wrong with this code? I'm trying to get re aquainted with JavaScript after a long break and I can't figure out what is 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> Link to comment Share on other sites More sharing options...
aspnetguy Posted February 1, 2006 Share Posted February 1, 2006 here you go <html><head><title>Grade Script</title><script Language="JavaScript"><!--function getGrade(name, grade){ grade = parseInt(grade); var letterGrade; if(grade >= 90){letterGrade = "A";} if(grade <= 89 && grade >= 80){letterGrade = "B";} if(grade <= 79 && grade >= 70){letterGrade = "C";} if(grade <= 69 && grade >= 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> Link to comment Share on other sites More sharing options...
Kasdraven Posted February 1, 2006 Author Share Posted February 1, 2006 here you go<html><head><title>Grade Script</title><script Language="JavaScript"><!--function getGrade(name, grade){ grade = parseInt(grade); var letterGrade; if(grade >= 90){letterGrade = "A";} if(grade <= 89 && grade >= 80){letterGrade = "B";} if(grade <= 79 && grade >= 70){letterGrade = "C";} if(grade <= 69 && grade >= 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> <{POST_SNAPBACK}> So what did I do wrong? Thanks for fixing it but I also want to know what I missed so that I can take note of it. Sorry, it's just that i'm making a newb tutorial for my junior class since I am the only one to know this stuff and so I figure if I make a mistake in some way, it's worth noting because they probably will too. Link to comment Share on other sites More sharing options...
aspnetguy Posted February 1, 2006 Share Posted February 1, 2006 -you did not put semi-colins at the end of your lines (-you where trying to assign the letter to lettergrade instead of letterGrade (case sensitive).-you were comparing grade which is a string to numbers. Link to comment Share on other sites More sharing options...
Kasdraven Posted February 2, 2006 Author Share Posted February 2, 2006 What does the parsInt thing do? Link to comment Share on other sites More sharing options...
aspnetguy Posted February 2, 2006 Share Posted February 2, 2006 What does the parsInt thing do?<{POST_SNAPBACK}> since grade was poassed to the function as a string...I needed to make it into an int (integer).parseInt is a built-in JavaScript function that takes a string and turns it into an int as long as the string is a in the form of a number. If it cannot complete the conversion it throws and exception. Link to comment Share on other sites More sharing options...
chadmichael Posted February 2, 2006 Share Posted February 2, 2006 I thought you didn't need semi-colons at the end of a javascript statement? Link to comment Share on other sites More sharing options...
aspnetguy Posted February 2, 2006 Share Posted February 2, 2006 Javascript does not require that you use semicolons to signify the end of each statement. If you are an experienced programmer and prefer to use semicolons, feel free to do so. Javascript will not malfunction from ending semicolons. The only time it is necessary to use a semicolon is when there are two statements on one line(i.e. two document.write statements on one line). quoted from www.tizag.comhmmmm....learn something new everyday.In college they drilled it into us to use semicolons, I never stopped to wonder if they were required or not...lolI use C# a lot, which does require them, so it is mostly a force of habit. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now