I'm trying to make a website that fetches a random 10 lines from a poem and then outputs them in the HTML file but instead of getting the .json data I'm getting [object Promise]. Can someone help me out?
Here's my code:
JS:
let url = 'https://poetrydb.org/random,linecount/1;10/title,author,lines.json'
const button = document.getElementById('button')
const body = document.getElementById('poem')
async function requestPoem(url) {
await fetch(url)
.then((response)=>{
let data = response.json()
return data
})
}
button.onclick = ()=>{
body.innerHTML = requestPoem(url)
}
HTML:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script defer src="scripts/main.js"></script>
<title>poem request</title>
</head>
<body>
<p id="poem"></p>
<button id="button">request poem</button>
</body>
</html>