Advertisement
vdjalov

Softuni Quiz

Jan 22nd, 2019
599
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. function solve() {
  2.  
  3. let count = 0;
  4. let sections = document.querySelectorAll("section");
  5. let radioButtons = document.querySelectorAll("#exercise section input[type=radio]");
  6. let normalButtons = document.querySelectorAll("button");
  7.  
  8. for(let i = 0 ; i < radioButtons.length; i++){
  9. radioButtons[i].addEventListener("click", questions);
  10. }
  11.  
  12. function questions(e){
  13. let target = e.target;
  14. let name = target.name;
  15.  
  16. if(name == "softUniYear"){
  17. let input1 = sections[0].querySelectorAll("input");
  18. for(let i = 0; i < input1.length; i++){
  19. input1[i].checked = false;
  20. }
  21. target.checked = true;
  22.  
  23. }else if(name == "popularName"){
  24. let input2 = sections[1].querySelectorAll("input");
  25. for(let i = 0; i < input2.length; i++){
  26. input2[i].checked = false;
  27. }
  28. target.checked = true;
  29. }else if(name == "softUniFounder"){
  30. let input3 = sections[2].querySelectorAll("input");
  31. for(let i = 0; i < input3.length; i++){
  32. input3[i].checked = false;
  33. }
  34. target.checked = true;
  35. }
  36. }
  37.  
  38. for(let i = 0 ; i < normalButtons.length; i++){
  39. normalButtons[i].addEventListener("click", next);
  40. }
  41.  
  42.  
  43. function next(e){
  44. if(count == 0){
  45. sections[1].style.display = "block";
  46. count++;
  47. }else if(count == 1){
  48. sections[2].style.display = "block";
  49. count++;
  50. }else if(count == 2){
  51. let answers = ["2013", "Pesho", "Nakov"];
  52. let score = 0;
  53. for(let i = 0; i < radioButtons.length; i++){
  54. if(radioButtons[i].checked){
  55. if(answers.includes(radioButtons[i].value)){
  56. score++;
  57. }
  58. }
  59. }
  60. let result = document.getElementById("result");
  61.  
  62. if(score == 3){
  63. result.textContent = `You are recognized as top SoftUni fan!`;
  64. }else {
  65. result.textContent = `You have ${score} right answers`;
  66. }
  67. }
  68. }
  69.  
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement