-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
92 lines (64 loc) · 2 KB
/
app.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
const reel1 = document.getElementById('reel1')
const reel2 = document.getElementById('reel2')
const reel3 = document.getElementById('reel3')
spinBtn = document.getElementById('spin')
resetBtn = document.getElementById('reset')
messageEl = document.getElementById('message')
let symbols = ['🍎', '🍋', '🍒', '💎', '🍊', '🔔', '🍀', '🍇']
let bankRoll = 101
let credit = 1
let stop
spinBtn.addEventListener('click', handleClick)
resetBtn.addEventListener('click', render)
function randomSymbol() {
return symbols[Math.floor(Math.random() * symbols.length)]
}
function spin() {
slots = []
reel1.style.background = 'white'
reel2.style.background = 'white'
reel3.style.background = 'white'
for (let i = 0; i < 3; i++) {
slots.push(randomSymbol())
}
winCombo()
messageEl.textContent = `$ ${bankRoll}`
console.log(slots)
}
function winCombo() {
reel1.textContent = slots[0]
reel2.textContent = slots[1]
reel3.textContent = slots[2]
console.log(bankRoll)
if (slots[0] === slots[1] && slots[0] !== slots[2]) {
reel1.style.background = 'gold'
reel2.style.background = 'gold'
return bankRoll = bankRoll - credit + (credit + 4)
} else if (slots[0] === slots[1] && slots[0] === slots[2]) {
reel1.style.background = 'gold'
reel2.style.background = 'gold'
return bankRoll = bankRoll - credit + (credit + 12)
} else {
return bankRoll -= 1
}
}
function handleClick() {
if (bankRoll <= 0) {
return spinBtn.addEventListener('click', handleClick).disabled = false
}
spin()
}
function render() {
bankRoll = 100
messageEl.textContent = '$ 100'
}
// let animation = setInterval(function() {
// reel1.textContent = slots[0]
// reel2.textContent = slots[1]
// reel3.textContent = slots[2]
// if(stop === !stop ) {
// clearInterval(animation)
// spin()
// }
// }, 100)
//https://www.codingcreativo.it/en/javascript-slot-machine/