1

I have been trying for a few days, to get a simple if/else script to work. The issue I am having is when I check syntax, it says:

error illegal use if reserved word else

The script I am using is:

if (aira.delsec.presence = "hidden")
airb.tblair._Row1.addInstance(1)
airb.presence = "visible"
aira.delsec.presence = "visible";
else
airb.tblair._Row1.addInstance(1)

Also, I have tried:

if (aira.delsec.presence = "hidden");{ 
airb.tblair._Row1.addInstance(1)
airb.presence = "visible"
aira.delsec.presence = "visible";
} else
{
aira.delsec.presence = "visible";
}

If I remove the else then the if statement works fine. I am really pulling out my hair and any help would be greatly appreciated.

jacefarm
  • 6,747
  • 6
  • 36
  • 46
jpee
  • 15
  • 4

1 Answers1

0

Your JavaScript syntax is wrong. Try:

if (aira.delsec.presence === "hidden") { // use an opening brace, and...
                                         //   === to check for equality...
                                         //   because = assigns a value
  airb.tblair._Row1.addInstance(1);      // end with a semi-colon
  airb.presence = "visible";             // end with a semi-colon
  airb.delsec.presence = "visible";      // end with a semi-colon
} else {                                 // use closing and opening braces
  airb.tblair._Row1.addInstance(1);      // end with a semi-colon
}                                        // use a closing brace

Be sure to use a linting tool to validate your JavaScript as you learn. You will become familiar with the proper syntax more quickly.

jacefarm
  • 6,747
  • 6
  • 36
  • 46
  • hi thank you, but when i try this it completly ignores the condition and whether or not aira.delsec is hidden or visible it will add rows to my table. if i add the semicolon in at the end of the condition then the if statement works but the else statement does not. – jpee Nov 30 '16 at 17:54
  • 1
    using the website you recommended i found that the following seems to work: `if (aira.delsec.presence === "hidden") { airb.tblair._Row1.addInstance(1); airb.presence = "visible"; aira.delsec.presence = "visible"; } else { airb.tblair._Row1.addInstance(1); }` :) – jpee Nov 30 '16 at 18:00
  • Good catch @jpee - I've updated the answer. Up-vote if helpful. – jacefarm Nov 30 '16 at 18:11