-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadamsAnimals.js
40 lines (31 loc) · 1.27 KB
/
adamsAnimals.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
if (Meteor.isClient) {
var previousNr; // used in 'click' function to prevent the same picture showing again
Template.hello.helpers({
counter: function () {}
});
Template.hello.events({
'click': function () {
var myPix = new Array("bear", "bee", "cat", "cow", "dog", "duck",
"elephant", "fox", "goat", "hippo", "lion",
"monkey", "mosquito", "mouse", "owl", "parrot",
"pig", "polar-bear", "rabbit", "squirrel", "tiger");
var randomNr = Math.floor((Math.random() * myPix.length));
while (previousNr == randomNr) {
var randomNr = Math.floor((Math.random() * myPix.length));
}
document.getElementById("myPicture").src = ((myPix[randomNr]) + ".jpg");
previousNr = randomNr;
var soundFile = ((myPix[randomNr]) + ".mp3")
// http://goldfirestudios.com/blog/104/howler.js-Modern-Web-Audio-Javascript-Library
// how to add it to meteor: https://atmospherejs.com/ovcharik/howler
var sound = new Howl({
urls: [soundFile]
}).play();
}
});
}
if (Meteor.isServer) {
Meteor.startup(function () {
// code to run on server at startup
});
}