daily pastebin goal
40%
SHARE
TWEET

4jon

a guest Mar 20th, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title>Quiz!</title>
  5. <meta charset="utf-8">
  6.  
  7. <link rel="stylesheet" type="text/css" href="quiz.css">
  8. </head>
  9. <body>
  10. <h1>Pop Quiz</h1>
  11.   <form id="quiz">
  12.     <div id="animal">What is Ashley's favourite animal?
  13.     </br><input type="radio" name="question0" value="sheep">Sheep
  14.     </br><input type="radio" name="question0" value="dog">Dog
  15.     </br><input type="radio" name="question0" value="cat">Cat
  16.     </br><input type="radio" name="question0" value="dragon">Dragon
  17. </div>
  18.     </br>
  19.     </br>
  20.   <div id="food">What is Ashley's favourite food?
  21. </br><input type="radio" name="question1" value="padthai">Pad Thai
  22. </br><input type="radio" name="question1" value="inoodle">Instant Noodles
  23. </br><input type="radio" name="question1" value="sushi">Sushi
  24. </br><input type="radio" name="question1" value="kale">Kale Salad
  25. </div>
  26. </br>
  27. </br>
  28. <div id="retirement">Where does Ashley want to retire?
  29. </br><input type="radio" name="question2" value="italy">Italy
  30. </br><input type="radio" name="question2" value="korea">South Korea
  31. </br><input type="radio" name="question2" value="thailand">Thailand
  32. </br><input type="radio" name="question2" value="singapore">Hyrule
  33. </div>
  34. </br>
  35. </br>
  36.   <div id="hobby">What is Ashley's favourite hobby?
  37. </br><input type="radio" name="question3" value="swimming">Swimming
  38. </br><input type="radio" name="question3" value="knitting">Knitting
  39. </br><input type="radio" name="question3" value="netflix">Netflix
  40. </br><input type="radio" name="question3" value="reading">Reading
  41. </div>
  42. </br>
  43. </br>  <button onclick="returnScore()">Submit Quiz</button>
  44. </br>  <div id="results"></div>
  45. </form>
  46.  
  47. <p id="ok"></p>
  48. <p id="fail"></p>
  49.  
  50.  
  51. </body>
  52. <script>
  53.  
  54. var answers = ["sheep","sushi","thailand","knitting"],
  55.     tot = answers.length;
  56.  
  57. function getCheckedValue( radioName ){
  58.     var radios = document.getElementsByName( radioName ); // Get radio group by-name
  59.     for(var y=0; y<radios.length; y++)
  60.       if(radios[y].checked) return radios[y].value; // return the checked value
  61. }
  62.  
  63. function getScore(){
  64.   var score = 0;
  65.   for (var i=0; i<tot; i++)
  66.     if(getCheckedValue("question"+i)===answers[i]) score += 1; // increment only
  67.   return score;
  68.  
  69. }
  70.  
  71. function returnScore(){
  72.   if (getScore()==4){
  73.     window.alert("<3")
  74.   } else {
  75.     window.alert(":(")
  76.   }
  77.  
  78. }
  79. </script>
  80. </html>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top