Skip to content
This repository was archived by the owner on Apr 18, 2025. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions using-fetch/exercise.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@ Open index.html in your browser. Every time you refresh the page,
a different greeting should be displayed in the box.
*/

fetch("*** Write the API address here ***")
fetch("https://random-word-api.herokuapp.com/word")
.then(function (response) {
return response.text();
return response.json();
})
.then(function (greeting) {
// Write the code to display the greeting text here
});
let greetElement = document.getElementById("greeting-text");
console.log(typeof greeting);
greetElement.innerText = greeting[0];
})
.catch((error) => console.error("Failed", error));