nikolayneykov

Untitled

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