Questionnaire Code in Preview and Live mode not the same

It is rather frustrating for me. I have some code that works in the preview mode but when I go to live mode it is entirely inactive. It does not even involve a database. I would really appreciate if someone can help me take a quick look. Thanks!!!

The page is https://www.teensharks.us/startup-bingo-idea-evaluator-1.
The code is simple, just three toggle switches, a “go” button, and display some dynamic text.
$w.onReady( function () {
//TODO: write your page related code here…

});
var scoreA= “0” ;
var scoreB= “0” ;
var scoreC= “0” ;
$w( ‘#text38’ ).text= “Please select the switches for three questions. When you are done, click the let’s go button.” ;

export function switch1_change(event) {
//Add your code for this event here:
if (scoreA=== “0” ) {
scoreA= “1” ;
} else {
scoreA= “0” ;
}
}

export function switch2_change(event) {
//Add your code for this event here:
if (scoreB=== “0” ) {
scoreB= “1” ;
} else {
scoreB= “0” ;
}
}

export function switch3_change(event) {
//Add your code for this event here:
if (scoreC=== “0” ) {
scoreC= “1” ;
} else {
scoreC= “0” ;
}
}

export function button13_click(event) {
//Add your code for this event here:
$w( ‘#text38’ ).text= “Congratulations. You got " +String(Number(scoreA)+Number(scoreB)+Number(scoreC))+ " points.” ;
}

Anyone at WIX have any ideas? the fact that something so simple is wrong makes me really wonder the integrity of the ADE. I know as coder I should not complain, but I am just trying to insert some lines of javascript. I think some settings is not wrong and my assumptions must be wrong. Thank you Master coders!!

It is invalid to reference page elements outside of the proper scope. You need to move the initialization of #text38 to be inside of the page’s onReady() event handler. Like this:

$w.onReady(function () {
$w('#text38').text="Please select the switches for three questions. When you are done, click the let's go button.";
});

For more information, see the article Making Sure the Element Has Loaded Before You Reference It.

Yes, it worked! The key is to reference page elements like active text box INSIDE the onReady but not in onEvent boxes such as _onclick or whatever.

I had a very surreal experience this morning.
I change the code as Yisrael suggested. I saved the page, published it, and it does not work on live site. I sent a long email to Yisrael on this forum saying it does not work.
Then I went back, and found that the change Yisrael suggested WAS NOT SAVED for some reason. (I made sure it was saved but it was still not saved). The #38 element is still out side of onReady. I change it, and it works. When I come to the forum to tell Yisrael, my previous long email is not there!!! It’s like two minutes of my life went missing. I swear it happened.
Wow!!
Thank you.

Now I have a some side comment related to the virtue of WIX. WIX is doing such a good job against Word Press!! I want you guys to keep up the good work, and certainly don’t ever let corporate greed or other financial concerns take over … It is sad to see companies like Network Solutions and WordPress run on corporate spread sheets. I am very happy that there is still companies like WIX out there doing good things. Thank you to the entire forum and team. Please keep up the innovation!! and be a leader.

Page elements can actually be referenced inside of any event handler (such as onReady, onClick, etc). They just can’t be referenced outside in the main part of the file.