-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
50 lines (35 loc) · 1.36 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
45
46
47
48
49
50
const search= document.querySelector("#search");
search.addEventListener("click", function (e) {
e.preventDefault()
let chave= "YJvYvzX3E1xCUh6DBNpmOdWc2I0hFjc350Er7VuX";
let inputVal= $("#input").val();
$.ajax ({
url: `https://api.nasa.gov/planetary/apod?api_key=${chave}&date=${inputVal}`,
type: "GET",
contentType: "application/json",
success: function(data) {
console.log(data)
console.log(data.copyright)
let explanation= data.explanation
let titulo= data.title
let copyR= data.copyright
if (data.media_type== "video") {
$("#title").text(`${titulo}`);
$("#texto").text(`${explanation}`);
$("#container2").css("display", "flex")
$("#video").css("display", "flex");
$("#img").css("display", "none");
$("#video").attr("src", data.url);
$("#textCopy").text(`${copyR}`);
} else {
$("#title").text(`${titulo}`);
$("#texto").text(`${explanation}`);
$("#container2").css("display", "flex")
$("#img").css("display", "flex");
$("#video").css("display", "none");
$("#img").attr("src", data.url);
$("#textCopy").text(`${copyR}`);
}
}
})
})