Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <form id="quiz">
- <label>1. What house at Hogwarts did Harry belong to?</label><br>
- <input type="text" id="firstQ"><span id="firstA"></span><br><br>
- <label>2. Which pet did Harry own?</label><br>
- <input type="text" id="secondQ"><span id="secondA"></span><br><br>
- <label>3. What was the name of Harry's pet?</label><br>
- <input type="text" id="thirdQ"><span id="thirdA"></span><br><br>
- <label>4. What is Harry's patronus ?</label><br>
- <input type="text" id="fourthQ"><span id="fourthA"></span><br><br>
- <label>5. Did Harry's pet die?</label><br>
- <input type="radio" id="correct" value="True" name="answer">
- <label>True</label>
- <input type="radio" id="wrong" value="False" name="answer">
- <label>False</label> <span id="fifthA"></span>
- <br><br><input type="button" id="submit" value="Submit" onclick="submitQuiz()">
- </form>
- </div>
- <script>
- var firstQuestion = document.getElementById('firstQ');
- var secondQuestion = document.getElementById('secondQ');
- var thirdQuestion = document.getElementById('thirdQ');
- var fourthQuestion = document.getElementById('fourthQ');
- var trueBox = document.getElementById('correct');
- var wrongBox = document.getElementById('wrong');
- var result = 0;
- var count = 0;
- var fq = firstQuestion.value;
- var sq = secondQuestion.value;
- var tq = thirdQuestion.value;
- var fourq = fourthQuestion.value;
- function submitQuiz(){
- if(fq.toLowerCase() == "gryffindor"){
- result++;
- count++;
- }
- else{
- document.getElementById('firstA').innerHTML = "Correct Answer: Gryffindor";
- count++;
- }
- if(sq.toLowerCase() == "owl"){
- result++;
- count++;
- }
- else{
- document.getElementById('secondA').innerHTML = "Correct Answer: Owl";
- count++;
- }
- if(tq.toLowerCase() == "hedwig"){
- result++;
- count++;
- }
- else{
- document.getElementById('thirdA').innerHTML = "Correct Answer: Hedwig";
- count++;
- }
- if(fourq.toLowerCase() == "stag"){
- result++;
- count++;
- }
- else{
- document.getElementById('fourthA').innerHTML = "Correct Answer: Stag";
- count++;
- }
- if(trueBox.checked == true){
- result++;
- count++;
- }
- else if(wrongBox.checked == true){
- document.getElementById('fifthA').innerHTML = "Correct Answer: True";
- count++;
- }
- else{
- alert("Error! True or False question is not answered.")
- }
- if(count == 5){
- alert("Your Score is " + (result*20));
- count = 0;
- }
- else{
- alert("You have a question not answered");
- }
- }
- </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement