+ 4

Why doesn't my code work? JavaScript

https://code.sololearn.com/WXZ4spC5mFdW/#js

31st Oct 2020, 4:55 PM
Karak10
Karak10 - avatar
10 ответов
+ 11
Here is my version with functional scope string, and using ternary conditional operator to determine when there should be a trailing comma after each iteration. https://code.sololearn.com/WP89MNcfwn3A/?ref=app
1st Nov 2020, 2:24 AM
Gordon
Gordon - avatar
+ 8
The function returns in the first iteration. The return keyword will terminate the function execution. Therefore breaking the loop Use yield instead of return https://javascript.info/generators https://code.sololearn.com/W06j212kaoK3
31st Oct 2020, 5:01 PM
Ore
Ore - avatar
+ 5
Gordon Generators will be a cleaner solution imo. Look at my code.
31st Oct 2020, 5:05 PM
Ore
Ore - avatar
+ 4
Your first return escapes the function, so the for loop stops at first iteration. Declare a string variable in the functional scope, Concantenate it in each iteration, Return the string once only after the loop.
31st Oct 2020, 5:02 PM
Gordon
Gordon - avatar
+ 4
Ore Wow~ 👏👏👏👏👏
31st Oct 2020, 5:07 PM
Gordon
Gordon - avatar
+ 3
Gordon LOL. Thanks.
31st Oct 2020, 5:09 PM
Ore
Ore - avatar
1st Nov 2020, 12:19 PM
Ore
Ore - avatar
1st Nov 2020, 1:55 PM
Sivaprasad
0
Cheap your spelling and santax
2nd Nov 2020, 3:14 PM
Abhishek Saini
Abhishek Saini - avatar