Skip to main content
Inspiring
March 18, 2021
Answered

Closing an If statement without using "Else"

  • March 18, 2021
  • 1 reply
  • 1657 views

Hi everyone,

 

I´d like to know if it is possible to close an "if statement" without using "else if" or "else", in case there is only one condition to be met.

My code is as follows:

 

If (Text15 == "BOILING") {

app.alert ("Correct answer. Congratulations!")

}

else if (Text15 !== "BOILING") {

app.alert (Incorrect answer. Please check for any misspelling.");

 

*** end of code***

 

Is it aceptable to finish the code with only one "else if" and not using an "else" statement after it, since I don´t have any other conditions to check?

If not, how can I close these sequence of conditions, since I won´t need an "else" statement?

 

Thanks a lot for your clarification in advance.

This topic has been closed for replies.
Correct answer George_Johnson

Thanks a lot. The code is working properly now.


This would typically be written as:

 

if (Text15 == "BOILING") {
    app.alert ("Correct answer. Congratulations!");
} else {
    app.alert ("Incorrect answer. Please check for any misspelling.");
}

1 reply

ls_rbls
Community Expert
Community Expert
March 18, 2021

Well, you're actually declaring and evaluating two conditions in your script, not just one.

 

If you're using this event as custom calculation script, just close the "else if" condition with the curly brace "}".

 

There's no need to add anything else.

 

 

 

Inspiring
March 18, 2021

Thanks for your prompt reply and clarification.

 

I´ve actually mentioned having only "one condition" hypothetically. 

 

So, my code seems correct, but I keep getting error messages from the debugger saying there is

a sintax error on line 6 (the line just after the "else if" statement).

 

I even re-wrote the code after creating a new text field and a button, but the error message keeps popping up.

 

Don´t know where else to turn to.

Legend
March 18, 2021

Hello Andres,

As mentioned, your code is missing the closing curly brace "}" after the "else if" statement.

 

If (Text15 == "BOILING") {

app.alert ("Correct answer. Congratulations!")

}

else if (Text15 !== "BOILING") {

app.alert (Incorrect answer. Please check for any misspelling.");

}


 
Regards,
Mike