Reputation: 11
So, I wrote a quiz on JavaScript. It works perfectly on computes, but on touchscreen it does not start.
I changed
start.addEventListener('click', startQuiz);
to
start.addEventListener('touchstart', startQuiz);
But is still does not start. Should I add something else?
start.addEventListener('touchstart', startQuiz);
start.addEventListener('touchstart', startQuiz);
function startQuiz(){
start.style.display = "none";
startText.style.display = "none";
renderQuestion();
quiz.style.display = "block";
renderProgress();
renderCounter();
TIMER = setInterval(renderCounter,1000); // 1000ms = 1s
}
Upvotes: 1
Views: 93
Reputation: 11
So, turns out the code was correct. The chrome browser that I was using was extremely outdated. On latest version quiz works perfectly! :)
Upvotes: 0
Reputation: 4905
I tried your coding it is working fine
let start =document.getElementById("start");
let quiz =document.getElementById("quiz");
start.addEventListener('touchstart', startQuiz);
function startQuiz(){
alert('Working')
start.style.display = "none";
startText.style.display = "none";
renderQuestion();
quiz.style.display = "block";
renderProgress();
renderCounter();
TIMER = setInterval(renderCounter,1000);
}
<div id='start'>start</div>
<div id='quiz'>34343</div>
Upvotes: 0
Reputation: 17
start.addEventListener('click touch', startQuiz);
This will bind both click and touch.
Upvotes: 0