Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve () {
- let counter = 0
- let selectionCounter = 3
- let buttons = Array.from(document.querySelectorAll('.answer-text'))
- buttons.forEach(b => b.addEventListener('click', getAnswer))
- let allSections = Array.from(document.querySelectorAll('section'))
- let sectionIndex = 0
- function getAnswer () {
- allSections[sectionIndex].style.display = 'none'
- if (
- (sectionIndex === 0 && this.textContent === 'onclick') ||
- (sectionIndex === 1 && this.textContent === 'JSON.stringify()') ||
- (sectionIndex === 2 &&
- this.textContent === 'A programming API for HTML and XML documents')
- ) {
- counter++
- }
- if (sectionIndex < selectionCounter - 1) {
- allSections[sectionIndex + 1].style.display = 'block'
- }
- sectionIndex++
- if (sectionIndex === 3) {
- document.querySelector('#results').style.display = 'block'
- let result = document.querySelector('#results h1')
- result.textContent =
- counter === 3
- ? 'You are recognized as top JavaScript fan!'
- : `You have ${counter} right answers`
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment