I appreciate this is very basic. Please go easy on me, I am at the beginning of my coding journey!
I am trying to establish whether there is an integer anywhere in a string. If there is, it should return true. If not, it should return false.
Here is my code, which is failing as it is returning true even when there are no integers present. I cannot work out why this might be happening.
function findTicketPrices(emailString) {
let emailArray = emailString.split(" ");
for (let i = 0; i < emailArray.length; i++) {
if (typeof parseInt(emailArray[i]) === "number") {
return true;
}
return false
}
}
parseIntreturnsNaNwhen given an invalid argument. Despite its name,NaNis, in fact, of type number. Try changing yourifstatement to instead check if the result isNaN, rather than seeing if the type is number. For this, theNumber.isNaN()function will help you.