-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
92 lines (88 loc) · 2.45 KB
/
index.html
File metadata and controls
92 lines (88 loc) · 2.45 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
86
87
88
89
90
91
92
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="author" content="Uditanshu saxena" />
<meta name="theme-color" content="#faebd7" />
<title>NASA APOD API</title>
<style>
body {
margin: 0px;
padding: 0px;
font-family: monospace;
background-color: antiquewhite;
padding-bottom: 10px;
}
#bg {
height: 100%;
width: 100%;
}
.title {
text-align: center;
}
#title {
text-align: center;
font-weight: 700;
font-size: large;
color: gray;
}
#date {
font-weight: 500;
color: brown;
}
#exp {
font-weight: 500;
font-size: 16px;
}
#ale{
font-size: 18px;
padding: 5px 15px 0px 15px;
margin: 2px;
}
#title,
#date,
#exp{
margin: 2px;
padding: 5px 15px 5px 15px;
}
button, a{
border : 0px;
background-color:burlywood;
color:white;
padding:10px 12px 10px 12px;
text-decoration: none;
}
</style>
</head>
<body>
<main>
<h1 class="title">ASTRONOMY PICTURE OF THE DAY</h1>
<img src="" id="bg"></img>
<br />
<p id="title"></p>
<p id="date"></p>
<h4 id="ale">A little explanation -</h4>
<p id="exp"></p>
<center><button><a id="dwnld" href="#">Download HD Image</a></button></center>
</main>
<script>
// fetch the data from nasa apod api (read about await & fetch from MDN docs)
async function getImg() {
base_url =
"https://api.nasa.gov/planetary/apod?api_key=<put your api key here>";
const response = await fetch(base_url);
const data = await response.json(); //convert response into json
console.log(data); //log the data
// diplay data on frontend
document.getElementById("date").textContent = "Date: " + data.date;
document.getElementById("exp").textContent = data.explanation;
document.getElementById("title").textContent = data.title;
document.getElementById('bg').src = data.url;
document.getElementById('dwnld').href = data.hdurl;
}
// function call
getImg();
</script>
</body>
</html>