Copy link to clipboard
Copied
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 would typically be written as:
if (Text15 == "BOILING") {
app.alert ("Correct answer. Congratulations!");
} else {
app.alert ("Incorrect answer. Please check for any misspelling.");
}
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Thanks a lot. The code is working properly now.
Copy link to clipboard
Copied
This would typically be written as:
if (Text15 == "BOILING") {
app.alert ("Correct answer. Congratulations!");
} else {
app.alert ("Incorrect answer. Please check for any misspelling.");
}
Copy link to clipboard
Copied
Thanks a lot for your reply.
Now I am aware that a semi-colon is needed after the closing of each instruction (app.alert).
The code is working properly now.
Copy link to clipboard
Copied
It's not really needed, but it's good practice to add it.
Also, adding "else" or "else if" is not needed, either.