-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
34 lines (29 loc) · 1.05 KB
/
script.js
File metadata and controls
34 lines (29 loc) · 1.05 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
//the user will enter a character name. Get the character name, photo, and mor einfo about the character
document.querySelector('button').addEventListener('click', getMoreInfo)
function getMoreInfo(){
const url = 'https://swapi.dev/api/people/1/'
fetch(url)
.then(res => res.json()) //parse response as JSON
.then(data => {
console.log(data)
document.querySelector('h1').innerText = data.name
document.querySelector('h2').innerText = "Height: " + data.height
})
.catch(err => {
console.log(`error ${err}`)
});
}
document.querySelector('button').addEventListener('click', getMovies)
function getMovies(){
const url = 'https://swapi.dev/api/films/1'
fetch(url)
.then(res => res.json()) //parse response as JSON
.then(data => {
console.log(data)
document.querySelector('h3').innerText = data.title
document.querySelector('p').innerText = data.opening_crawl
})
.catch(err => {
console.log(`error ${err}`)
});
}