-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
89 lines (77 loc) · 2.7 KB
/
script.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
var r = document.getElementById('rock'),
p = document.getElementById('paper'),
s = document.getElementById('scissors'),
u = document.getElementById('u'),
b = document.getElementById('bot');
var rps = ["rock", "paper", "scissors"]
var emoji = { rock: '✊️', paper: '🖐️', scissors: '✌️' }
r.addEventListener('click', function() {
const random = rps[Math.floor(Math.random() * rps.length)]
check('rock', random)
})
p.addEventListener('click', function() {
const random = rps[Math.floor(Math.random() * rps.length)]
check('paper', random)
})
s.addEventListener('click', function() {
const random = rps[Math.floor(Math.random() * rps.length)]
check('scissors', random)
})
function check(u, b) {
if(u == "rock" && b == "rock") {
index('Tie!', u, b, 'is-warning')
score(false, false)
} else if(u == "rock" && b == "paper") {
index('You Lose!', u, b, 'is-danger')
score(false, true)
} else if(u == "rock" && b == "scissors") {
index('You Win!', u, b, 'is-primary')
score(true, false)
} else if(u == "paper" && b == "paper") {
index('Tie!', u, b, 'is-warning')
score(false, false)
} else if(u == "paper" && b == "scissors") {
index('You Lose!', u, b, 'is-danger')
score(false, true)
} else if(u == "paper" && b == "rock") {
index('You Win!', u, b, 'is-primary')
score(true, false)
} else if(u == "scissors" && b == "scissors") {
index('Tie!', u, b, 'is-warning')
score(false, false)
} else if(u == "scissors" && b == "rock") {
index('You Lose!', u, b, 'is-danger')
score(false, true)
} else if(u == "scissors" && b == "paper") {
index('You Win!', u, b, 'is-primary')
score(true, false)
}
}
function index(n, u, b, s) {
document.getElementById("notif").innerHTML = `<div class="notification ${s} is-light" id="notif">
<button class="delete" id="deleteButton"></button>
You choose: <span id="u">${u + " " + emoji[u]}</span>
<br />
Bot choose: <span id="bot">${b + " " + emoji[b]}</span>
<br />
<p class="has-text-centered">
<span id="state" class="has-text-weight-bold">${n}</span>
</p>
</div>`
document.getElementById('deleteButton').addEventListener('click', function() {
document.getElementById('notif').innerHTML = ""
//document.getElementById("b").removeChild(document.getElementById('notif'))
//document.getElementById("b").appendChild(document.createElement('div')).id = "notif"
})
}
function score(u, b) {
var user = document.getElementById('user-score'),
bot = document.getElementById('bot-score');
if(u) {
var s = Number(user.textContent) + 1;
user.innerHTML = s
} else if(b) {
var s = Number(bot.textContent) + 1;
bot.innerHTML = s
}
}