0

Hi, I am a newbie to html. I have a project I am doing for school. Can someone take a look at my code and see what is wrong? After I put my answers in the form, my results will not populate. Any help appreciated

<html>
    <head>
         <title>
         My Fun Quiz - Constance Dobbins 
         </title>
         <script>
                 function getInputAsText(_id){return document.getElementById(_id).value}
                 function getInputAsNumber(_id){return parseFloat(document.getElementById(_id).value)}
                 function setOutput(_id, _value){document.getElementById(_id).value = _value}
                 function calculate ()
                 {
                     //declare variables
          var myAnswer1
          var myAnswer2
          var myAnswer3
          var myResult1
                        var myResult2
          var myResult3
                        var score

                     //get variable's value  
                        myAnswer1=getInputAsNumber ("myAnswer1")
          myAnswer2=getInputAsText ("myAnswer2")    
          myAnswer3=getInputAsText ("myAnswer3") 
          myResult1=getInputAsText ("myResult1")
          myResult2=getInputAsText ("myResult2")
          myResult3=getInputAsText ("myResult3")
          score=getInputAsNumber ("score")
          if (myAnswer1 == "8")
        {
           score = +1 
           myResult1 = "correct"
        }
        else
        {
          myResult1 = "WRONG! It's Eight"
        }

              if (myAnswer2.toLowercase() == "Apple".toLowerCase())
        {
          score = + 1 
          myResult2 = "correct"
        }
         else
        {
          myResult2 = "WRONG! It's Apple"
        }

              if (myAnswer3.toLowercase() == "Microsoft".toLowerCase())
        {
         score = + 1 
        myResult3 = "correct"
        }
         else
        {
         myResult3 = "WRONG! It's Microsoft"
        }

    //write output value
        setOutput ("myresultBox", myResult1)
        setOutput ("myresultBox", myResult2)
        setOutput ("myresultBox", myResult3)
        setOutput ("scoreBox", "Your total score is " + score + " out of 3")
               }
          </script>
   </head>

   <body>
    Instructions:<br>
    Answer all three questions and press go.<br>
    The total score will appear.<br><br>

    Input Values:<br>
    1. A byte is how many bits? <INPUT id= "myAnswer1Box"><br>  
    2. Steve Jobs heads what company?<INPUT id= "myAnswer2Box"><br>
    3. Bill Gates heads what company?<INPUT id= "myAnswer3Box"><br>
    <input type="submit"  Value="go" onclick="calculate()"><br><br>

    Output Value:<br>
    Result# 1:<INPUT id= "myResult1Box"><br>
    Result# 2:<INPUT id= "myResult2Box"><br>
    Result# 3:<INPUT id= "myResult3Box"><br>  
    Your score <INPUT id= "scoreBox">

   </body>
</html>
2
Contributors
1
Reply
2
Views
4 Years
Discussion Span
Last Post by pritaeas
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.