const correctAnswers = ['B', 'B', 'B', 'B'];
const form = document.querySelector(".quiz-form")
const result = document.querySelector(".result")

form.addEventListener("submit", (e) => {
    e.preventDefault();

    let score = 0;
    const userAnswers = [form.q1.value, form.q2.value, form.q3.value, form.q4.value];

    // check answers
    userAnswers.forEach((answer, index) => { // Überprüfung die richtige Antworten
        if (answer === correctAnswers[index]) {
            score += (100 / correctAnswers.length) // Berechnet das Resultat
        }
    })
    // console.log(score)
    scrollTo(0, 0)
    //show result on page
    result.classList.remove("d-none")

    let output = 0;
    const timer = setInterval(() => { // Animation des Resultats
        result.querySelector("span").textContent = `${output}%`;
        if (output === score) {
            clearInterval(timer);
        } else {
            output++;
        }
    }, 10);
})

// console.log(document.querySelector("form"))

// setTimeout(() => {
//     console.log("hello")
// }, 3000)

// let i = 0

// let timer = setInterval(() => {
//     console.log("hello")
//     i++;
//     if (i === 5) {
//         clearInterval(timer)
//     }
// }, 2000);
