Advertisement
Guest User

Untitled

a guest
Jun 24th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.40 KB | None | 0 0
  1. // ADINA: This structure works but a constructor object would help you avoid repeating code. It would look something like this:
  2.  
  3. // var questions = [];
  4. // function question(question, answers, correctAnswer) {
  5. // this.question = question;
  6. // this.answers = answers;
  7. // this.correctAnswer = correctAnswer;
  8. // questions.push(this);
  9. // }
  10.  
  11. // var q1 = new question("Who was the team’s coach in the 1999-2000 season?",["Dean Smith", "Bill Guthridge", "Matt Doherty", "Roy Williams"]);
  12.  
  13. //Missing is code that on click would access file for "gun cocking".
  14. //Second Sound File would be accessed upon a wrong answer and would fire a shot.
  15.  
  16. var triviaQuestions = [{
  17. question: "Which villian's weapon was a hat?",
  18. answerList: ["Odd Job", "Jaws", "Xenia Onatopp", "Auric Goldfinger"],
  19. answer: 0
  20. },{
  21. question: "How does Goldfinger try to kill James Bond?",
  22. answerList: ["Gun","Laser","Car Bomb","Strangulation"],
  23. answer: 1
  24. },{
  25. question: "What is Octopussy's main talent?",
  26. answerList: ["Criminal Mastermind", "Gymnast", "Pilot", "World-class hotdog eating champ"],
  27. answer: 2
  28. },{
  29. question: "Who is notorius for using a golden gun?",
  30. answerList: ["Ernst Stavro Blofeld","Alec Trevelyan","Francisco Scaramanga","Dr. Kananga"],
  31. answer: 2
  32. },{
  33. question: "Who was the first actor to portray James Bond?",
  34. answerList: ["Daniel Craig", "Zac Efron", "George Lazenby", "Sean Connery"],
  35. answer: 3
  36. },
  37. {
  38. question: "What type of gun does James Bond use?",
  39. answerList: ["Ak-47","Walther PPK","Machine Gun","Glock"],
  40. answer: 1
  41. },{
  42. question: "What does the second 'E' in SPECTRE stand for?",
  43. answerList: ["Extortion","Extinction","Extermination","Elimination"],
  44. answer: 0
  45. },{
  46. question: "Who created James Bond?",
  47. answerList: ["J.K. Rowling", "Ian Fleming", "Mario Puzo", "Tom Clancy"],
  48. answer: 1
  49. },{
  50. question: "What is James Bond's Military Rank?",
  51. answerList: ["Private First Class","Colonel British Army","007 Agent","Commander in the Royal Navy"],
  52. answer: 3
  53. },{
  54. question: "What is Q's Real Name?",
  55. answerList: ["It's Actually Q"," Sir Christopher Smith","Major Geoffrey Boothroyd","Colonel William Lawrence"],
  56. answer: 2
  57. },]
  58.  
  59. var gifArray = ['question1', 'question2', 'question3', 'question4', 'question5', 'question6', 'question7', 'question8','question9','question10'];
  60. var currentQuestion; var correctAnswer; var incorrectAnswer; var unanswered; var seconds; var time; var answered; var userSelect;
  61. var messages = {
  62. correct: "Way to go Double-0!",
  63. incorrect: "You might want Q to answer these for you",
  64. endTime: "Out of time!",
  65. finished: "The mission is over,<br> did you come out unscathed."
  66. }
  67.  
  68. $('#startBtn').on('click', function(){
  69. $(this).hide();
  70. game();
  71. });
  72.  
  73. $('#startOverBtn').on('click', function(){
  74. $(this).hide();
  75. game();
  76. });
  77.  
  78. function game(){
  79. $('#finalMessage').empty();
  80. $('#correctAnswers').empty();
  81. $('#incorrectAnswers').empty();
  82. $('#unanswered').empty();
  83. currentQuestion = 0;
  84. correctAnswer = 0;
  85. incorrectAnswer = 0;
  86. unanswered = 0;
  87. Question();
  88. }
  89.  
  90. function Question(){
  91. $('#message').empty();
  92. $('#correctedAnswer').empty();
  93. $('#gif').empty();
  94. answered = true;
  95.  
  96.  
  97. $('#currentQuestion').html('Question #'+(currentQuestion+1)+'/'+triviaQuestions.length);
  98. $('.question').html('<h3>' + triviaQuestions[currentQuestion].question + '</h3>');
  99. for(var i = 0; i < 4; i++){
  100. var choices = $('<div>');
  101. choices.text(triviaQuestions[currentQuestion].answerList[i]);
  102. choices.attr({'data-index': i });
  103. choices.addClass('thisChoice');
  104. $('.answerList').append(choices);
  105. }
  106. countdown();
  107.  
  108. $('.thisChoice').on('click',function(){
  109. userSelect = $(this).data('index');
  110. clearInterval(time);
  111. answers();
  112. });
  113. }
  114.  
  115. function countdown(){
  116. seconds = 15;
  117. $('#timeLeft').html('<h3>Time Remaining: ' + seconds + '</h3>');
  118. answered = true;
  119.  
  120. time = setInterval(showCountdown, 1000);
  121. }
  122.  
  123. function showCountdown(){
  124. seconds--;
  125. $('#timeLeft').html('<h3>Time Remaining: ' + seconds + '</h3>');
  126. if(seconds < 1){
  127. clearInterval(time);
  128. answered = false;
  129. answers();
  130. }
  131. }
  132.  
  133. function answers(){
  134. $('#currentQuestion').empty();
  135. $('.thisChoice').empty();
  136. $('.question').empty();
  137.  
  138. var rightAnswerText = triviaQuestions[currentQuestion].answerList[triviaQuestions[currentQuestion].answer];
  139. var rightAnswerIndex = triviaQuestions[currentQuestion].answer;
  140. $('#gif').html('<img src = "assets/images/'+ gifArray[currentQuestion] +'.jpg" width = "200px">');
  141.  
  142. if((userSelect == rightAnswerIndex) && (answered == true)){
  143. correctAnswer++;
  144. $('#message').html(messages.correct);
  145. } else if((userSelect != rightAnswerIndex) && (answered == true)){
  146. incorrectAnswer++;
  147. $('#message').html(messages.incorrect);
  148. $('#correctedAnswer').html('The correct answer was: ' + rightAnswerText);
  149. } else{
  150. unanswered++;
  151. $('#message').html(messages.endTime);
  152. $('#correctedAnswer').html('The correct answer was: ' + rightAnswerText);
  153. answered = true;
  154. }
  155.  
  156. if(currentQuestion == (triviaQuestions.length-1)){
  157. setTimeout(scoreboard, 5000)
  158. } else{
  159. currentQuestion++;
  160. setTimeout(Question, 5000);
  161. }
  162. }
  163.  
  164. function scoreboard(){
  165. $('#timeLeft').empty();
  166. $('#message').empty();
  167. $('#correctedAnswer').empty();
  168. $('#gif').empty();
  169.  
  170. $('#finalMessage').html(messages.finished);
  171. $('#correctAnswers').html("Correct Answers: " + correctAnswer);
  172. $('#incorrectAnswers').html("Incorrect Answers: " + incorrectAnswer);
  173. $('#unanswered').html("Unanswered: " + unanswered);
  174. $('#startOverBtn').addClass('reset');
  175. $('#startOverBtn').show();
  176. $('#startOverBtn').html('Start Over?');
  177. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement