Advertisement
Guest User

Untitled

a guest
Sep 8th, 2017
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.18 KB | None | 0 0
  1. /*
  2. -#inner2 starts with 'start' button
  3. -on click, randomly pick a question from array of question objects
  4. -each question object has a question and multiple answers
  5.  
  6. -questions will 'fade' into existence
  7. -answers will swing left and right into #inner 2
  8. -answers will be highlighted on hover
  9. -if wrong, #inner2 changes to red and shakes -- also plays incorrect sound
  10. -if correct, #inner2 changes to green and does some sort of confirmation animation -- also plays correct sound
  11. -if question objects all have 'answered' property set to true, end game screen is shown
  12. -reset button which reloads page
  13. */
  14.  
  15. var questionOne = {
  16. question: "What company invented the floppy disk?",
  17. actualAnswer: "IBM",
  18. answers: ["Apple","Microsoft","IBM"],
  19. answered: false
  20. };
  21.  
  22. var questionTwo = {
  23. question: "What is the first domain name ever registered?",
  24. actualAnswer: "Symblolic.com",
  25. answers: ["WorldWideWeb.com","Symblolic.com","Me.com"],
  26. answered: false
  27. };
  28.  
  29. var questionThree = {
  30. question: "Which company is the largest producer of software for PC?",
  31. actualAnswer: "Microsoft",
  32. answers: ["Google","Microsoft","Dell"],
  33. answered: false
  34. };
  35.  
  36. var questionFour = {
  37. question: "What is CPU?",
  38. actualAnswer: "Central Processing Unit",
  39. answers: ["Central Programming Unit","Central Processing Unit","Central Placement Unit"],
  40. answered: false
  41. };
  42.  
  43. var questionFive = {
  44. question: "What is RAM?",
  45. actualAnswer: "Random Access Memory",
  46. answers: ["Random Access Memory","Random Automatic Memory","Random Automated Memory"],
  47. answered: false
  48. };
  49.  
  50. var questionSix = {
  51. question: "Has modern cell phone computing power surpassed that of the Apollo 11 Lunar Lander?",
  52. actualAnswer: "True",
  53. answers: ["True","False"],
  54. answered: false
  55. };
  56.  
  57. var questionSeven = {
  58. question: "The first computer mouse was constructed in 1964 with what material?",
  59. actualAnswer: "Wood",
  60. answers: ["Metal","Rubber","Wood"],
  61. answered: false
  62. };
  63.  
  64. var questionEight = {
  65. question: "Approximately how many domain names are registered every month? (2014)",
  66. actualAnswer: "1,000,000",
  67. answers: ["200,000","600,000","1,000,000"],
  68. answered: false
  69. };
  70.  
  71. var questionNine = {
  72. question: "Approximately how many web pages are on the internet today? (2014)",
  73. actualAnswer: "20,000,000,000",
  74. answers: ["5,000,000,000","10,000,000,000","20,000,000,000"],
  75. answered: false
  76. };
  77.  
  78. var questionTen = {
  79. question: "What does 'PCMR' mean?",
  80. actualAnswer: "PC Master Race",
  81. answers: ["PC Master Race","PC Master Race","PC Master Race"],
  82. answered: false
  83. };
  84.  
  85. var questionHolder = [questionOne,questionTwo,questionThree,questionFour,questionFive,questionSix,questionSeven,questionEight,questionNine,questionTen];
  86. var randomQuestion = questionHolder[Math.floor((Math.random() * questionHolder.length) + 0)];
  87. //console.log(randomQuestion);
  88.  
  89. var pickedQuestions = [];
  90.  
  91. if(pickedQuestions.includes(randomQuestion)){
  92. randomQuestion = questionHolder[Math.floor((Math.random() * questionHolder.length) + 0)];
  93. }else{
  94. pickedQuestions.push(randomQuestion);
  95. //console.log(pickedQuestions);
  96. }
  97.  
  98. function nextQuestion(){
  99. randomQuestion = questionHolder[Math.floor((Math.random() * questionHolder.length) + 0)];
  100.  
  101. if(pickedQuestions.includes(randomQuestion)){
  102. randomQuestion = questionHolder[Math.floor((Math.random() * questionHolder.length) + 0)];
  103. }else{
  104. pickedQuestions.push(randomQuestion);
  105. //console.log(pickedQuestions);
  106. }
  107. }
  108.  
  109. $('#start').on("click",function(){
  110. $('#inner').html("<p class='animated fadeInUp' style='font-family: Bungee;position: relative;top: 40px'>" + randomQuestion.question + "</p>");
  111. for(var i = 0; i < randomQuestion.answers.length; i++){
  112. $('#inner2').append("<div id='inner3' class='animated bounceInUp'>" + "<p id='inner3-sub'>" + randomQuestion.answers[i] + "</p>" + "</div>");
  113. }
  114. });
  115.  
  116. $('#inner3').on("click",function(){
  117. var currentText = $(this).find("inner3-sub").text(),
  118. trimmedText = $.trim(currentText);
  119. if (trimmedText == randomQuestion.actualAnswer) {
  120. $('.container').css("background-color", "#0dd913");
  121. } else {
  122. $('.container').css("background-color", "#e7170d");
  123. }
  124. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement