-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
85 lines (54 loc) · 2.26 KB
/
script.js
File metadata and controls
85 lines (54 loc) · 2.26 KB
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
82
83
84
85
/*global $*/
console.log("hi");
function characterChose(){
var characterSearch = $("#searchInput").val();
var url = "https://rickandmortyapi.com/api/character/?name=" + characterSearch ;
$.ajax({
url: url,
method: "GET",
success: function(response){
if(characterSearch && response.results[0].species === "Human"){
$("#categoryOne").append("<img src=" + response.results[0].image + ">", "<h1>" + response.results[0].name + "</h1>");
}
else if(characterSearch && response.results[0].species === "unknown"){
$("#categoryThree").append("<img src=" + response.results[0].image + ">", "<h1>" + response.results[0].name + "</h1>");
}
else if(characterSearch){
$("#categoryTwo").append("<img src=" + response.results[0].image + ">", "<h1>" + response.results[0].name + "</h1>" + "Species:" + "<p>" + response.results[0].species + "</p>");
}
else{
}
}
});
}
function randomCharacter(){
var randomNum = Math.floor(Math.random() * 493) + 1;
var url ="https://rickandmortyapi.com/api/character/" + randomNum;
$.ajax({
url: url,
method: "GET",
success: function(y){
if(y.id === randomNum && y.species === "Human"){
$("#categoryOne").append("<img src=" + y.image + ">" + "<h1>" + y.name + "</h1>");
}
else if(y.id === randomNum && y.species === "Alien"){
$("#categoryThree").append("<img src=" + y.image + ">" + "<h1>" + y.name + "</h1>");
}
else if(y.id === randomNum && y.species !== "Alien"){
$("#categoryTwo").append("<img src=" + y.image + ">" + "<h1>" + y.name + "</h1>" + "Species " + "<p>" + y.species + "</p>");
}
}
});
}
$("#searchButton").click(function(){
characterChose();
});
$("#randomCharac").click(function(){
randomCharacter();
});
$("#locations").click(function(){
window.location = "location-page.html";
});
$("#info").click(function(){
window.location = "randomEP.html";
});