-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
63 lines (58 loc) · 1.49 KB
/
index.js
File metadata and controls
63 lines (58 loc) · 1.49 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/* eslint-disable func-names */
import {
startGame,
difficulty,
numArray,
ifLose
} from './javascript/gameSetup.js';
import { userTurn } from './javascript/gameplay.js';
let pos = 0;
const secretArray = [1, 2, 3, 4, 3, 2, 1];
// export let buttonid;
document.getElementById('start-button').addEventListener('click', () => {
startGame(document.getElementById('start-button'));
});
let buttons = document.querySelectorAll('button.play-button');
for (const button of buttons) {
button.addEventListener('click', () => {
console.log(button.id);
pos = userTurn(numArray, pos, ifLose, button.id, difficulty);
if (pos === -1) {
pos = 0;
while (numArray.length > 0) {
numArray.pop();
}
}
});
}
let interval;
function shakeit(element) {
element.style.display = 'block';
var x = -1;
interval = setInterval(function() {
if (x == -1) {
element.style.marginLeft = '-5px';
} else {
switch (x) {
case 0:
element.style.marginLeft = '-10px';
break;
case 1:
element.style.marginLeft = '0px';
element.style.marginTop = '10px';
break;
case 2:
element.style.marginTop = '-10px';
break;
default:
element.style.marginTop = '0px';
clearInterval(interval);
}
}
x++;
}, 50);
}
shakeit(document.getElementsByClassName('shakeit')[0]);
setInterval(function() {
shakeit(document.getElementsByClassName('shakeit')[0]);
}, 2000);