<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<select id="section">
<option value="home">Home</option>
<option value="arts">Art</option>
</select>
<button id="refresh">Refresh</button>
<script>
function callAPI() {
let output = ''
fetch(`http://api.nytimes.com/svc/topstories/v2/${section.value}.json?api-key=ue5gpNuOXmVwacpftV5uEmjyTFwYmM4i`)
.then(res => res.json())
.then(data => {
console.log(data)
})
}
const section = document.querySelector('#section')
const refreshBtn = document.querySelector('#refresh')
section.addEventListener('change', () => {
callAPI()
})
refreshBtn.addEventListener('click', () => {
alert('I')
callAPI()
})
callAPI()
</script>
</body>
</html>
This is the code that I already wrote! But I want to display information on web page not in console.log! How can I do that? Could anyone help me? I appreciate any help!