Skip to content

Commit b886488

Browse files
authored
Merge pull request #25 from Nefariusek/feature-issue#14
Feature issue#14
2 parents 7d6b8c3 + 05d9540 commit b886488

File tree

3 files changed

+170
-0
lines changed

3 files changed

+170
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,4 @@ dist-ssr
3838
# Yarn
3939
.yarn
4040
.pnp.*
41+
src/score/user-score.html

src/score/user-score.js

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import './user.score.css';
2+
3+
export function renderScorePage() {
4+
renderPage();
5+
scoreLocalStorage();
6+
saveScoreBtn.addEventListener('click', saveHighScore);
7+
}
8+
9+
function renderPage() {
10+
document.querySelector('#app').innerHTML = `
11+
<div class="container">
12+
<div id="end" class="">
13+
<h1 id="scoreTxt">CONGRATS! YOUR SCORE IS:</h1>
14+
<h1 id="finalScore"></h1>
15+
<form>
16+
<input type="text" id="username" placeholder="NICK" />
17+
<button type="submit" class="btn" id="saveScoreBtn" disabled>
18+
SUBMIT
19+
</button>
20+
</form>
21+
<button class="btn menuBtn" href="/">
22+
MENU
23+
</button>
24+
<button class="btn playAgain" href="/">
25+
PLAY AGAIN
26+
</button>
27+
</div>
28+
</div>
29+
`;
30+
}
31+
32+
function scoreLocalStorage() {
33+
const username = document.getElementById('username');
34+
const saveScoreBtn = document.getElementById('saveScoreBtn');
35+
36+
username.addEventListener('keyup', () => {
37+
saveScoreBtn.disabled = !username.value;
38+
});
39+
}
40+
41+
const highScores = JSON.parse(localStorage.getItem('highScores')) || [];
42+
const recentUserScore = '12';
43+
44+
function saveHighScore(e) {
45+
e.preventDefault();
46+
const finalScore = document.getElementById('finalScore');
47+
finalScore.innerText = recentUserScore;
48+
const score = {
49+
score: recentUserScore,
50+
name: username.value,
51+
};
52+
53+
highScores.push(score);
54+
localStorage.setItem('highScores', JSON.stringify(highScores));
55+
56+
username.value = null;
57+
}

src/score/user.score.css

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
:root {
2+
background-color: #8ab0ab;
3+
font-size: 62.5%;
4+
}
5+
6+
* {
7+
box-sizing: border-box;
8+
font-family: Arial, Helvetica, sans-serif;
9+
margin: 0;
10+
padding: 0;
11+
color: #333;
12+
}
13+
14+
h1 {
15+
font-size: 5.4rem;
16+
color: whitesmoke;
17+
margin-bottom: 3rem;
18+
}
19+
20+
/* UTILITIES */
21+
22+
.container {
23+
width: 100vw;
24+
height: 100vh;
25+
display: flex;
26+
justify-content: center;
27+
align-items: center;
28+
max-width: 80rem;
29+
margin: 0 auto;
30+
padding: 2rem;
31+
}
32+
33+
.container > * {
34+
width: 100%;
35+
}
36+
37+
#scoreTxt {
38+
display: flex;
39+
justify-content: center;
40+
font-size: 30px;
41+
}
42+
#finalScore {
43+
display: flex;
44+
justify-content: center;
45+
font-size: 30px;
46+
}
47+
48+
/* BUTTONS */
49+
.btn {
50+
font-size: 1.8rem;
51+
font-weight: 700;
52+
padding: 1rem 0;
53+
width: 20rem;
54+
height: 6rem;
55+
border: 1em;
56+
border-radius: 15px;
57+
text-align: center;
58+
margin-bottom: 1rem;
59+
text-decoration: none;
60+
color: white;
61+
background-color: #3e505b;
62+
}
63+
64+
.btn.menuBtn {
65+
width: 25rem;
66+
position: absolute;
67+
bottom: 100px;
68+
left: 100px;
69+
}
70+
71+
.btn.playAgain {
72+
width: 25rem;
73+
position: absolute;
74+
bottom: 100px;
75+
right: 100px;
76+
}
77+
78+
#saveScoreBtn:hover {
79+
background-color: rgba(62, 80, 91, 0.4);
80+
color: #333;
81+
}
82+
83+
#saveScoreBtn:active {
84+
background-color: whitesmoke;
85+
color: #333;
86+
}
87+
88+
/* FORMS */
89+
form {
90+
width: 100%;
91+
display: flex;
92+
flex-direction: row;
93+
justify-content: space-around;
94+
align-items: space-around;
95+
}
96+
97+
input {
98+
margin-bottom: 1rem;
99+
width: 40rem;
100+
height: 6rem;
101+
padding: 1.5rem;
102+
font-size: 1.8rem;
103+
border: none;
104+
border-radius: 15px;
105+
background-color: rgba(62, 80, 91, 0.4);
106+
}
107+
108+
input::placeholder {
109+
color: #333;
110+
text-align: center;
111+
font-weight: 700;
112+
}

0 commit comments

Comments
 (0)