Code works on preview, but not on live site preview

So first of all I’d like to clarify that I’m a novice at coding- I’m a designer, not a coder.

I wrote some code to change the state of a Multi-State Box when certain text is clicked on, and since that text is duplicated across all the states, I put those elements into an array so I didn’t have to call the onClick function for them individually.

The site is not live yet, so I’m only checking it through the Site Preview option and it’s throwing up a bunch of errors that my small, non-coder brain cannot comprehend. There are no errors in Preview mode from the editor.

This is the code, please forgive its messiness:

$w.onReady(function () {
switchOnClick();
}); 

const econ = $w("#econTextP, #econTextC, #econTextT, #econtextL, #econTextD");
const politics = $w("#politicsTextE, #politicsTextC, #politicsTextT, #politicsTextL, #politicsTextD");
const climate = $w("#climateTextE, #climateTextP, #climateTextT, #climateTextL, #climateTextD");
const tech = $w("#techTextE, #techTextP, #techTextC, #techTextL, #techTextD");
const life = $w("#lifeTextE, #lifeTextP, #lifeTextC, #lifeTextT, #lifeTextD");
const edu = $w("#eduTextE, #eduTextP, #eduTextC, #eduTextT, #eduTextL");

function switchToRelevant(state) {
    $w('#multiStateBoxArticles').changeState(state);
}

function switchOnClick() {
    econ.onClick(() => {
        switchToRelevant('econState')
    })

    politics.onClick(() => {
        switchToRelevant('politicsState')
    })

    climate.onClick(() => {
        switchToRelevant('climateState')
    })

    tech.onClick(() => {
        switchToRelevant('techState')
    })

    life.onClick(() => {
        switchToRelevant('lifeState')
    })

    edu.onClick(() => {
        switchToRelevant('eduState')
    })
}

hey, @shahlalalalala if the issue is not resolved yet, please contact our Velo team, you can find instructions here: https://support.wix.com/en/article/contacting-wix-customer-care-for-support
once you will launch the ChatBot please type Velo inside the input field

Hi Andrew, modifying the code to call the function for each item individually fixed it. I’m still baffled on why it worked on the preview and not the live, though.