Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-30-2012, 02:43 AM   PM User | #1
joanmicham
New to the CF scene

 
Join Date: Sep 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
joanmicham is an unknown quantity at this point
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>
joanmicham is offline   Reply With Quote
Old 09-30-2012, 10:20 AM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,044
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
__________________

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.

Last edited by Philip M; 09-30-2012 at 10:24 AM..
Philip M is offline   Reply With Quote
Old 09-30-2012, 02:19 PM   PM User | #3
joanmicham
New to the CF scene

 
Join Date: Sep 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
joanmicham is an unknown quantity at this point
Even with this ";" the coding doesn't work can you help me?
joanmicham is offline   Reply With Quote
Old 09-30-2012, 04:23 PM   PM User | #4
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,044
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
__________________

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.

Last edited by Philip M; 09-30-2012 at 04:41 PM..
Philip M is offline   Reply With Quote
Old 10-01-2012, 12:07 AM   PM User | #5
joanmicham
New to the CF scene

 
Join Date: Sep 2012
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
joanmicham is an unknown quantity at this point
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
joanmicham is offline   Reply With Quote
Old 10-01-2012, 03:34 AM   PM User | #6
jmrker
Senior Coder

 
jmrker's Avatar
 
Join Date: Aug 2006
Location: FL
Posts: 2,765
Thanks: 29
Thanked 453 Times in 447 Posts
jmrker will become famous soon enough
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
jmrker is offline   Reply With Quote
Old 10-01-2012, 07:51 AM   PM User | #7
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,044
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
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.
Philip M is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:46 PM.


Advertisement
Log in to turn off these ads.