SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member
    Join Date
    Aug 2008
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    rookie javascript error?

    I don't know what I'm doing wrong, but I get these firebug errors with my javascript:

    3grades2.html (line 47)
    syntax error:
    if (grade <= 100 && grade >=90)\n

    3grades2.html (line 47)
    myGrade is not defined
    myGrade(94);

    Here's my script, thank you so much for your help!:


    5<head>
    6<title> Javascript samples lesson 2 exercise </title>
    7<SCRIPT Language="JavaScript"><!--
    8
    9
    10
    11function myGrade(grade)
    12if (grade <= 100 && grade >=90)
    13 {
    14 document.write("You got an A! </br>");
    15 }
    16
    17else if (grade < 90 && grade >= 80)
    18 {
    19 document.write("You got a B, that's okay by middle-class standards </br>");
    20 }
    21
    22else if (grade < 80 && grade >= 70)
    23 {
    24 document.write("You got a C, which isn't awarded often enough </br>");
    25 }
    26
    27else if (grade < 70 && grade >= 60)
    28 {
    29 document.write("You got an D!</br>");
    30 }
    31
    32else if (grade < 60)
    33 {
    34 document.write("You got a F, you moron!</br>");
    35 }
    36
    37
    38//--></SCRIPT>
    39</head>
    40
    41<body bgcolor="CC22FF">
    42
    43
    44<SCRIPT Language="JavaScript"><!--
    45
    46
    47myGrade(94);
    48
    49
    50//--></SCRIPT>
    51</p>
    52
    53
    54
    55
    56</body>
    57</html>

  2. #2
    SitePoint Member
    Join Date
    Aug 2008
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I spent several hours trying to figure this out, went to the sitepoint forum, posted my question, and within 15 minutes suddenly realized what the problem was.

    I had failed to enclose lines 12 through 35 in brackets. (Firebugs' error messages were misleading.)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •