function fetchData(){
let req = fetch("https://ghibliapi.herokuapp.com/people");
setTimeout(function(){
if(req.ok){
return req;
}
else{
return req.statusText;
}
},5000);
}
fetchData().then(function(response){
return response.json();
}).then(function(data){
console.log(data)
}).catch(function(error){
console.log("Error", error)
})
setTimeout(function(){
console.log("Stop")
},6000);
Why does the if-else statement not work in this scenario? It only works when I place the return statement after the else block. Can someone please explain?
Thank you!