Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function solve() {
- let points = 0;
- //let answers = Array.from(document.querySelectorAll('.answer-text'))
- //let[one, two, three, four, five, six] = answers
- let currSection = 0;
- let question = document.getElementsByTagName('section');
- let correctAnswers = ["onclick", "JSON.stringify()", "A programming API for HTML and XML documents"]; //add array with the correct answers
- Array.from(document.querySelectorAll('.answer-text')) //add event to answer-text elements instead of quiz-answer
- .map((x) => x.addEventListener('click', (answer) => {
- if (correctAnswers.includes(x.textContent)) { //check if the correct answers array contains the current clicked answer
- points++;
- };
- question[currSection].style.display = 'none';
- currSection++;
- currSection !== 3
- ? question[currSection].style.display = 'block'
- : printResult(points);
- }));
- function printResult(points) {
- document.querySelector("#results").style.display = 'block';
- let text = '';
- points === 3
- ? text = 'You are recognized as top JavaScript fan!'
- : text = `You have ${points} right answers`;
- document.querySelector("#results > li > h1").textContent = text;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement