I'm testing the fetch example from mozilla (https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API).
My "fetchtest" function should return the google.com source code... but it isn't working.
Can you help me please?
console.log(fetchtest('http://google.com'));
function fetchtest(url) {
fetch(url).then(function(response) {
if(response.ok) {
response.text().then(function(text) {
//console.log(text); // is working
return text; // isn't working
});
} else {
return 'Network response was not ok.';
}
}).catch(function(error) {
return 'There has been a problem with your fetch operation: ' + error.message;
});
}