I have this global variable in my javascript code:
var currentcount=0;
Later on I try to update currentcount, and it is enclosed in the following manner:
function next(){
...
if(userAnswer === myQuestions[overallcount].correctAnswer){
...
var tempcount = currentcount;
for(tempcount in myQuestions.length-1){
if(currentdiff<myQuestions[tempcount].difficulty)
currentcount=tempcount;
}
...
}
When I output currentcount, it is still 0.
I am simply having trouble understanding what the scope of currentcount is, and why it is not updating in the way I want it to. tempcount does update to whatever currentcount is, but currentcount never updates.
If I do something like:
function next(){
...
if(userAnswer === myQuestions[overallcount].correctAnswer){
...
var tempcount = currentcount;
currentcount++;
...
}
}
currentcount does update, but again, it's not the way I want it to.
Please provide an explanation as to why it is so and if there is a solution to update currentcount in the manner I want it to.
Thank you in advance.