开发者

Javascript coding working in Google Chrome but not on other browsers like FF

I did a quiz page for our computer project and I've recently finished it.I was happy to know that it was working well. The problem now is that it only works on Google Chrome but not on Firefox. When I open it in Google Chrome, everything works: prompts for a name, function for score, etc. But nothing works in Firefox. Need help please.

<html>
    <head>
    <title>Javascript Quiz</title>
    <script type="text/javascript">
    function name()
    {
        var n
        n = prompt("Enter your name")
        document.q.name.value = n
    }
    function score()
    {
        var a
        var s = 0;
        var m

        if (q.answer1.value=="Alex Alfred S. Billones")
        {
            s = s+1
        }
        if (q.answer2.value=="grandfathers")
        {
            s = s+1
        }
        if (q.answer3.value=="b")
        {
            s = s+1
        }
        if (q.answer4.value=="c")
        {
            s = s+1
        }
        if (q.answer5.value=="b")
        {
            s = s+1
        }
        if (q.answer6.value=="Angel" || q.answer6.value=="Rex" || q.answer6.value=="Alejandro")
        {
            s = s+1
        }
        if (q.choicesSet2a.checked==true && q.choicesSet2c.checked==true && q.choicesSet2e.checked==true && q.choicesSet2b.checked==false && q.choicesSet2d.checked==false)
        {
            s = s+1
        }
        if (q.answer8.value=="17")
        {
            s = s+1
        }
        if (q.answer9.value=="a")
        {
            s = s+1
        }
        if (q.answer10.value=="never")
        {
            s = s+1
        }

        // remarks part
        if (s==0)
        {
            m = "You don't know me =("
        }
        if (s>0&&s<=3)
        {
            m = "You probably heard stories about me from someone."
        }
        if (s>=4&&s<=5)
        {
            m = "You've met me."
        }
        if (s>=6&&s<=8)
        {
            m = "You know me well."
        }
        if (s==9)
        {
            m = "You love me! :D"
        }
        if (s==10)
        {
            m = "You're a stalker."
        }
        //end of remarks part

        a = confirm("Are you sure with your answers?")
        if (a==true)
        {
            true
        }
        else
        {
            break
        }
        document.q.final.value = s;
        document.q.remark.value = m;



    }
    </script>
</head>

<body bgcolor="green" text="white" onload="name()">
<center><b>How well do you know me? Take this quiz to find out!</b><br>
            Observe correct capitalization of letters in typing.</center><hr>
<form name="q">
<ol>
    <li>What is my COMPLETE name? (with correct middle initial)<br>
        Answer: <input type="text" name="answer1" value=""/>
    </li>

    <li>
        From who among the following was my name gotten from?<br>
        <select name="answer2">
            <option value=""></option>
            <option value="grandfathers">Grandfathers</option>
            <option value="uncle">Uncle</option>
            <option value="stranger">Stranger</option>
            <option value="famous">Famous person</option>
        </select>
    </li>
    <li>Which of the following is the correct spelling of my family name?<br>
        <input type="radio" name="choicesSet1" onclick="q.answer3.value='a' ">Billiones<br>
        <input type="radio" name="choicesSet1" onclick="q.answer3.value='b'">Billones<br>
        <input type="radio" name="choicesSet1" onclick="q.answer3.value='c' ">Biliones<br>
        <input type="radio" name="choicesSet1" onclick="q.answer3.value='d' ">None of the above.<br>
        <input type="hidden" name="answer3" value=""/>
    </li>

    <li>When is my birthday?<br>
        <input type="radio" name="choicesSet2" onclick="q.answer4.value='a' ">February 14<br>
        <input type="radio" name="choicesSet2" onclick="q.answer4.value='b'">October 17<br>
        <input type="radio" name="choicesSet2" onclick="q.answer4.value='c' ">December开发者_StackOverflow中文版 17<br>
        <input type="radio" name="choicesSet2" onclick="q.answer4.value='d' ">March 28<br>
        <input type="hidden" name="answer4" value=""/>
    </li>

    <li>How many siblings do I have?<br>
        <input type="radio" name="choicesSet3" onclick="q.answer5.value='a' ">3<br>
        <input type="radio" name="choicesSet3" onclick="q.answer5.value='b' ">2<br>
        <input type="radio" name="choicesSet3" onclick="q.answer5.value='c' ">1<br>
        <input type="radio" name="choicesSet3" onclick="q.answer5.value='d' ">100<br>
        <input type="hidden" name="answer5" value=""/>
    </li>

    <li>Name one of my siblings. (nickname/first name only) <br>
        Answer: <input type="text" name="answer6" value=""><br>
    </li>

    <li>Which of the following are my hobbies? (only three of them are correct)<br>
        <input type="checkbox" name="choicesSet2a">Playing soccer<br>
        <input type="checkbox" name="choicesSet2b">Studying<br>
        <input type="checkbox" name="choicesSet2c">Surfing the net<br>
        <input type="checkbox" name="choicesSet2d">Drinking<br>
        <input type="checkbox" name="choicesSet2e">Reading<br>
    </li>

    <li>What is my favorite number?<br>
        <select name="answer8">
            <option value=""></option>
            <script type="text/javascript">
                for (c=1;c<=50;c++)
                {
                    document.write("<option value='")
                    document.write(c,"'>",c,"</option>")
                }
            </script>
        </select>
    </li>

    <li>How did I have my front tooth broken?<br>
        <input type="radio" name="choicesSet4" onclick="q.answer9.value='a' ">I fainted.<br>
        <input type="radio" name="choicesSet4" onclick="q.answer9.value='b'">I got punched in the face.<br>
        <input type="radio" name="choicesSet4" onclick="q.answer9.value='c' ">I tripped and fell down.<br>
        <input type="radio" name="choicesSet4" onclick="q.answer9.value='d' ">None of the above.<br>
        <input type="hidden" name="answer9" value=""/>
    </li>

    <li>How many times have I been in a relationship?<br>
        <select name="answer10">
            <option value=""></option>
            <option value="1">1</option>
            <option value="3">3</option>
            <option value="4">4</option>
            <option value="never">Never</option>
        </select>
    </li>

</ol>

    <center>
    <input type="button" value="Well...how did I do?" onclick="score()">
    <input type="reset" value="Reset"/><br><br>
    Thank you for taking the quiz, <input type="text" name="name" size="5">.You scored <input type="text" name="final" id="final" size="1"> out of 10.<br>
    <input type="text" name="remark" size="50">

    </center>
</form>
</body>
</html>


My Firefox Web Developer Toolbar tells me the following when running this code:

  • Error: unlabeled break must be inside loop or switch
  • Error: name is not a function

The first is to be fixed by replacing break with return. The second has disappeared after fixing the first.

Firebug also tells about the same problems in the JS console.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜