As the title may give away I am trying to increment a score value across page refreshes. I'm not entirely sure if what I have is set up right so there's a bit commented out. Not looking for straight answers, just some pointers and advice to get to where I need to be.
var score = 0;
//localStorage.setItem("score", score);
var rounds;
var ans;
var img;
img = document.getElementsByClassName("image")[0].id;
$(".answer").click(function() {
ans = $(this).attr('id');
if (ans === img) {
//score++;
//score = localStorage.getItem("score", score);
score++;
//localStorage.setItem("score", score);
//rounds++;
alert('right answer');
location.reload();
} else {
//score = 0;
//rounds++;
alert('wrong answer');
//location.reload();
}
});
//var res = localStorage.getItem("score", score)
//console.log(res);
Only been playing around with query for a couple of days so still feeling about blindly. Any help would be great. Rest of the script can be found here jfiddle