xxxxxxxxxx
1
const DOG_URL = "https://dog.ceo/api/breeds/image/random";
2
•
3
const doggos = document.getElementById("dog-target3");
4
•
5
async function addNewDoggo() {
6
const promise = await fetch(DOG_URL);
7
const processedResponse = await promise.json();
8
const img = document.createElement("img");
9
img.src = processedResponse.message;
10
img.alt = "Cute doggo";
11
doggos.appendChild(img);
12
}
13
•
14
document.getElementById("dog-btn3").addEventListener("click", addNewDoggo);
1
undefined
xxxxxxxxxx
async function handleFetchAwait(id) {
let response = await fetch(`https://samplesite.com/users_id/${id}`);
let data = await response.json()
return data;
}
handleFetchAwait(21)
.then(data => console.log(data));
xxxxxxxxxx
async function fetchMovies404() {
const response = await fetch('/oops');
response.ok; // => false
response.status; // => 404
const text = await response.text();
return text;
}
fetchMovies404().then(text => {
text; // => 'Page not found'
});
xxxxxxxxxx
async function fetchMovies404() {
const response = await fetch('/oops');
response.ok; // => false
response.status; // => 404
const text = await response.text();
return text;
}
fetchMovies404().then(text => {
text; // => 'Page not found'
});