-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
48 lines (43 loc) · 1.07 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
var no = random(6);
var correct = 'rgb(' + random(255) + ',' + random(255) + ',' + random(255) + ')';
colors();
$('#lookfor').html(correct);
$('#new-game, #wrong').hide();
function newgame() {
no = random(6);
correct = 'rgb(' + random(255) + ',' + random(255) + ',' + random(255) + ')';
colors();
$('#lookfor').html(correct);
$('.color').css('opacity', '1');
$('#new-game').slideDown();
setTimeout(() => { $('#new-game').slideUp() }, 2000);
}
function colors() {
setcolor(1);
setcolor(2);
setcolor(3);
setcolor(4);
setcolor(5);
setcolor(6);
}
function setcolor(element) {
var thing = '#color-' + element
if (no != element) {
var color = 'rgb(' + random(255) + ',' + random(255) + ',' + random(255) + ')';
$(thing).css('background-color', color);
} else {
$(thing).css('background-color', correct);
};
}
function random(up_to) {
return Math.floor((Math.random() * up_to) + 1);
}
function checkoutput(number) {
if (number == no) {
console.log('Correct!');
newgame();
} else {
$('output').html('Incorrect!')
$('#color-'+ number).css('opacity', '0');
}
};