I have this problem that only exists on first page load in Chrome on desktop. It works in Chrome on the second or more page loads. It also works on mobile in Chrome on every page load.
It works fine in Safari and Firefox, MOST OF THE TIME. I have experienced the below error there as well, only on first page load, only on desktop, but I am not able to reproduce it there for about an entire day now.
Does anyone know what is going on?
The only thing I have been able to come up with is that somehow my redirect function is triggered. Because as you can see in the flow indicated below at number 6, after the error, the page redirects back to index.html. However that function would only trigger if the value of one of my sessionStorage values is null and I can see in the browser console that those values are set correctly when I press the button to go to the next page.
The error:
The flow:
The line generating the error is where I use the loadQuiz function to set the question element's value in my html to the 'english' property value of the first object in the filtered array.
The code (js):
function redirect() {
if (selectedBook !== null) {
// do nothing
} else {
window.location = "<myURL>"
};
};
redirect();
function loadQuiz() {
const currentQuizData = quizArr[currentQuiz]; // currentQuiz is the question counter. It starts at 0 to get the first object, then increments by 1 after each question
questionEl.innerText = currentQuizData.english;
// line above is where the error is generated
counter.innerText = (currentQuiz + 1) + "/" + quizArr.length;
};
loadQuiz();