Help Please: No hair left to pull: Javascript with Boolean

Hi all,

I am a Javascript novice and am trying to do something very basic, but cannot seem to get the syntax right.

Screen Shot 2020-02-27 at 11.41.14 AM

I have yes/no custom state called “sortDescending” that I am trying to use to define the sort sequence in the above. I have tried every possible combination of brackets, curly brackets, straight brackets and semi colons that I can think of to no avail. Can someone please save me from eternal pain and suffering.

@AliFarahat @keith @Jici @lottemint.md are the heroes who can help you!

1 Like

I don’t know JS, but games’s sortDescending’s value is either Yes or No. Your code appears to be evaluating for true, so maybe simplest fix is to change: if (whichOrder = ‘Yes’)… That will at least get the terms correct. I don’t know about other syntax, sorry.

1 Like

Another thing just occurred to me: I don’t think = is the correct operator in the evaluation expression, I think it should be: if (whichOrder==‘Yes’)

1 Like

if (whichOrder === true)

Use three “=”.

Whenever you have syntax issues, use this https://esprima.org/demo/validate.html

4 Likes

Thank you @nocodeventure @meyerhd2 @vini_brito,
Y’all are the best!!!

I pulled the initialization of the variable out of the function to make it cleaner and made sure it is a string.
Screen Shot 2020-02-27 at 5.39.16 PM

and then the clean function looks like such:
Screen Shot 2020-02-27 at 5.39.04 PM

1 Like

This topic was automatically closed after 70 days. New replies are no longer allowed.