I can't assign the link of image that I got with API to src of image. I'm using fetch to get info, (I'm new with APIs).
fetch("https://restcountries.com/v3.1/all")
.then(respons => respons.json())
.then(b => {
let pic = b[0].flags.png;
document.getElementById("img").src = "pic";
})
<img src="" alt="" id="img">
There’s a problem with your code. You created the variable named pic. But instead of assigning variable to src you are assigning "pic"
string. The correct code is:
fetch("https://restcountries.com/v3.1/all")
.then(respons => respons.json())
.then(b => {
let pic = b[0].flags.png;
document.getElementById("img").src = pic;
})
Note that I removed quotes from pic
variable.