-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathend.js
40 lines (29 loc) · 1.06 KB
/
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
30
31
32
33
34
35
36
37
38
39
40
const usernames = JSON.parse(localStorage.getItem('usernames'))
const finalScore = document.querySelector ('#finalScore')
const user = document.querySelector('#user')
const mostRecentScore = localStorage.getItem('mostRecentScore')
const endtext = document.querySelector ('#end-text')
const highScores = JSON.parse(localStorage.getItem('highScores')) || []
console.log(highScores)
const MAX_HIGH_SCORES = 3
finalScore.innerText = mostRecentScore
user.innerText = usernames
saveHighScores = e => {
e.preventDefault()
const score = {
score: mostRecentScore,
username: usernames
}
console.log(score)
highScores.push(score)
highScores.sort((a, b) =>{
return b.score - a.score
})
highScores.splice (3)
localStorage.setItem('highScores', JSON.stringify(highScores));
}
document.addEventListener('DOMContentLoaded', ()=>{
document.getElementById('saveScoreBtn').addEventListener('click', saveHighScores);})
$(document).ready(function(e) {
$("#saveScoreBtn").click(function(e) {
$("#saveScoreBtn").css("display","none")})});