-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrandomEP.js
More file actions
27 lines (21 loc) · 736 Bytes
/
randomEP.js
File metadata and controls
27 lines (21 loc) · 736 Bytes
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
/*global $*/
$("#homeBtn").click(function(){
window.location = "index.html";
});
function getRandomEP(){
var randomNum = Math.floor(Math.random() * 31) + 1;
console.log(randomNum);
var randomEPUrl = "https://rickandmortyapi.com/api/episode/" + randomNum;
$.ajax({
url: randomEPUrl,
method: "GET",
success: function(x){
var ep = "https://rickandmorty.fandom.com/wiki/" + x.name;
console.log(ep);
$("#main").append("<h1>" + x.name + "</h1>", "<h2>" + "Air Date: " + x.air_date + "</h2>", "<h2>" + "Episode: " + x.episode + "</h2>", "<a href=" + ep + ">" + "Episode Info" + "</a>");
}
});
}
$("#displayEP").click(function(){
getRandomEP();
});