Category: Question and Answers


This solution is summarized from an archived support forum post. This information may have changed. If you notice an error, please let us know in Discord.

SyntaxError: Unexpected token ‘if’


I am getting a SyntaxError with my if statement in my Text Label. The error says "Unexpected token 'if'". After reviewing my code, I realized that the problem was with the line that was returning a color value in my if statement. I learned that if statements cannot directly return anything and that I needed to use a return statement within a function instead to fix the issue.


The initial if statement had a syntax error, causing the “Unexpected token ‘if’” error. The problem was caused by the presence of “{ “#22c55e”; }” which cannot be returned directly from an if statement. A new solution was suggested that involves using a function that returns the appropriate color for the selectedRow status. The function includes if-else statements to check the status and return the corresponding color code. The function is immediately invoked using “()” so that the result is displayed in the Text Label. The use of return was explained to avoid similar errors in the future.