-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathend.js
29 lines (23 loc) · 813 Bytes
/
end.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
const username= document.getElementById('username');
const saveScoreButton = document.getElementById('saveScoreButton');
const finalScore= document.getElementById('finalScore');
const mostRecentScore = window.localStorage.getItem('mostRecentScore');
finalScore.innerText = mostRecentScore;
const highScore = JSON.parse(localStorage.getItem('highScore')) || [];
username.addEventListener('keyup',()=>{
saveScoreButton.disabled= !(username.value);
})
saveHighScore=(e)=>{
e.preventDefault();
const info= {
score:mostRecentScore,
user: username.value
}
highScore.push(info);
highScore.sort((a,b)=>{
return b.score-a.score;
})
highScore.splice(5);
localStorage.setItem('highScore',JSON.stringify(highScore));
window.location.assign('/');
}