I have setup a fetch request that request a random phrase from an API. This is called when the window reloads or load initially. I created a button that when clicked would re-run the fetch I have setup. Currently it is not working and I am getting this error:
Uncaught (in promise) TypeError: 'fetch' called on an object that does not implement interface Window.
Javascript Code
var generateBtn = document.getElementById('generateSP');
generateBtn.addEventListener('click', fetch);
fetch('https://random-words-api.herokuapp.com/w?n=10')
.then(
function(response) {
if (response.status !== 200) {
console.log('Looks like there was a problem. Status Code: ' +
response.status);
return;
}
response.json().then(function(data) {
console.log(data);
document.getElementById('w3review').value = data;
});
}
)
.catch(function(err) {
console.log('Fetch Error :-S', err);
});