[SOLVED] Undefined value acting as defined value

So I have various buttons that need to show or hide based on information in a dataset. If a value is present in a specific key, a button should be visible. If not, it should be hidden. Here’s the snippet of code I’m using

$w.onReady( function () {
$w(‘#dataset1’).onReady( () => {
let status = $w(‘#dataset1’).getCurrentItem().status;
console.log("Status = " + status)
if (status === “Student” || “Teacher” || “Official”) {
$w(‘#button11’).hide();
console.log(“already registered”)
(There are several nested if statements moving further but the proper closing is there for this block, including an else statement.)
I’m using the “||” since the status field of the dataset can contain any of those three options.
The console logs status as undefined but it still carries out this code instead of moving to the else statement. It should register that the value of the status field doesn’t match any of the 3 desired values and move on to the else statement if I’m correct.

Can anyone help me figure this out?

Your if statement is incorrect:

You want this :
if (status === “Student” || status === “Teacher” || status === “Official”) {
not :
if (status === “Student” || “Teacher” || “Official”) {

I know, it’s weird, but your if statement will always end up as true .

Thank you so much. That solved the problem and your quick response is very much appreciated.

1 Like