Roman Numeral Converter Code works in vscode, not working in fcc

Hello,
I would appreciate if someone could look into this. fcc throws the error: Potential infinite loop detected on line 15. Tests may be failing because of this.
Potential infinite loop detected on line 30. Tests may be failing because of this.
These are the functions: findRange() and convert().

Here is the javascript code:

const convertBtn = document.getElementById("convert-btn");
const numberInput = document.getElementById("number");
const output = document.getElementById("output");

output.classList.toggle("hidden");

const mapSymbols = {
    1:"I", 4:"IV", 5:"V", 9:"IX", 10:"X", 40:"XL", 50:"L", 90:"XC", 100:"C", 400:"CD", 500:"D", 900:"CM", 1000:"M"
};
let keys = Object.keys(mapSymbols);     //This will produce an array of keys ['1', '5', ...]

let t = "";         //output result
let r = 12;        //index of findRange

const findRange = (n) => {
    if (r === 0) {
        return r
    } 
    else {
        if (n >= Number(keys[r])) {
            return r
        }
        else {
            r -= 1;
            return findRange(n);
        }
    }
 }

const convert = (n) => {  
    let rg = findRange(n);
    if (n === Number(keys[rg])) {
        return mapSymbols[keys[rg]] + ","
    } 
    return convert(n - Number(keys[rg])) + mapSymbols[keys[rg]] + ",";
}

const resolve = () => {
    let numberValue = parseInt(numberInput.value);

    //Run some checks
    if (!numberValue|| isNaN(numberValue)) {
        alert("Please enter a valid number");
        return
    }

    if (numberValue >= 4000) {
        alert("Please enter a number less than or equal to 3999");
        return
    }

    if (numberValue <= 0) {
        alert("Please enter a number greater than or equal to 1");
        return
    }
    
    //Run the conversion reversing the order of the output
    t = convert(numberValue).split(",").reverse().join("");    
    output.classList.toggle("hidden");    
    output.innerHTML = `       
        <p id="result">${t}</p>       
    `
}

convertBtn.addEventListener("click", resolve);

I wouldn’t use these global variables