Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve () {
- let rightAnswers = [
- 'onclick',
- 'JSON.stringify()',
- 'A programming API for HTML and XML documents'
- ]
- let rightAnswersCounter = 0
- Array.from(document.querySelectorAll('.answer-text')).forEach(el =>
- el.addEventListener('click', checkAnswer)
- )
- function checkAnswer (el) {
- let currentAnswer = el.target.innerHTML
- currentSection = el.target.parentNode.parentNode.parentNode.parentNode
- nextSection = currentSection.nextElementSibling
- rightAnswers.includes(currentAnswer)
- ? rightAnswersCounter++
- : (rightAnswersCounter += 0)
- currentSection.style.display = 'none'
- nextSection.style.display = 'block'
- if (nextSection.id === 'results') {
- let resultElement = document.querySelector('#results h1')
- rightAnswersCounter === 3
- ? (resultElement.innerHTML =
- 'You are recognized as top JavaScript fan!')
- : (resultElement.innerHTML = `You have ${rightAnswersCounter} right answers`)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment