Skip to content

Commit 126870b

Browse files
committed
solve linter error
1 parent 9abe934 commit 126870b

File tree

2 files changed

+58
-52
lines changed

2 files changed

+58
-52
lines changed

Source-Code/JumpGame/script.js

+49-49
Original file line numberDiff line numberDiff line change
@@ -1,66 +1,66 @@
1-
const character = document.getElementById("character");
2-
const block = document.getElementById("block");
3-
const block2 = document.getElementById("block2");
4-
const co = document.getElementById("co");
5-
var counter = 0;
1+
const character = document.getElementById('character');
2+
const block = document.getElementById('block');
3+
const block2 = document.getElementById('block2');
4+
let counter = 0;
65

7-
var je = setInterval(() => {
8-
co.classList.add("animate2");
6+
const jump = () => {
7+
if (character.classList.contains('animate')) return;
8+
character.classList.add('animate');
99
setTimeout(() => {
10-
co.classList.add("show");
11-
}, 2000);
12-
}, 1000);
13-
function jump() {
14-
if (character.classList === "animate") {
15-
return;
16-
}
17-
character.classList.add("animate");
18-
setTimeout(function () {
19-
character.classList.remove("animate");
10+
character.classList.remove('animate');
2011
}, 300);
21-
}
22-
function myFunction(event) {
23-
var x = event.keyCode;
24-
if (x == 32) {
25-
jump();
26-
}
27-
}
28-
var checkDead = setInterval(function () {
29-
let characterTop = parseInt(
30-
window.getComputedStyle(character).getPropertyValue("top")
12+
};
13+
14+
// eslint-disable-next-line no-unused-vars
15+
const checkDead = setInterval(() => {
16+
const characterTop = parseInt(
17+
window.getComputedStyle(character).getPropertyValue('top'),
18+
10,
3119
);
32-
let blockLeft = parseInt(
33-
window.getComputedStyle(block).getPropertyValue("left")
20+
const blockLeft = parseInt(
21+
window.getComputedStyle(block).getPropertyValue('left'),
22+
10,
3423
);
3524
if (blockLeft < 20 && blockLeft > -20 && characterTop >= 130) {
36-
block.style.animation = "none";
37-
alert("Game Over. score: " + Math.floor(counter / 100));
25+
block.style.animation = 'none';
26+
alert(`Game Over. Score: ${Math.floor(counter / 100)}`);
3827
counter = 0;
39-
block.style.animation = "block 1s infinite linear";
40-
} else if (ka()) {
28+
block.style.animation = 'block 1s infinite linear';
4129
} else {
42-
counter++;
43-
document.getElementById("scoreSpan").innerHTML = Math.floor(counter / 100);
30+
counter += 1;
31+
document.getElementById('scoreSpan').innerText = Math.floor(counter / 100);
4432
}
4533
}, 10);
46-
var add = setInterval(() => {
47-
block2.classList.add("animate1");
34+
35+
const add = () => {
36+
block2.classList.add('animate1');
4837
setTimeout(() => {
49-
block2.classList.remove("animate1");
38+
block2.classList.remove('animate1');
5039
}, 9000);
51-
}, 7000);
40+
};
5241

53-
function ka() {
54-
let characterTop = parseInt(
55-
window.getComputedStyle(character).getPropertyValue("top")
42+
// Call the `add` function at regular intervals to animate block2
43+
setInterval(add, 7000);
44+
45+
// eslint-disable-next-line no-unused-vars
46+
const ka = () => {
47+
const characterTop = parseInt(
48+
window.getComputedStyle(character).getPropertyValue('top'),
49+
10,
5650
);
57-
let blockTop = parseInt(
58-
window.getComputedStyle(block2).getPropertyValue("left")
51+
const blockTop = parseInt(
52+
window.getComputedStyle(block2).getPropertyValue('left'),
53+
10,
5954
);
60-
if (blockTop < 20 && characterTop == 100) {
61-
block2.classList.remove("animate1");
62-
alert("Game Over. score: " + Math.floor(counter / 100));
55+
if (blockTop < 20 && characterTop === 100) {
56+
block2.classList.remove('animate1');
57+
alert(`Game Over. Score: ${Math.floor(counter / 100)}`);
6358
counter = 0;
6459
}
65-
}
66-
window.addEventListener("keydown", myFunction);
60+
};
61+
62+
window.addEventListener('keydown', (event) => {
63+
if (event.keyCode === 32) {
64+
jump();
65+
}
66+
});

Source-Code/JumpGame/style.css

+9-3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ h2 {
2626
p {
2727
color: white;
2828
font-size: 20px;
29+
text-align: center;
2930
}
3031

3132
#character {
@@ -45,12 +46,15 @@ p {
4546
0% {
4647
top: 150px;
4748
}
49+
4850
30% {
4951
top: 100px;
5052
}
53+
5154
70% {
5255
top: 100px;
5356
}
57+
5458
100% {
5559
top: 150px;
5660
}
@@ -83,6 +87,7 @@ p {
8387
0% {
8488
left: 500px;
8589
}
90+
8691
100% {
8792
left: -20px;
8893
}
@@ -92,20 +97,21 @@ p {
9297
0% {
9398
left: 500px;
9499
}
100+
95101
100% {
96102
left: -20px;
97103
}
98104
}
99-
p {
100-
text-align: center;
101-
}
105+
102106
#co {
103107
margin-bottom: 10px;
104108
font-weight: bold;
105109
}
110+
106111
.animate2 {
107112
animation: pa 1s ease-in-out;
108113
}
114+
109115
.show {
110116
opacity: 0;
111117
}

0 commit comments

Comments
 (0)