Decoding a random amount of strings into a message

This function should take a random amount of numbers represented in strings, parse them into ints and then replace each string with the correct letter of the alphabet wich index is the result of input string % 27. Also when input % 27 == 0 it switches between lower and uppercase, and also when you pass an input%9==0 it switches to ‘punctuation’ mode to retrieve the corresponding puntuation character detailed in the getPunctuation function.

function compareToAlphabet(number, mode){
                const alphabetUpper = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
                const alphabetLower = ['a','b','c','d','e','f','g','h','i','j','k','l','m','i','o','p','q','r','s','t','u','v','w','x','y','z']

                const index = parseNumber(number) - 1
                
                    let result = '';
                    if(mode=='uppercase'){
                        for (let i = 0; i <= alphabetUpper.length - 1; i++){
                        if (index === alphabetUpper.indexOf(alphabetUpper[i])){
                            result = alphabetUpper[i]
                            } 
                        } return result
                    }
                    if (mode=='lowercase'){
                        for (let i = 0; i <= alphabetLower.length - 1; i++){
                        if (index === alphabetLower.indexOf(alphabetLower[i])){
                            result = alphabetLower[i]
                            } 
                        } return result
                    }
                
            }
function getPunctuation(number){
                const index = parseNumber(number);
                let result = '' 
                    switch(index){
                        case 1: result = '!';
                        break;
                        case 2: result = '?';
                        break;
                        case 3: result = ',';
                        break;
                        case 4: result = '.';
                        break;
                        case 5: result = ' ';
                        break;
                        case 6: result = ';';
                        break;
                        case 7: result = '"';
                        break;
                        case 8: result = ''';
                        break;  
                    } return result
                
            }
    function decoder(...args) {
    let resultArr = [];
    let mode = 'uppercase'; 

    for (let i = 0; i < args.length; i++) {
        let index = parseNumber(args[i]);
        function getLetter(index, mode) {
            
             
            // Update mode based on conditions
           
            if (index % 27 === 0 && mode === 'uppercase') {
                mode = 'lowercase';
            } else if (index % 27 === 0 && mode === 'lowercase') {
                mode = 'uppercase';
            } else if (index % 9 === 0 &&(mode === 'lowercase'||mode==='uppercase')){
                mode === 'punctuation'
            }
            if(mode === 'lowercase' || mode === 'uppercase'){
                return compareToAlphabet(index % 27, mode);
            }
            if(mode === 'punctuation'){
                return getPunctuation(index % 9)
            }
            
        }

        let emptyLetter = getLetter(index, mode)

        if (emptyLetter !== ''){//skips pushing empy strings
            resultArr.push(getLetter(index, mode));
        }

        mode = (index % 27 === 0 || index % 9 === 0) ? 
        ((mode === 'uppercase' || mode === 'lowercase') ? 'punctuation' : 
         (mode === 'punctuation' ? (index % 27 === 0 ? 'lowercase' : 'uppercase') : mode)) : mode;

    }
    
    return resultArr.join('');
}

Ri"'?kr"es! <— this is the output i get
Right?Yes! <— this is the expected output

what am i doing wrong?