-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscript.js
81 lines (68 loc) · 2.36 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
$(document).ready(function() {
var songIds = ["995535015", "966411602", "823593456", "956689796", "943946671",
"982388023", "907242704", "201281527", "656801339", "910038357",
"250038575", "878000348", "794095205", "1645339", "400835962",
"325618", "169003415", "51958108",
"76532142", "192688540", "684811768", "344799464", "217633921",
"192811017", "640047583", "517438248" ];
var data;
var audioElement = $('#audio_preview');
var count =0;
//Some note
//Functions
$("form").on("submit", function(e){
e.preventDefault();
var songChoice = $("#songSelect").val();
$("#songSelect").val("");
if (songChoice === data.results[0].artistName){
$("h2").text("Correct.");
console.log("Correct.");
count++;
$(".scoreUp").text(count);
console.log(count);
} else{
console.log("You lose");
$("h2").text("Incorrect.");
}
});
function startSong(){
audioElement.attr('src', data.results[0].previewUrl);
audioElement.on("canplay", function() {
if (this.paused === false){
this.pause();
}else{
audioElement[0].play();
$("#songSelect").focus();
console.log(data);
}});
// submitSong();
}
function grabSong(){
$.ajax({
url: "https://itunes.apple.com/us/lookup?id="+ _.sample(songIds),
dataType: 'JSONP'
}).done(function(response){
data = response;
audioElement.attr('src', data.results[0].previewUrl);
audioElement.on("canplay", function(){
audioElement[0].play();
$("#songSelect").val("");
$("#songSelect").focus();
console.log(data);
// submitSong();
});
$("h2").text("");
});
}
$.ajax({
url: "https://itunes.apple.com/us/lookup?id="+ _.sample(songIds),
dataType: 'JSONP'
})
.done(function(response) {
data = response;
//Play track
$(".play").on("click", startSong);
$("#next-bt").on("click", grabSong);
})
.fail(function(data) { console.log(data);});
});