Skip to content

Commit 4b634de

Browse files
added score
1 parent 21a9b8d commit 4b634de

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

index.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111

1212
<div class="main">
1313
<h1>Simon Says</h1>
14-
<h2 id="level">Ready when you are.</h2>
14+
<h2 id="level">Press any key to start</h2>
15+
<h3 id="score">Score: 0</h3>
1516

1617
<div class="container">
1718
<div class="btn red" id="red"></div>

script.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ let level = 0;
66
let started = false;
77

88
let h2 = document.querySelector("#level");
9+
let scoreDisplay = document.querySelector("#score");
910

1011
document.addEventListener("keypress", function () {
1112
if (!started) {
@@ -19,6 +20,9 @@ function nextlevel() {
1920
level++;
2021

2122
h2.innerText = "Level " + level;
23+
score = level - 1;
24+
scoreDisplay.innerText = "Score: " + score;
25+
2226

2327
let randColor = colors[Math.floor(Math.random() * 4)];
2428
gameSeq.push(randColor);
@@ -55,6 +59,8 @@ function checkAnswer(index) {
5559
}
5660
} else {
5761
h2.innerText = "Game Over! Press any key to restart";
62+
scoreDisplay.innerText = "Score: " + score;
63+
5864
document.body.style.backgroundColor = "red";
5965

6066
setTimeout(() => {

0 commit comments

Comments
 (0)