Different results when running leetcode JS code runner and local

I'm trying to submit my solutions for the easy/basic Javascript problems - Jewels & Stones and Remove Parenthesis.

I get the expected output just fine in my local, but when I run it in leetcode, it shows a different output. I'm novice in programming and new to leetcode so I'm not sure if I'm using leetcode incorrectly. Let me know what the issue could be.

Jewels and Stones - link

/**
 * @param {string} J
 * @param {string} S
 * @return {number}
 */

let S = 'aAAbbbb';
let J = 'aA';
let count = 0;

var numJewelsInStones = function(J, S) {
    for (let i = 0; i < S.length; i++) (J.indexOf(S[i])>-1)?count++:false;        
    return count;
}

Remove Outermost Parentheses - link

/**
 * @param {string} S
 * @return {string}
 */
let S = "";
let R = "";

var removeOuterParentheses = function(S) {
    let openCounter = 0;
    let closeCounter = 0;
    for (let i = 0; i < S.length; i++) {

        if(S[i] === "(") openCounter++;         
        if(S[i] === ")") openCounter--
        if((S[i] === "(" && openCounter > 1) || (S[i] === ")" && openCounter > 0)){
            //console.log('S['+i+ '] - '+ S[i] +', yes: ' + openCounter);
            R+=S[i];
        }

    }
    return(R);
};
Comments (2)