1
undefined
以外のコードを書くことはできません。私は何を正しくしていないのですか?私は、どのようにスコア機能が働くか分からない。これまで私はバニラfunction doSomething() {}
メソッドを書いただけです。ありがとうございました。初心者でlocalStorageを稼働させようとしました
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());
'window.localStorage'? – OrangeDog
それは動作しているようですhttps://jsfiddle.net/2t6ngjvw/ – maioman
上記のコードは 'undefined 'を与えません – nikhil