Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Feb 2014
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Quiz Master Question Game

    Hey guys and girls,

    Just wanna say many thanks in advance to those who are able to help me out here.

    Okay. So basically i've trying to make a fun movie quiz game and rather than build from scratch, i was about to find something pre-made and i went about modifying the questions and answers to suit. the issue i've ran into is this, the original quiz was only 3 questions and i'm going to be adding in more questions and i go, what i'm not overly sure about is identifying the 'correct' answers in the coding. this is what i have so far...


    PHP Code:
    <body>

    <
    html>
    <
    head>
    <
    title></title>
    <
    style>
    .
    Question {background-color:white;}
    </
    style>
    <
    script>
    correctAnswers=[0,1,2,1];
    var 
    AnsweredCorrectly=0;
    function 
    start(){
    document.getElementById('quizstart').style.display="none";
    document.getElementById('question0').style.display="block";
    }
    function 
    toggle(a,b){
    AnsweredCorrectly+=(document.getElementsByName('ans'+a)[correctAnswers[a]].checked?1:0);
    document.getElementById('question'+a).style.display="none";
    document.getElementById('question'+b).style.display="block";
    }
    function 
    end(a){
    AnsweredCorrectly+=(document.getElementsByName('ans'+a)[correctAnswers[a]].checked?1:0);
    document.getElementById('question'+a).style.display="none";
    document.getElementById('summary').style.display="block";
    document.getElementById('result').innerHTML=AnsweredCorrectly;
    }
    </script>

    </head>
    <body>

    <h1>QUIZ MASTER</h1>
    <div id="quizstart">
        <button onclick="start()">Click To Begin</button>

    </div>
    <div id="question0" style="display:none">
    <span class="question">In which of these Movies didn't Keanu Reeves appear?</span><br>
    <input type="radio" name="ans0">Sudden Impact<br>
    <input type="radio" name="ans0">The Devil's Advocate<br>
    <input type="radio" name="ans0">Speed<br>
    <input type="radio" name="ans0">Chain Reaction<br>
       <button onclick="toggle(0,1)">Submit Answer</button>

    </div>
    <div id="question1" style="display:none">
    <span class="question">Sigourney Weaver's real first name is?</span><br>
    <input type="radio" name="ans1">Sue<br>
    <input type="radio" name="ans1">Susan<br>
    <input type="radio" name="ans1">Sally<br>
    <input type="radio" name="ans1">Sandra<br>
       <button onclick="toggle(1,2)">Submit Answer</button>

    </div>
    <div id="question2" style="display:none">
    <span class="question">In 'Working Girl' what was the name of Melanie Griffiths character?</span><br>
    <input type="radio" name="ans2">Toby Roebuck<br>
    <input type="radio" name="ans2">Patty Palmer<br>
    <input type="radio" name="ans2">Tess McGill<br>
    <input type="radio" name="ans2">Tina Tercell<br>
       <button onclick="toggle(2,3)">Submit Answer</button>
       
    </div>
    <div id="question3" style="display:none">
    <span class="question">In the 2000 Movie, 'X-Men', what was the name of the band of evil mutants?</span><br>
    <input type="radio" name="ans3">X-Men<br>
    <input type="radio" name="ans3">The Triad<br>
    <input type="radio" name="ans3">The Mutants<br>
    <input type="radio" name="ans3">The Brotherhood<br> 
        <button onclick="toggle(3,4)">Submit Answer</button>
      
    </div>
    <div id="question4" style="display:none">
    <span class="question">In which of these Movies didn't Rovert de Niro appear?</span><br>
    <input type="radio" name="ans4">Casino<br>
    <input type="radio" name="ans4">The Beach<br>
    <input type="radio" name="ans4">Backdraft<br>
    <input type="radio" name="ans4">The Untouchables<br>
       <button onclick="toggle(4,5)">Submit Answer</button>
       
    </div>
    <div id="question5" style="display:none">
    <span class="question">Which Movie isn't a Steven Seagal movie?</span><br>
    <input type="radio" name="ans5">The Patriot<br>
    <input type="radio" name="ans5">Patriot<br>
    <input type="radio" name="ans5">Patriot Games<br>
    <input type="radio" name="ans5">The Patriots<br>
         <button onclick="end(5)">Finish</button>
     
    </div>
    <div id="summary" style="display:none">
    you have <span id="result"></span> correct answers out of 5 questions
    </div>

    </body>
    </html> 
    for the record, the answers are...

    q.0 - A
    Q.1 - B
    Q.2 - C
    Q.3 - D
    Q.4 - B
    Q.5 - A

    i understand that the coding at the start needs to be changed, but being a beginner, its making things rather difficult!

    again, many thanks in advance.

  • #2
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,198
    Thanks
    23
    Thanked 605 Times in 604 Posts
    Some HTML in the <body> would help here .
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • #3
    New to the CF scene
    Join Date
    Feb 2014
    Posts
    3
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Cal. View Post
    Hey guys and girls,

    Just wanna say many thanks in advance to those who are able to help me out here.

    Okay. So basically i've trying to make a fun movie quiz game and rather than build from scratch, i was about to find something pre-made and i went about modifying the questions and answers to suit. the issue i've ran into is this, the original quiz was only 3 questions and i'm going to be adding in more questions and i go, what i'm not overly sure about is identifying the 'correct' answers in the coding. this is what i have so far...


    PHP Code:
    <body>

    <
    html>
    <
    head>
    <
    title></title>
    <
    style>
    .
    Question {background-color:white;}
    </
    style>
    <
    script>
    correctAnswers=[0,1,2,1];
    var 
    AnsweredCorrectly=0;
    function 
    start(){
    document.getElementById('quizstart').style.display="none";
    document.getElementById('question0').style.display="block";
    }
    function 
    toggle(a,b){
    AnsweredCorrectly+=(document.getElementsByName('ans'+a)[correctAnswers[a]].checked?1:0);
    document.getElementById('question'+a).style.display="none";
    document.getElementById('question'+b).style.display="block";
    }
    function 
    end(a){
    AnsweredCorrectly+=(document.getElementsByName('ans'+a)[correctAnswers[a]].checked?1:0);
    document.getElementById('question'+a).style.display="none";
    document.getElementById('summary').style.display="block";
    document.getElementById('result').innerHTML=AnsweredCorrectly;
    }
    </script>

    </head>
    <body>

    <h1>QUIZ MASTER</h1>
    <div id="quizstart">
        <button onclick="start()">Click To Begin</button>

    </div>
    <div id="question0" style="display:none">
    <span class="question">In which of these Movies didn't Keanu Reeves appear?</span><br>
    <input type="radio" name="ans0">Sudden Impact<br>
    <input type="radio" name="ans0">The Devil's Advocate<br>
    <input type="radio" name="ans0">Speed<br>
    <input type="radio" name="ans0">Chain Reaction<br>
       <button onclick="toggle(0,1)">Submit Answer</button>

    </div>
    <div id="question1" style="display:none">
    <span class="question">Sigourney Weaver's real first name is?</span><br>
    <input type="radio" name="ans1">Sue<br>
    <input type="radio" name="ans1">Susan<br>
    <input type="radio" name="ans1">Sally<br>
    <input type="radio" name="ans1">Sandra<br>
       <button onclick="toggle(1,2)">Submit Answer</button>

    </div>
    <div id="question2" style="display:none">
    <span class="question">In 'Working Girl' what was the name of Melanie Griffiths character?</span><br>
    <input type="radio" name="ans2">Toby Roebuck<br>
    <input type="radio" name="ans2">Patty Palmer<br>
    <input type="radio" name="ans2">Tess McGill<br>
    <input type="radio" name="ans2">Tina Tercell<br>
       <button onclick="toggle(2,3)">Submit Answer</button>
       
    </div>
    <div id="question3" style="display:none">
    <span class="question">In the 2000 Movie, 'X-Men', what was the name of the band of evil mutants?</span><br>
    <input type="radio" name="ans3">X-Men<br>
    <input type="radio" name="ans3">The Triad<br>
    <input type="radio" name="ans3">The Mutants<br>
    <input type="radio" name="ans3">The Brotherhood<br> 
        <button onclick="toggle(3,4)">Submit Answer</button>
      
    </div>
    <div id="question4" style="display:none">
    <span class="question">In which of these Movies didn't Rovert de Niro appear?</span><br>
    <input type="radio" name="ans4">Casino<br>
    <input type="radio" name="ans4">The Beach<br>
    <input type="radio" name="ans4">Backdraft<br>
    <input type="radio" name="ans4">The Untouchables<br>
       <button onclick="toggle(4,5)">Submit Answer</button>
       
    </div>
    <div id="question5" style="display:none">
    <span class="question">Which Movie isn't a Steven Seagal movie?</span><br>
    <input type="radio" name="ans5">The Patriot<br>
    <input type="radio" name="ans5">Patriot<br>
    <input type="radio" name="ans5">Patriot Games<br>
    <input type="radio" name="ans5">The Patriots<br>
         <button onclick="end(5)">Finish</button>
     
    </div>
    <div id="summary" style="display:none">
    you have <span id="result"></span> correct answers out of 5 questions
    </div>

    </body>
    </html> 
    for the record, the answers are...

    q.0 - A
    Q.1 - B
    Q.2 - C
    Q.3 - D
    Q.4 - B
    Q.5 - A

    i understand that the coding at the start needs to be changed, but being a beginner, its making things rather difficult!

    again, many thanks in advance.
    Quote Originally Posted by sunfighter View Post
    Some HTML in the <body> would help here .
    not sure what you mean, i did just notice the was an extra "<body>" in the coding that was throwing things out...

  • #4
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,198
    Thanks
    23
    Thanked 605 Times in 604 Posts
    Maybe my finger slipped while doing a copy/paste, but I didn't get the HTML portion of the post and so didn't know how the functions were called. Thanks for reposting. Once I had everything the problem was obvious and I tested it to my satisfaction.
    The problem is the array -> correctAnswers=[0,1,2,1]; Only enough answers for 4 questions. You have 6. You need to have the array correctAnswers=[0,1,2,1,1,0];

    Fixed it Changed to 5 to 6 questions and Robert de Niro's name:
    Code:
    <!DOCTYPE html>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta charset="UTF-8" />
    <title>Title of the document</title>
    <style>
    .Question {background-color:white;}
    </style>
    </head>
    
    <body>
    <h1>QUIZ MASTER</h1>
    <div id="quizstart">
        <button onclick="start()">Click To Begin</button>
    </div>
    <div id="question0" style="display:none">
    <span class="question">In which of these Movies didn't Keanu Reeves appear?</span><br>
    <input type="radio" name="ans0">Sudden Impact<br>
    <input type="radio" name="ans0">The Devil's Advocate<br>
    <input type="radio" name="ans0">Speed<br>
    <input type="radio" name="ans0">Chain Reaction<br>
       <button onclick="toggle(0,1)">Submit Answer</button>
    
    </div>
    <div id="question1" style="display:none">
    <span class="question">Sigourney Weaver's real first name is?</span><br>
    <input type="radio" name="ans1">Sue<br>
    <input type="radio" name="ans1">Susan<br>
    <input type="radio" name="ans1">Sally<br>
    <input type="radio" name="ans1">Sandra<br>
       <button onclick="toggle(1,2)">Submit Answer</button>
    
    </div>
    <div id="question2" style="display:none">
    <span class="question">In 'Working Girl' what was the name of Melanie Griffiths character?</span><br>
    <input type="radio" name="ans2">Toby Roebuck<br>
    <input type="radio" name="ans2">Patty Palmer<br>
    <input type="radio" name="ans2">Tess McGill<br>
    <input type="radio" name="ans2">Tina Tercell<br>
       <button onclick="toggle(2,3)">Submit Answer</button>
    
    </div>
    <div id="question3" style="display:none">
    <span class="question">In the 2000 Movie, 'X-Men', what was the name of the band of evil mutants?</span><br>
    <input type="radio" name="ans3">X-Men<br>
    <input type="radio" name="ans3">The Triad<br>
    <input type="radio" name="ans3">The Mutants<br>
    <input type="radio" name="ans3">The Brotherhood<br>
        <button onclick="toggle(3,4)">Submit Answer</button>
    
    </div>
    <div id="question4" style="display:none">
    <span class="question">In which of these Movies didn't Robert De Niro appear?</span><br>
    <input type="radio" name="ans4">Casino<br>
    <input type="radio" name="ans4">The Beach<br>
    <input type="radio" name="ans4">Backdraft<br>
    <input type="radio" name="ans4">The Untouchables<br>
       <button onclick="toggle(4,5)">Submit Answer</button>
    
    </div>
    <div id="question5" style="display:none">
    <span class="question">Which Movie isn't a Steven Seagal movie?</span><br>
    <input type="radio" name="ans5">The Patriot<br>
    <input type="radio" name="ans5">Patriot<br>
    <input type="radio" name="ans5">Patriot Games<br>
    <input type="radio" name="ans5">The Patriots<br>
         <button onclick="end(5)">Finish</button>
    
    </div>
    <div id="summary" style="display:none">
    you have <span id="result"></span> correct answers out of 6 questions
    </div>
    
    <script>
    correctAnswers=[0,1,2,1,1,0];
    var AnsweredCorrectly=0;
    function start(){
    	document.getElementById('quizstart').style.display="none";
    	document.getElementById('question0').style.display="block";
    }
    function toggle(a,b){
    	AnsweredCorrectly+=( document.getElementsByName('ans'+a)[correctAnswers[a]].checked?1:0);
    	document.getElementById('question'+a).style.display="none";
    	document.getElementById('question'+b).style.display="block";
    }
    function end(a){
    	AnsweredCorrectly+=(document.getElementsByName('ans'+a)[correctAnswers[a]].checked?1:0);
    	document.getElementById('question'+a).style.display="none";
    	document.getElementById('summary').style.display="block";
    	document.getElementById('result').innerHTML= AnsweredCorrectly;
    }
    </script>
    </body>
    </html>
    Evolution - The non-random survival of random variants.

    "If you leave hydrogen alone, for long enough, it begins to think about itself."

  • Users who have thanked sunfighter for this post:

    Cal. (03-18-2014)


  •  

    Posting Permissions

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