Advertisement
nikolayneykov

Untitled

May 18th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function solve () {
  2.   let allSections = document.querySelectorAll('section')
  3.   let wrongAnswersCount = 0
  4.  
  5.   let wrongAnswersText = [
  6.     'onmouseclick',
  7.     'JSON.toString()',
  8.     'The DOM is your source HTML'
  9.   ]
  10.   let sections = Array.from(document.getElementsByTagName('section'))
  11.  
  12.   let answers = document.getElementsByClassName('answer-text')
  13.  
  14.   for (let j = 0; j < answers.length; j++) {
  15.     answers[j].addEventListener('click', function () {
  16.       if (wrongAnswersText.includes(this.innerHTML)) {
  17.         wrongAnswersCount++
  18.       }
  19.  
  20.       let section = sections.shift()
  21.       section.style.display = 'none'
  22.       let nextSection = section.nextElementSibling
  23.       nextSection.style.display = 'block'
  24.       console.log(section)
  25.     })
  26.   }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement