Advertisement
Guest User

Untitled

a guest
Apr 5th, 2018
637
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.31 KB | None | 0 0
  1. var globalScore = 0;
  2. var globalProgress = 0;
  3. var currentAnswer = 0;
  4.  
  5. function createQuestionBlock(i) {
  6. var questionNumber = i + 1;
  7. var qString = "<p>Pytanie nr. " + questionNumber + "<br><b>" + getQuestion(i) + "</b></p>" + br() + "<form>" +
  8. "<label for=\"answer1\"><input type=\"radio\" id=\"answer1\" name=\"answers\" onclick=\"radioOnChange(this," + i + ");\" value=1> " +
  9. getAnswer1(i) + "<\label>" + br() +
  10. "<label for=\"answer2\"><input type=\"radio\" id=\"answer2\" name=\"answers\" onclick=\"radioOnChange(this," + i + ");\" value=2> " +
  11. getAnswer2(i) + "<\label>" + br() +
  12. "<label for=\"answer3\"><input type=\"radio\" id=\"answer3\" name=\"answers\" onclick=\"radioOnChange(this," + i + ");\" value=3> " +
  13. getAnswer3(i) + "<\label>" + br() +
  14. "<label for=\"answer4\"><input type=\"radio\" id=\"answer4\" name=\"answers\" onclick=\"radioOnChange(this," + i + ");\" value=4> " +
  15. getAnswer4(i) + "<\label>" + br() + br();
  16. return qString;
  17.  
  18. }
  19.  
  20. function requiredScore() {
  21.  
  22. return Math.floor(questions.length * (passingPercent / 100));
  23. }
  24.  
  25. function radioOnChange(answers, i) {
  26. if (answers.value == questions[i].aCorrect) {
  27. currentAnswer = answers.value;
  28. } else {
  29. currentAnswer = answers.value;
  30. }
  31. }
  32.  
  33. function nextQuestion() {
  34. if (currentAnswer == questions[globalProgress].aCorrect) {
  35. globalProgress++;
  36. globalScore++;
  37. } else {
  38. globalProgress++;
  39. }
  40. if (globalProgress >= questions.length) {
  41. dprintScore();
  42. } else {
  43. dprint();
  44. }
  45.  
  46.  
  47. }
  48.  
  49. function dprintScore() {
  50. var passString = "";
  51.  
  52. document.getElementById("content").innerHTML = "<center><p>Twój wynik to:<br><b>" + globalScore + "/" + questions.length + "</b>"
  53. }
  54.  
  55. function getRandomQuestion() {
  56. return Math.floor((Math.random() * questions.length));
  57. }
  58.  
  59. function getQuestion(i) {
  60. return questions[i].question;
  61. }
  62.  
  63. function getAnswer1(i) {
  64. return questions[i].a1;
  65. }
  66.  
  67. function getAnswer2(i) {
  68. return questions[i].a2;
  69. }
  70.  
  71. function getAnswer3(i) {
  72. return questions[i].a3;
  73. }
  74.  
  75. function getAnswer4(i) {
  76. return questions[i].a4;
  77. }
  78.  
  79. function getCorrectAnswer(i) {
  80. return questions[i].aCorrect;
  81. }
  82.  
  83. function br() {
  84. return "<br>";
  85. }
  86.  
  87. function fisherYates(array) {
  88. var count = array.length,
  89. randomnumber, temp;
  90. while (count) {
  91. randomnumber = Math.random() * count-- | 0;
  92. temp = array[count];
  93. array[count] = array[randomnumber];
  94. array[randomnumber] = temp
  95. }
  96. }
  97.  
  98. function getQuestionBlock(i) {
  99. return br() + getQuestion(i) + br() +
  100. getAnswer1(i) + br() +
  101. getAnswer2(i) + br() +
  102. getAnswer3(i) + br() +
  103. getAnswer4(i) + br() +
  104. getCorrectAnswer(i) + br() + br() +
  105. "Example question finish";
  106. }
  107.  
  108. function testQuestionBlock() {
  109. var qString = br() + getQuestion(1) + br() +
  110. getAnswer1(1) + br() +
  111. getAnswer2(1) + br() +
  112. getAnswer3(1) + br() +
  113. getAnswer4(1) + br() +
  114. getCorrectAnswer(1) + br() + br() +
  115. "Example question finish" + br();
  116.  
  117. document.getElementById("content").innerHTML = "<br>" + qString + "<br><br>Length of Question Array: " + questions.length + 1;
  118. }
  119.  
  120. function dprint(s) {
  121. document.getElementById("content").innerHTML = createQuestionBlock(globalProgress);
  122. }
  123.  
  124. document.getElementById("settings").innerHTML = "Liczba pytań: " + questions.length;
  125. dprint();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement