Results 1 to 6 of 6

Thread: Quiz and viewing answers

  1. #1
    Join Date
    Nov 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation Quiz and viewing answers

    Hi,

    I'm writing my own quiz and I have a question: how to do that when I'm choosing correct answer in quiz near answer I'll see information: "Good answer!",
    but when I choose incorrect answer I'll see info: "Bad answer!".
    Good answer - green color, bad - red.
    Here is the code of my quiz:
    Code:
    <td class="text" align="left">
    	<b><font SIZE="3"><center><a name="quiz1">Quiz </a></center></font></B><br></b>
    	<b>1. Question 1:</b>
    	<br><INPUT TYPE="radio" NAME="ans1" value="1" onClick="submit()"> answer 1 
        <br><INPUT TYPE="radio" NAME="ans2" VALUE="2" onClick="submit()"> answer 2  
    	<br><INPUT TYPE="radio" NAME="ans3" VALUE="3" onClick="submit()"> answer 3  
        <br><INPUT TYPE="radio" NAME="ans4" VALUE="4" onClick="submit()"> answer 4
        </form>
    	<br>
    	<br><form><input TYPE="button" VALUE="Next question" onClick="parent.location.href='quiz2.html#quiz2'"></FORM>
    	
    	</td>
    </tr>
    </table>

  2. #2
    Join Date
    Sep 2006
    Location
    England
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Talking

    Hi Oyster,
    Sorry I have'nt time to sort your code right now but here is a full quiz I wrote a while back for a friend. It's easy to follow and you can easily edit it to suit.

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    
    <html>
    <head>
    	<title>Oysters Quiz</title>
    
    <script type="text/JavaScript">
    <!--
    var ans = new Array;
    var done = new Array;
    var yourAns = new Array;
    var explainAnswer = new Array;
    
    var score = 0;
    // correct answers - just change these
    ans[1] = "b";
    ans[2] = "b";
    ans[3] = "a";
    ans[4] = "c";
    ans[5] = "b";
    
    // reasons for the answers - just fill them in
    explainAnswer[1]="The reason why Answer 1 is -b- is because Blah Blah Blah";
    explainAnswer[2]="The reason why Answer 2 is -b- is because Blah Blah Blah";
    explainAnswer[3]="The reason why Answer 3 is -a- is because Blah Blah Blah";
    explainAnswer[4]="The reason why Answer 4 is -c- is because Blah Blah Blah";
    explainAnswer[5]="The reason why Answer 5 is -b- isbecause Blah Blah Blah";
    
    function do_answers_stuff(question, answer) {
    yourAns[question]=answer;
    }
    
    function Score(){
    var answerText = "How did you do?\n------------------------------------\n";
    for(i=1;i<=5;i++){
       answerText=answerText+"\nQuestion :"+i+"\n";
      if(ans[i]!=yourAns[i]){
        answerText=answerText+"\nThe correct answer was "+ans[i]+"\n"+explainAnswer[i]+"\n";
      }
      else{
        answerText=answerText+" \nCorrect! \n";
        score++;
      }
    }
    
    answerText=answerText+"\n\nYour total score is : "+score+"\n";
    
    //now score the user
    answerText=answerText+"\nComment : ";
    if(score<=0){
    answerText=answerText+"You need to get out more often";
    }
    if(score>=1 && score <=2){
    answerText=answerText+"bit more practice and you'll do OK.";
    }
    if(score>=3 && score <=3){
    answerText=answerText+"Hmmm. alright but hmmmmmm";
    }
    if(score>4){
    answerText=answerText+"You need to go back to high school!!!";
    }
    
    alert(answerText);
    
    }
    //-->
    </script>
    </head>
    
    <body>
    <div align="center">
    <h1>Oysters Quiz</h1>
    <b>Prepare to be questioned like you've never been questioned before!!</b>
    <hr>
    <FORM>
    <b>1. People who don't know you tend to think you are?</b><br>
    <input type=radio name="q1" value="a" onClick="do_answers_stuff(1, this.value)">a) Awful<br>
    <input type=radio name="q1" value="b" onClick="do_answers_stuff(1, this.value)">b) Horrible<br>
    <input type=radio name="q1" value="c" onClick="do_answers_stuff(1, this.value)">c) Prude.<br>
    <input type=radio name="q1" value="d" onClick="do_answers_stuff(1, this.value)">d) Beautiful.<br>
    <input type=radio name="q1" value="d" onClick="do_answers_stuff(1, this.value)">d) Ugly.<p>
    
    <b>2. Please pick an item.</b><br>
    <input type=radio name="q2" value="a" onClick="do_answers_stuff(2, this.value)">a) Your nose<br>
    <input type=radio name="q2" value="b" onClick="do_answers_stuff(2, this.value)">b) Your toes<br>
    <input type=radio name="q2" value="c" onClick="do_answers_stuff(2, this.value)">c) Your spots<br>
    <input type=radio name="q2" value="d" onClick="do_answers_stuff(2, this.value)">d) A nice chocolate/candy bar<p>
    
    <b>3. What music do you listen to?</b><br>
    <input type=radio name="q3" value="a" onClick="do_answers_stuff(3, this.value)">a) Crap - er sorry, I meant Rap<br>
    <input type=radio name="q3" value="b" onClick="do_answers_stuff(3, this.value)">b) Soothing music<br>
    <input type=radio name="q3" value="c" onClick="do_answers_stuff(3, this.value)">c) Punk<br>
    <input type=radio name="q3" value="d" onClick="do_answers_stuff(3, this.value)">d) Heavy metal <p>
    
    <b>4. When you look in your room, what do you see?</b><br>
    <input type=radio name="q4" value="a" onClick="do_answers_stuff(4, this.value)">Dirty socks<br>
    <input type=radio name="q4" value="b" onClick="do_answers_stuff(4, this.value)">Little 'orrible brother<br>
    <input type=radio name="q4" value="c" onClick="do_answers_stuff(4, this.value)">Cobwebs 'n spiders<br>
    <input type=radio name="q4" value="d" onClick="do_answers_stuff(4, this.value)">Clothing all over the place<p>
    
    <b>5. Okay, you're sick of life. What do you do?</b><br>
    <input type=radio name="q5" value="a" onClick="do_answers_stuff(5, this.value)">Listen to music to die by such as as 'Everybody Hurts - REM'<br>
    <input type=radio name="q5" value="b" onClick="do_answers_stuff(5, this.value)">A deal with the Devil<br>
    <input type=radio name="q5" value="c" onClick="do_answers_stuff(5, this.value)">Shout 'I love George Bush' outside 10 Downing Street,UK<br>
    <input type=radio name="q5" value="d" onClick="do_answers_stuff(5, this.value)">Shout 'I love Tony Blair' outside the the Whitehouse,USA<p>
    </center>
    <center>
    <input type=button onClick="Score()" value="Well... How did I do?">
    </center>
    </form>
    </div>
    
    </body>
    </html>
    Hope this helps for now - have fun!!
    Regards,
    Ges.

  3. #3
    Join Date
    Nov 2006
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I want script in JS which will checking correct answer and viewing information about good or bad choice....

  4. #4
    Join Date
    Aug 2006
    Posts
    34
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    [QUOTE=Ges;63030]Hi Oyster,
    Sorry I have'nt time to sort your code right now but here is a full quiz I wrote a while back for a friend. It's easy to follow and you can easily edit it to suit.

    [CODE]

    Good and fun script!! I want to use the script in a more creative manner. I will to use the script as "key" to enter a webpage. For example, if the person answer wrong, the message will appears as "Access denied!! You did not do your homework". If he/she answer correctly, he/she will automatically be redirected to the required page. In other word, the answer will functions as the password to access the page.
    Also, for "security reason" can i put the script in external file?

  5. #5
    Join Date
    Sep 2006
    Location
    England
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Talking

    Hi terkini and glad you appreciate the English sense of humour!
    I'm not fuuly sure what you require. If you want a straightforward password/sentence type thingy then I've done one that uses an external Javascript. The input is case sensitive but always remeber that a javascript can easily be viwed by the determined hacker.
    Anyway, try this for now.
    This is the external Javascript - call it 'keychecker.js'
    Code:
    function Login(){
    var done=0;
    var keyword=document.enter_keyword.keyword.value;
    //keyword=keyword.toLowerCase();
    if (keyword=="BAH HUMBUG") { window.location="http://www.somewhere_over.com"; done=1; }
    if (keyword=="Where are my presents") { window.location="http://www.the_rainbow.com"; done=1; }
    if (done==0) { alert("ACCESS DENIED PLONKER:\n\nYou did not do your HOMEWORK!!!!!"); }
    //if (done==0) { document.write('<img src=answer.jpg>');}
    }
    Just change the keywords and URL's to whatever you need. Here is the HTML code to drive it - call this whatever you want to;

    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    
    <html>
    <head>
    	<title>Untitled</title>
    	
    <script language="JavaScript" src="keychecker.js">
    <!--
    
    //-->
    </script>	
    
    </head>
    
    <body>
    <center>
    <form name=enter_keyword>
        <table border="1" cellpadding="2" cellspacing="2" bgcolor="#7B97E0">
    	    <tr>
    			<td>
    			<font color="#ffffff"><b>Enter keyword:</b></font>
    			</td>
    			<td><input type=text name=keyword>
    			</td>
    		</tr>
    		<tr>
    			<td colspan=2 align=center>
    			<input type=button value="Login!" onClick="Login()">
    			</td>
    		</tr>
    	</table>
    </form>
    </center>
    </body>
    </html>
    If you want the 'error' output to display an image instead of an alert box then comment out the 'if' statement and UNcomment the document.write statement in the script.
    I've attached a .jpg file for a response that I think will amuse you!!

    I will quickly adapt the quiz if that is what you want. If so, then do they have to get ALL the answers corrct before they are redirectd? Thats easily done but I was'nt quite sure. Just let me know.
    Regards,
    Ges.

    PS It makes a change doing something even dafter than just programming.

  6. #6
    Join Date
    Jan 2007
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    Hey there

    I found this thread by searching on Google, and I need something similar. Instead of a dialogue box showing when finishing the quiz, is it then possible to have the score either below the quiz or on a new page? And also, is it possible to calculate a score with the percentage of correct answers, and have a text attached to every, say, 20% correct answers?

    I know it's an old thread, but I hope you will still see and respond to my post.

    Yours,
    Martin

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
  •