0

Again, I have no idea what is going wrong here. I tried debugging but it just returns false no matter what I do. It is supposed to check for a number in the input string, then check if that number is greater than the input variable A and less than the input variable B.

function ageCheck(string, a, b) {
    const found = string.match(/\d{2,3}/gm)
    let containsNumber = false
    for (let i = 0; i < found.length; i++) {
        const number = parseInt(found[i])
        if (number > a && number < b) {
            let containsNumber = true
        }
    }
    return containsNumber
}

1 Answers1

0

Just as snow has said you are declaring the "containsNumber" variable twice and this won't work with let, if you wan't to declare it again you can use var instead but it's not a good idea!

function ageCheck(string, a, b) {
    
        const found = string.match(/\d{2,3}/gm)
        let containsNumber = false
    
        for (let i = 0; i < found.length; i++) {
    
            const number = parseInt(found[i])
    
            if (number > a && number < b) {
                
                containsNumber = true //remove let keyword
            }
    
        }
    
        return containsNumber
    }