2010-08-29 3 views
0

J'ai fait une page de quiz pour notre projet informatique et je l'ai récemment terminée. J'étais heureux de savoir que ça fonctionnait bien. Le problème est maintenant que cela ne fonctionne que sur Google Chrome, mais pas sur Firefox. Quand je l'ouvre dans Google Chrome, tout fonctionne: des invites pour un nom, une fonction pour le score, etc. Mais rien ne fonctionne dans Firefox. Besoin d'aide s'il vous plaît.Codage Javascript fonctionnant dans Google Chrome mais pas sur d'autres navigateurs comme FF

<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 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> 
+2

Et nous avons besoin de code si nous allons aider. :-) –

+1

Mes pouvoirs psychiques sont un peu faibles ce matin. Cela vous dérangerait-il de donner quelques indices sur ce à quoi ressemble le code, sur ce qu'il est censé faire et sur ce qui ne va pas sur Firefox? – Pointy

+1

Et un autre bon début serait d'installer FireBug sur votre FireFox et de passer votre code JavaScript pour voir ce qui ne va pas. –

Répondre

1

Mon Firefox Web Developer Toolbar me dit ce qui suit lors de l'exécution de ce code:

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

La première est fixée par le remplacement break avec return. Le second a disparu après avoir réparé le premier.

Firebug indique également les mêmes problèmes dans la console JS.

+0

OMFG IT FONCTIONNE! : DDDDDDDDD MERCI BEAUCOUP !! –

Questions connexes