I want to create a line of code, so that if there is no universities/result with the name it search, it runs a code setting an alert
Any idea? I can’t make it work for some reason
I want to create a line of code, so that if there is no universities/result with the name it search, it runs a code setting an alert
Any idea? I can’t make it work for some reason
if( uni.name == undefined ){
alert( ' Alert ' );
}
Debería funcionar, no?
No, I guess it must be the way the API works as it returns an empty array when it doesn’t detect
That value is not equivalent to false? Or you could check the length property, if it returns 0 it is because it is an empty array
What about:
if (array.length === 0) {
alert('Alert');
}
Thank you for this, but it doesn’t work, I feel like the API doesn’t really spit back anything now that I rechecked, it’s weird but it’s how it is funnily enough
if array
is empty the loop doesn’t run, Where are you putting the code for alert?
So there’s a loop I created that creates and attach elements to the div to show the stuff I get from API, so I add a logic that goes
‘If the search get backs nothing, please alert()’
But I can’t really implement it
This is what I get when I search for something that don’t exist within the API
and can you show the code that you have written for that?
Sorry I actually got the code running already, when you talked about the loop I realized, I misplaced the position of the code within the loop, and so when I use Kevin Smith’s code, it’s right, but it’s in the wrong place.
Thank you again for the help
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.