password protected video if statement

An input field, a button, a box container and a video player. Having trouble with an if else statement.
First fill out the input field with a password ,then upon button click I want the code to check if the input field’s content is equal to string1. If it is equal, then play the video. Else videoplayer1 pause.

$w.onReady(function () {

});

 var string1 = "password";
 

export function button1_click(event) { 
 var string2 = $w("#input1");
 if((string2 = string1)) {
        $w('#videoPlayer1').play();
    }else{$w('#videoPlayer1').pause();}
}

I’ll hide the video controls as well, after I get this part to work.
What am i doing wrong ? lol
thank you. :blush:

The comparison in your if statement is incorrect.

You have this:

if((string2 = string1)) {

You want this:

if((string2 === string1)) {

See JavaScript Comparison and Logical Operators for more information.

Thanks Yisrael.
That made a difference. Now the button will pause the video. I’m not sure if string1, string2 or both are not getting the string assigned to it/them. It doesn’t play the video even if i enter “password” into input1.
Should i be using a dataset or maybe I’m missing a setting in the input1 or button1?
This is what i have for code now.


$w.onReady(function () {

});


var string1 = "password"; 
var string2 = $w("#input1");

export function button1_click(event) { 
 if((string2 === string1)) {
        $w('#videoPlayer1').play();
    }else{$w('#videoPlayer1').pause();
    }

}

I’m excited ! I got it to work. You were a big help, you pointed me in the right direction. Thank you. :blush:


$w.onReady(function () {

});


export function button1_click(event) {
 let txt1 = "key";
 let txt2 = $w("#input1").value// "Text Value"
    console.log(txt2);
 if((txt2 === txt1)) {
            $w('#videoPlayer1').play();
        }
 else {
            $w('#videoPlayer1').pause();
        }
}

What I’ll do next is hide the controls for the video player. :blush: