I have attached the before code and the after code. The code is if the answer is correct a pop up div appears for a second saying correct, if the answer is wrong a pop up div appears for a second saying wrong.
I decided to improve the code by using functions to hide and show divs and use the variable id to pass the div id, and call it when i need to hide or unhide a div, as throughout the reso of the code i am constantly hiding and unhiding divs.
but for some reason teh functions work on all other divs accept in this new code. the score variable increases and the inner html for the score updates just the "wrong" and "correct" divs dont show and then hide after a second.
Before,
function hideCorrectBox(){
document.getElementById("correct").style.display='none';
}
function hideWrongBox(){
document.getElementById("wrong").style.display='none';
}
document.getElementById("box1").onclick=function(){
if(areWePlaying==true){
if(document.getElementById("box1").innerHTML==answer){
document.getElementById("correct").style.display='initial';
setTimeout(hideCorrectBox,1000);
score= score+1;
document.getElementById("scoreValue").innerHTML= score;
newQuestion();
}
else {document.getElementById("wrong").style.display='initial';
setTimeout(hideWrongBox,1000);}
}}
After,
function show(Id){
document.getElementById(Id).style.display="initial";
}
function hide(Id){
document.getElementById(Id).style.display="none";
}
document.getElementById("box1").onclick=function(){
if(areWePlaying==true){
if(document.getElementById("box1").innerHTML==answer){
show("correct");
setTimeout(hide("correct"),1000);
score= score+1;
document.getElementById("scoreValue").innerHTML= score;
newQuestion();
}
else {show("wrong");
setTimeout(hide("wrong"),1000);}
}}