nikolayneykov

Untitled

May 20th, 2019
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve () {
  2.   let counter = 0
  3.   let selectionCounter = 3
  4.   let buttons = Array.from(document.querySelectorAll('.answer-text'))
  5.   buttons.forEach(b => b.addEventListener('click', getAnswer))
  6.   let allSections = Array.from(document.querySelectorAll('section'))
  7.   let sectionIndex = 0
  8.   function getAnswer () {
  9.     allSections[sectionIndex].style.display = 'none'
  10.     if (
  11.       (sectionIndex === 0 && this.textContent === 'onclick') ||
  12.       (sectionIndex === 1 && this.textContent === 'JSON.stringify()') ||
  13.       (sectionIndex === 2 &&
  14.         this.textContent === 'A programming API for HTML and XML documents')
  15.     ) {
  16.       counter++
  17.     }
  18.  
  19.     if (sectionIndex < selectionCounter - 1) {
  20.       allSections[sectionIndex + 1].style.display = 'block'
  21.     }
  22.  
  23.     sectionIndex++
  24.  
  25.     if (sectionIndex === 3) {
  26.       document.querySelector('#results').style.display = 'block'
  27.       let result = document.querySelector('#results h1')
  28.       result.textContent =
  29.         counter === 3
  30.           ? 'You are recognized as top JavaScript fan!'
  31.           : `You have ${counter} right answers`
  32.     }
  33.   }
  34. }
Advertisement
Add Comment
Please, Sign In to add comment