-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
44 lines (40 loc) · 1.14 KB
/
index.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
var birthYear = 1992
var images = [
'sweet1.png',
'sweet2.png',
'sweet3.png',
'sweet4.png',
'sweet6.png',
'sweet7.png',
'sweet8.png',
'sweet9.png',
'sweet10.png',
'sweet11.png'
]
var treatedOnce = false;
$('#box, #gift').click(function() {
if (!treatedOnce) {
$(this).fadeOut(200, function() {
$(this).attr("src", "assets/box-opened.jpg").fadeIn();
$('#gift').attr("src", 'assets/' + images[getRandomInt(images.length - 1)]).fadeIn();
})
treatedOnce = true;
} else {
$('#gift').fadeOut(200, function() {
$(this).attr("src", 'assets/' + images[getRandomInt(images.length - 1)])
$(this).fadeIn();
});
}
})
$('#age').text(new Date().getFullYear() - birthYear)
/**
* Returns a random integer between min (inclusive) and max (inclusive).
* The value is no lower than min (or the next integer greater than min
* if min isn't an integer) and no greater than max (or the next integer
* lower than max if max isn't an integer).
* Using Math.round() will give you a non-uniform distribution!
*/
function getRandomInt(max) {
max = Math.floor(max);
return Math.floor(Math.random() * (max + 1));
}