Advertisement
Lulunga

DOM 03. JavaScript Quizz

Oct 21st, 2019
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve() {
  2.   let point = 0;
  3.   let result = document.getElementById('results');
  4.   let answers = document.getElementsByTagName('p');
  5.  
  6.   let section = document.getElementsByTagName('section');
  7.   section[0].style.display = 'block';
  8.  
  9.   document.body.addEventListener('click', (e) => {
  10.  
  11.     if (section[0].style.display == 'block') {
  12.       if (e.target === answers[0]) {
  13.         point++;
  14.       }
  15.  
  16.       section[0].style.display = 'none';
  17.       section[1].style.display = 'block';
  18.     } else if (section[1].style.display == 'block') {
  19.       if (e.target === answers[3]) {
  20.         point++;
  21.       }
  22.  
  23.       section[1].style.display = 'none';
  24.       section[2].style.display = 'block';
  25.     } else if (section[2].style.display == 'block') {
  26.       if (e.target === answers[4]) {
  27.         point++;
  28.       }
  29.  
  30.       section[2].style.display = 'none';
  31.      
  32.       (point === 3)
  33.         ? result.children[0].children[0].textContent = 'You are recognized as top JavaScript fan!'
  34.         : result.children[0].children[0].textContent = `You have ${point} right answers`;
  35.  
  36.       result.style.display = 'block';
  37.     }
  38.   });
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement