I need help: How to make a simple Javascript Quiz?

Kaves

New member
Joined
Oct 3, 2011
Messages
0
Reaction score
0
Points
0
I am a beginner in Javascrip and I'm trying out for the first time in making a simple javascript quiz. Basically I have a question with a multiple choice of 3 radio buttons, and I want an alert to come out once the user selects/clicks a choice in the radio buttons. This alert would tell if the user got the correct or wrong answer. And ultimately, at the end, I want the score to be tallied/add up and display the result.

Here is the code that I am working on:


<form name="form1" method="post" action="">
<p>From what TV show does the phrase Bazinga come from? <br>
<label>
<input type="radio" name="bazinga" value="1" onClick="answer()">
The Big Bang Theory</label>
<br>
<label>
<input type="radio" name="bazinga" value="2" onClick="answer()">
The Puppet Show</label>
<br>
<label>
<input type="radio" name="bazinga" value="3" onClick="answer()">
Giligan's Island</label>
<br>
<input type="button" name="Button" value="Get Score" onClick="score()">
<input name="score" type="text" id="score">
</p>
</form>
</body>

<SCRIPT language = javascript>
var score = 0;

function answer(){
answer = document.form1.bazinga.value

if (answer == 1) {
alert("You got the correct answer!");
score += 1
}
else {
alert("I am sorry, the correct answer is The Big Bang Theory")
}
}

function score(){
document.form1.score.value = score +

</SCRIPT>
</html>

I apologize, I am just a newbie at this. Thanks for advance!
Sorry I got the last part wrong, in the code:

function score(){
document.form1.score.value = score
}

</SCRIPT>
</html>

But anyways, is there something else that I'm missing?
 
Back
Top