Play Home Contribute GitHub Join Us Discourse Staff Members GitHub Contribution Guides Team

FYC: expected a conditional expression and instead saw an assignment


I receive brown box (error?) for valid JavaScript code.

Fix Your Code: expected a conditional expression and instead saw an assignment

This is the code that is correct but “rejected”:

while (enemy=this.findNearestEnemy()) this.attack(enemy);

I have this situation at level Deadly Dungeon Rescue, new level in dungeon. Well, I used this construction for first time, maybe it has nothing to do with new level, I just want to compress my code…


I found a trick to remove the warning; this code is accepted:

while ((enemy=this.findNearestEnemy())) this.attack(enemy);


Ah, thanks for the great bug report. I’m tracking the bug over here now. Interesting that the extra parentheses are enough for the workaround.


Sometimes the (generally helpful) assumptions of the code checker can be annoying, maybe they should be warnings only?
I particularly hate when the javascript checker makes me declare my lambdas as named functions if I want to use them in a loop. (otherwise it errors out with a text like “declare functions outside loops”).
Similarly, something seems odd with javascript variable scoping (or it’s a weirder language than I thought), I can’t re-declare variables with the same name using “var” in separate scopes.

Oh, and I just switched to python to see if there’s any more sample code in “deadly dungeon rescue”, and then back to javascript, but now both the on-the-fly checker and code completion is stuck in python :slight_smile:


Does it give an error (red box) or warning (yellow box) when complaining about using functions within loops?

Are you sure you have a different scope? JavaScript only treats separate functions as separate scopes; loops and if-bodies and such things are the same scope.

I have a bug listed somewhere about the linter and autocomplete not updating properly sometimes when switching languages, but it should be all in one language if you reload the page as a workaround for now.