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 7 of 7
  1. #1
    New to the CF scene
    Join Date
    Sep 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help about creating a Quiz in Javascript!

    Hello i have an assignment about creating a quiz in javascript which will display the score at the end and then an alert with the wrong answers. I have this code but i don't know what is going wrong. Can you help me please?
    Code:
    <html>
    <head>
    	<title>Ioanna Michael - Personal Portfolio</title>
    	<link rel="stylesheet" type="text/css" href="im.michael.css" />
    	<script>
    		var totalquestions=4;
    		var actualchoices=new Array()
    		var correctchoices=new Array()
    			correctchoices[0]='b' 
    			correctchoices[1]='c' 
    			correctchoices[2]='b'
    			correctchoices[3]='c'
    		function getScore(){
    			var incorrect=null
    			for (i=1;i<=totalquestions;i++){
    			var thequestion=eval("document.immichael.question"+i)
    				for (j=0;j<thequestion.length;j++){
    				if (thequestion[j].checked==true)
    				actualchoices[i]=thequestion[j].value
    			}
    		
    			if (actualchoices[i]!=correctchoices[i]){ 
    			if (incorrect==null)
    			incorrect=i
    			else
    			incorrect+="/"+i
    			}
    		}
    		}
    	</script>
    </head>
    
    <body>
    	<div id="table">
    		<table width="1000px" border="0">
    			<tr>
    				<th colspan="2"><img src="header.jpg" width="1000px"/></th>
    			</tr>
    			<tr>
    				<td class="menu">
    					<p><a href="http://www.youtube.com/watch?v=EAfaIAnSOjc&feature=player_embedded">3d Modelling</a></p>
    					<p><a href="http://www.youtube.com/watch?v=uEvOuhefOks">Video Production</a></p>
    					<p><a href="http://www.facebook.com/ioanna.michael1">Contact Us</a></p>
    				<div id="info">
    					<p style="color:white;"><img src="facebook_logo_2.jpg" width="20px"/>&nbsp;&nbsp;ioanna.michael1</p>
    					<p style="color:white;"><img src="phone-rotary-symbol.png" width="20px"/>&nbsp;&nbsp;96 844741</p>
    				</div>
    				</td>
    				<td>
    					<div id="quiz">
    					<form method="POST" name="immichael">
    						<h2><b>Quiz</b></h2>
    						<ol>
    							<li>Ti simainei CSS?</li>
    							<ul>
    								<li><input type="radio" name="css" value="a">Colourful Style Symbols</input></li>
    								<li><input type="radio" name="css" value="b">Cascading Style Sheets</input></li>
    								<li><input type="radio" name="css" value="c">Computer Style Symbols</input></li>
    							</ul>
    							<li>Ti simainei HTML?</li>
    							<ul>
    								<li><input type="radio" name="html" value="a">Hypno-tic markup language</input></li>
    								<li><input type="radio" name="html" value="b">Hyper-text mathematical language</input></li>
    								<li><input type="radio" name="html" value="c">Hyper-text markup language</input></li>
    							</ul>
    							<li>Me poia etiketa eisagoume ena senario Javascript?</li>
    							<ul>
    								<li><input type="radio" name="java" value="a">&lt;form&gt;&lt;/form&gt;</input></li>
    								<li><input type="radio" name="java" value="b"> &lt;script&gt;&lt;/script&gt;</input></li>
    								<li><input type="radio" name="java" value="c">&lt;javascript&gt;&ltjavascript&gt;</input></li>
    							</ul>
    							<li>Me poia entoli orizoume mia sinartisi?</li>
    							<ul>
    								<li><input type="radio" name="function" value="a">Script</input></li>
    								<li><input type="radio" name="function" value="b">Program</input></li>
    								<li><input type="radio" name="function" value="c">Function</input></li>
    							</ul>
    						</ol>
    						<button onClick="reset()">Clear Answers</button>
    					</form>
    
    						<input type="button" value="Get Score" name="score" onClick="getScore()"/>
    						<p>Score=<input type="text" name="sc"/></p>
    
                        <form method="POST">
    						<script>
    							var wrong=0
    							for (e=0;e<=2;e++)
    								document.result[e].value=""
    
    								var results=document.cookie.split(";")
    								for (n=0;n<=results.length-1;n++){
    									if (results[n].charAt(1)=='sc')
    									parse=n
    
    									}
    
    								var incorrect=results[parse].split("=")
    								incorrect=incorrect[1].split("/")
    								if (incorrect[incorrect.length-1]=='b')
    								incorrect=""
    								document.result[0].value=totalquestions-incorrect.length+" out of "+totalquestions
    								document.result[2].value=(totalquestions-incorrect.length)/totalquestions*100+"%"
    								for (temp=0;temp<incorrect.length;temp++)
    								document.result[1].value+=incorrect[temp]+", "
    
    
    							</script>
    						</form>
    					
    					</div>	
    					
    							
    				</td>
    			</tr>
    			<tr>
    				<td>
    				</td>
    				<td>
    					</br>
    					<p><iframe width="700" height="400" src="http://www.youtube.com/embed/-HO27zsX3Bw?feature=player_embedded" frameborder="0" allowfullscreen></iframe></p>
    				</td>
    			</tr>
    			<tr>
    				<td class="footer"><th colspan="2">Ioanna Michael Copyrights 2012</th></td>
    			</tr>
    		</table>
    	</div>
    </body>
    </html>

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,017
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    Have you tried using your error console?

    Apart from a brace { } every Javascript statement should be followed by a semi-colon (;). It is quite possible to disregard this advice, but if you do one day it will rise up and bite you in the undercarriage.
    Last edited by Philip M; 09-30-2012 at 10:24 AM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #3
    New to the CF scene
    Join Date
    Sep 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Even with this ";" the coding doesn't work can you help me?

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,017
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    Suggest you fix the errors in your markup first. See http://validator.w3.org/

    33 errors, 12 warnings

    Quizzes have been covered very many times in this forum. Try using the search feature.

    The problem with any quiz such as this where the scoring is done via JavaScript is that it is as secure as tissue paper. Anybody who has the least understanding of Javascript will do View Source and peek at the HTML and JS code and know the answers.
    Last edited by Philip M; 09-30-2012 at 04:41 PM.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #5
    New to the CF scene
    Join Date
    Sep 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Can you please give me an example or explain me further? I know how to make view source but i have only knowledge on html and no javascript and i can't really understand how it works

  • #6
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,087
    Thanks
    38
    Thanked 498 Times in 492 Posts
    Quote Originally Posted by joanmicham View Post
    Can you please give me an example or explain me further? I know how to make view source but i have only knowledge on html and no javascript and i can't really understand how it works
    Start here...
    http://www.google.com/search?q=site%...ipt+quiz&se=on

  • #7
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,017
    Thanks
    203
    Thanked 2,538 Times in 2,516 Posts
    Quote Originally Posted by joanmicham View Post
    i have only knowledge on html and no javascript and i can't really understand how it works
    So how come that you have an assignment involving Javascript?

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Posting Permissions

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