Advertisement
Guest User

Untitled

a guest
Jan 18th, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.05 KB | None | 0 0
  1.  
  2.  
  3. /*var questions = [{
  4. "question" : "Insert question 1 here",
  5. "option1" : "Answer 1",
  6. "option2" : "Answer 2",
  7. "option3" : "Answer 3",
  8. "option4" : "Answer 4",
  9. "answer" : "2",
  10. }, {
  11. "question" : "Insert question 2 here",
  12. "option1" : "Answer 1",
  13. "option2" : "Answer 2",
  14. "option3" : "Answer 3",
  15. "option4" : "Answer 4",
  16. "answer" : "3",
  17. }, {
  18. "question" : "Insert question 3 here",
  19. "option1" : "Answer 1",
  20. "option2" : "Answer 2",
  21. "option3" : "Answer 3",
  22. "option4" : "Answer 4",
  23. "answer" : "4",
  24. }, {
  25. "question" : "Insert question 4 here",
  26. "option1" : "Answer 1",
  27. "option2" : "Answer 2",
  28. "option3" : "Answer 3",
  29. "option4" : "Answer 4",
  30. "answer" : "1",
  31. }];
  32.  
  33.  
  34.  
  35.  
  36.  
  37. var currentQuestion = 0;
  38. var score = 0;
  39. var totQuestions = questons.length;
  40.  
  41. var container = document.getElementById('quizContainer');
  42. var questionEl = document.getElementById('question');
  43. var opt1 = document.getElementById('opt1');
  44. var opt2 = document.getElementById('opt2');
  45. var opt3 = document.getElementById('opt3');
  46. var opt4 = document.getElementById('opt4');
  47. var nextButton = document.getElementById ('nextButton');
  48. var resultCont = document.getElementById ('result');
  49.  
  50. function loadQuestion (questionIndex) {
  51. var q = questions [questionIndex];
  52. questionEl.textContent = (questionIndex + 1) + '. '+ q.question;
  53. opt1.textContent = q.option1;
  54. opt2.textContent = q.option2;
  55. opt3.textContent = q.option3;
  56. opt4.textContent = q.option4;
  57. };
  58.  
  59. function loadNextQuestion () {
  60. var selectedOption = document.querySelector('input[type=radio]:checked');
  61. if (!selectedOption){
  62. alert('Please select your answer');
  63. return;
  64. }
  65. var answer = selectedOption.value;
  66. if (questions[currentQuestion].answer == answer){
  67. score += 10;
  68. }
  69. selectedOption.checked = false;
  70. currentQuestion++;
  71. if(currentQuestion == totQuestions -1{
  72. nextButton.textContent = 'Finish';
  73. }
  74. if(currentQuestion == totQuestions){
  75. container.style.display = 'none';
  76. resultCont.style.display = '';
  77. resultCont.textContent = 'Your Score: ' + score;
  78. return;
  79. }
  80. loadQuestion(currentQuestion);
  81. }
  82. loadQuestion(currentQuestion); */
  83.  
  84.  
  85. var questions = [{
  86. "question" : "For what use was Youtube originally created for?",
  87. "option1" : "Gaming videos",
  88. "option2" : "Memes",
  89. "option3" : "Educational videos",
  90. "option4" : "A dating site",
  91. "answer" : "4",
  92. }, {
  93. "question" : "What is the most searched tutorial on youtube?",
  94. "option1" : "how to tame a dragon",
  95. "option2" : "How to kiss",
  96. "option3" : "How to make a bird house",
  97. "option4" : "how to make chicken nuggets",
  98. "answer" : "2",
  99. }, {
  100. "question" : "The most disliked video on youtube is?",
  101. "option1" : "Despacito",
  102. "option2" : "PewdiePie plays Amnesia",
  103. "option3" : "Justin Biebers baby",
  104. "option4" : "Logan paul finds a dead body",
  105. "answer" : "3",
  106. }, {
  107. "question" : "When was the youtube domain name registerd?",
  108. "option1" : "Valentine’s Day in 2005",
  109. "option2" : "Christmas in 2001",
  110. "option3" : "April fools day in 2003",
  111. "option4" : " 7 December 1997",
  112. "answer" : "1",
  113. }, {
  114. "question" : "How much does a avarage user visit youtube a month?",
  115. "option1" : "14 times",
  116. "option2" : "28 times",
  117. "option3" : "50 times",
  118. "option4" : "100 times",
  119. "answer" : "1",
  120. }, {
  121. "question" : "What is the most watched non music video on youtube?",
  122. "option1" : "The legend of tiny knuckles",
  123. "option2" : "YLYL #9",
  124. "option3" : "Charlie bit my finger",
  125. "option4" : "The onision rant",
  126. "answer" : "3",
  127. }, {
  128. "question" : "Who created youtube",
  129. "option1" : "Chad Hurley",
  130. "option2" : "Steve Chen",
  131. "option3" : "Jawed Karim",
  132. "option4" : "All three of themm",
  133. "answer" : "4",
  134. }, {
  135. "question" : "How much does an avarage user use youtube a hour?",
  136. "option1" : "48 hours",
  137. "option2" : "12 hours",
  138. "option3" : "5 hours",
  139. "option4" : "1 hour",
  140. "answer" : "1",
  141. }, {
  142. "question" : "For how much did google buy youtube",
  143. "option1" : "12 american dollars",
  144. "option2" : "They just stole it!",
  145. "option3" : "1.65 Billion",
  146. "option4" : "12.5 million",
  147. "answer" : "3",
  148. }, {
  149. "question" : "How much time would you need to watch all the youtube content",
  150. "option1" : "1,700 years",
  151. "option2" : "13 years and 5 days",
  152. "option3" : "100 years",
  153. "option4" : "a full week without sleeping",
  154. "answer" : "1",
  155. }];
  156.  
  157. var appContainer = document.getElementById('cont'),
  158. questionEl = document.getElementById('question'),
  159. opt1 = document.getElementById('opt1'),
  160. opt2 = document.getElementById('opt2'),
  161. opt3 = document.getElementById('opt3'),
  162. opt4 = document.getElementById('opt4'),
  163. nxtBtn = document.getElementById('next'),
  164. result = document.getElementById('result'),
  165.  
  166. currentQuestion = 0,
  167. totQuestions = questions.length,
  168. score = 0;
  169.  
  170.  
  171. function loadQuestion(questionIndex) {
  172. 'use strict';
  173. var q = questions[questionIndex];
  174. questionEl.textContent = (questionIndex + 1) + '. ' + q.question;
  175. opt1.textContent = q.option1;
  176. opt2.textContent = q.option2;
  177. opt3.textContent = q.option3;
  178. opt4.textContent = q.option4;
  179. }
  180.  
  181. function loadNextQuestion() {
  182. 'use strict';
  183. var selectedOption = document.querySelector('input[type=radio]:checked'),
  184. answer;
  185. if (!selectedOption) {
  186. alert('Please Select Your Answer');
  187. return;
  188. }
  189. answer = selectedOption.value;
  190. if (questions[currentQuestion].answer === answer) {
  191. score += 10;
  192. }
  193. selectedOption.checked = false;
  194. currentQuestion += 1;
  195. if (currentQuestion === totQuestions - 1) {
  196. nxtBtn.textContent = 'Finish';
  197. }
  198.  
  199. if (currentQuestion === totQuestions) {
  200. appContainer.style.display = 'none';
  201. result.style.display = '';
  202. result.textContent = 'Your Score: ' + score;
  203. return;
  204. }
  205. loadQuestion(currentQuestion);
  206. }
  207. loadQuestion(currentQuestion);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement