Advertisement
bobo_bobkata

Untitled

Oct 9th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.19 KB | None | 0 0
  1. function solve() {
  2. let arr = ['onclick', 'JSON.stringify()', 'A programming API for HTML and XML documents'];
  3. let index = 0;
  4. let rightAnswers = 0;
  5. Array.from(
  6. document.querySelectorAll(".quiz-answer")
  7. ).map(el => el.addEventListener('click', function asd(e) {
  8. if (arr.includes(e.target.innerHTML)) {
  9. rightAnswers++;
  10. }
  11. let currentSelection = document.querySelectorAll('section')[index];
  12. currentSelection.style.display = 'none';
  13. let nextSelection = document.querySelectorAll('section')[index + 1];
  14. if (nextSelection !== undefined) {
  15. nextSelection.style.display = 'block';
  16. } else {
  17. document.getElementById("results").style.display = 'block';
  18. if (rightAnswers === arr.length) {
  19. document.getElementById("results").classList.remove('none');
  20. document.querySelector("#results > li > h1").innerHTML = "You are recognized as top JavaScript fan!";
  21. } else {
  22. document.querySelector("#results > li > h1").innerHTML = `You have ${rightAnswers} right answers`;
  23.  
  24.  
  25. }
  26. }
  27. index++;
  28. }));
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement