0

I am learning how to make links work with JS and after trying a few different things I managed to make it work but I geta n error on the console and I'd like to understand why.

const card = document.getElementById("card2");
const flipButton = (document.querySelector(".side-two").onclick =
  function flip() {
    if (card.className == "card2_back") card.className = "card2_front";
    else card.className = "card2_back";
  });

const goToQuiz = (document.querySelector(".start-quiz").onclick =
  function goToQuiz() {
    location.href = "./quiz.html";
  });

const goToQuiz2 = (document.querySelector(".tutorial-start-quiz").onclick =
  function goToQuiz() {
    location.href = "./quiz.html";
  });

This works but I get an error on the target page's console

app.js:4 Uncaught TypeError: Cannot set properties of null (setting `enter code here`'onclick')
    at app.js:4:65

I have tried different things like

goToQuiz.addEventListener("click", (e) => {
  onclick = goToQuiz() {
    location.href = "./quiz.html";
  };
});

goToQuiz2.addEventListener("click", (e) => {
  onclick = function () {
    location.href = "./quiz.html";
  };
});

I'd appreciate the help!

Rigoz13
  • 9
  • 2

0 Answers0