I can't get the following code to say anything other than undefined
. What am I not doing right? I'm not sure how the score function works, either. So far I've only written vanilla function doSomething() {}
methods. Thank you.
var score = score || {};
score = {
saveHighScore: function(tally) {
var high_score = localStorage.high_score;
if (typeof high_score == 'number') {
if (tally > high_score) {
localStorage.high_score = tally;
}
} else {
localStorage.high_score = tally;
}
},
getHighScore: function() {
var high_score = localStorage.high_score;
if(typeof high_score !== 'number') {
high_score = 0;
localStorage.high_score = high_score;
}
return high_score;
}
}
window.console.log("Score: ", score.getHighScore());