Advertisement
Guest User

Untitled

a guest
Feb 26th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.35 KB | None | 0 0
  1. let counter = 0;
  2. let correct = 0;
  3.  
  4. let db_matrix = {
  5. question_1: "Is Donald Trump the president of the United States?",
  6. queston_1_correct: "Donald Trump is currently the president.",
  7. question_1_wrong: "Donald Trump is currently not the president.",
  8.  
  9. question_2: "Is the creator of this program called Edin?",
  10. queston_2_correct: "Yes, the creator of this program is Edin.",
  11. question_2_wrong: "No, the creator of this program is John.",
  12.  
  13. question_3: "Are complex passwords an important security measure?",
  14. queston_3_correct: "Complex passwords are not important anymore.",
  15. question_3_wrong: "Complex passwords are an important security measure."
  16. };
  17.  
  18. // appending HTML code to the DOM
  19. html_inject = (in_1,in_2,in_4) => {
  20. in_1 = document.getElementById(in_2);
  21. in_1.insertAdjacentHTML('afterend', in_4);
  22. };
  23.  
  24. let qstn_str_1 = document.getElementById('strt_1');
  25. qstn_str_1.addEventListener("click", function() {
  26. // remove intial quiz instructions
  27. let prt_qz = document.getElementById("quiz");
  28. let chld_qz = document.getElementById("question");
  29. prt_qz.removeChild(chld_qz);
  30.  
  31. // remove "start quiz" button
  32. let chld_qz_btn = document.getElementById("strt_1");
  33. prt_qz.removeChild(chld_qz_btn);
  34.  
  35. // raw HTML data for the question, answers and buttons.
  36. let qstn_strg_qst = '<h2 id="question" class="headline-secondary--grouped">' + db_matrix.question_1 + '</h2>';
  37. let qstn_strg0 = '<p id="choice0">' + db_matrix.queston_1_correct + '</p>';
  38. let qstn_strg1 = '<button id="guess0" class="btn--default">Select Answer</button>';
  39. let qstn_strg2 = '<p id="choice1">' + db_matrix.question_1_wrong +'</p>';
  40. let qstn_strg3 = '<button id="guess1" class="btn--default">Select Answer</button>';
  41.  
  42. // Question 1, Answer 1, Answer 1 button, Answer 2, Answer 2 button ==> html injection
  43. html_inject(document.getElementById("quiz_title"), "quiz_title", qstn_strg_qst);
  44. html_inject(document.getElementById("question"), "question", qstn_strg0);
  45. html_inject(document.getElementById("choice0"), "choice0", qstn_strg1);
  46. html_inject(document.getElementById("guess0"), "guess0", qstn_strg2);
  47. html_inject(document.getElementById("choice1"), "choice1", qstn_strg3);
  48.  
  49. // change question counter
  50. let prgs = document.getElementById('progress')
  51. counter ++;
  52. prgs.innerHTML = "Question " + counter + " of 3";
  53.  
  54.  
  55. // *** QUESTION ONE CODE BLOCK ***
  56.  
  57. // ** BUTTON ONE **
  58. let qstn_str_2 = document.getElementById('guess0')
  59. qstn_str_2.addEventListener("click", function() {
  60. console.log("clicked!");
  61. console.log(this);
  62.  
  63. });
  64.  
  65. // ** BUTTON TWO **
  66. let qstn_str_3 = document.getElementById('guess1')
  67. qstn_str_3.addEventListener("click", function() {
  68. page_builder(this.id);
  69.  
  70. });
  71.  
  72. page_builder = (bttn) => {
  73. // grab all IDs for (1) question and all answers
  74. let qst_1 = document.getElementById('question');
  75. let prnt = document.getElementById('quiz')
  76.  
  77. // two answers to be removed
  78. let answers_1 = document.getElementById('choice0');
  79. let answers_2 = document.getElementById('choice1');
  80. prnt.removeChild(answers_1);
  81. prnt.removeChild(answers_2);
  82. prnt.removeChild(qst_1);
  83.  
  84. // Updating counter
  85. let prgs = document.getElementById('progress')
  86. counter ++;
  87. prgs.innerHTML = "Question " + counter + " of 3";
  88.  
  89. let answr_0 = bttn;
  90. console.log(bttn);
  91. };
  92.  
  93.  
  94. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement