-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
31 lines (22 loc) · 848 Bytes
/
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
var nasaImages = $("#nasa-images");
var input = $("#datepicker").datepicker({ dateFormat: 'yy-mm-dd' });
$("form button").click(function (e) {
e.preventDefault();
var date = input.val();
if( date === "") {
alert("Please fill the field");
return;
}
let url = "https://api.nasa.gov/mars-photos/api/v1/rovers/curiosity/photos?earth_date=" + date + "&api_key=NBlCLhD21Eud5RxMy1TjZoeJedDa1c1qbsnLMIG2";
$.get(url, function (data) {
let photos = data.photos;
if(photos.length === 0 ) {
alert("No photos available for this date");
return;
}
$("#nasa-images img").remove();
for (let photo of photos) {
nasaImages.append('<img src="' + photo.img_src + '" alt="' + photo.id + '">');
}
});
});