-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
77 lines (51 loc) · 1.56 KB
/
test.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
const userName = prompt("what is your name?")
if(userName === 'justin'){
alert('oh, your name is justin?? >:)')
} else {
alert(`your name is now ${userName}`)
}
if(userName.toLowerCase() === 'justin'){
const justinImage = document.querySelector("#justin");
justinImage.classList.remove('hidden')
}
const container = document.querySelector('.container');
const colors = ['red', 'green', 'yellow', 'blue']
function makeSquare(color) {
const square = document.createElement('div')
square.classList.add('square')
square.style.backgroundColor = color
square.addEventListener('click', userClick)
container.appendChild(square);
}
colors.forEach(makeSquare)
let userPick;
random.addEventListener('click', randomClicked)
function userClick(ev){
const color = ev.target.style.backgroundColor;
userPick = color;
console.log(color);
alert('you chose ' + color);
}
function randomClicked() {
if(!userPick) {
alert(`pick a color first, ${userName}`);
return;
}
const randomNumber = findRandomNumber()
const computerColor = colors[randomNumber];
let message = `Computer picked ${computerColor}! `;
if(computerColor === userPick) {
message += ` You lose ${userName}!`
} else {
message += ` You survived for now ${userName}!`
}
alert(message);
userPick = null;
}
function findRandomNumber(){
return Math.floor(Math.random() * 4);
}
const buttons = document.querySelectorAll('button');
const button1 = buttons[0];
while (1 > 2){
}