-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
100 lines (90 loc) · 2.86 KB
/
script.js
File metadata and controls
100 lines (90 loc) · 2.86 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
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
93
94
95
96
97
98
99
100
let money = 1000;
let colour = "not_selected";
let display_color;
let lost;
function updateMoneyDisplay() {
document.getElementById("money").textContent = `Money: $${money}`;
}
function updateColourDisplayRed() {
document.getElementById("colour").textContent = `Colour Selected: Red`;
document.getElementById("red-button").style.borderColor = `gray`;
document.getElementById("black-button").style.borderColor = `lightgray`;
}
function updateColourDisplayBlack() {
document.getElementById("colour").textContent = `Colour Selected: Black`;
document.getElementById("black-button").style.borderColor = `gray`;
document.getElementById("red-button").style.borderColor = `lightgray`;
}
function addMoney(amount) {
money += parseInt(amount);
updateMoneyDisplay();
}
function subtractMoney(amount) {
if (money >= amount) {
money -= amount;
updateMoneyDisplay();
return true;
}
return false;
}
function red() {
updateColourDisplayRed();
colour = "red";
lost = "black";
}
function black() {
updateColourDisplayBlack();
colour = "black";
lost = "red";
}
function spin() {
document.getElementById("result").innerHTML = "";
amount = document.getElementById("bet-amount");
if (amount.value == "") {
alert("Enter Bet Below To Spin!");
} else if (money == 0) {
alert("You Lost, Plese Refresh To Start Playing Again.");
} else if (money < amount.value) {
alert("You Cannot Bet More Than Your Money!");
} else if (colour == "not_selected") {
alert("Please Select A Color To Bet On!");
} else {
document.getElementById("spin-button").setAttribute("disabled", "true");
let number = Math.floor(Math.random() * (10 - 1 + 1)) + 1;
let remainder = number % 2;
if (remainder == 0) {
display_color = colour;
wheel();
const myTimeout1 = setTimeout(() => {
document.getElementById("result").innerHTML =
"YOU WON $" + amount.value;
addMoney(amount.value);
document.getElementById("result").style.animation =
"winColorChange 1s infinite";
document.getElementById("spin-button").removeAttribute("disabled");
}, 2000);
} else {
display_color = lost;
wheel();
const myTimeout2 = setTimeout(() => {
document.getElementById("result").innerHTML =
"YOU Lost $" + amount.value;
subtractMoney(amount.value);
document.getElementById("result").style.animation =
"colorChange 1s infinite";
document.getElementById("spin-button").removeAttribute("disabled");
}, 2000);
}
}
}
function wheel() {
console.log(display_color);
const wheel = document.getElementById("spin-circle");
wheel.style.animation = "none";
void wheel.offsetWidth;
if (display_color === "red") {
wheel.style.animation = "spin_red 2s ease forwards";
} else {
wheel.style.animation = "spin_black 2s ease forwards";
}
}