+ 4
Why doesn't my code work? JavaScript
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
+ 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
+ 5
Gordon Generators will be a cleaner solution imo. Look at my code.
+ 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.
+ 4
Ore Wow~ 👏👏👏👏👏
+ 3
Gordon LOL. Thanks.
0
For code shrinking fans
https://code.sololearn.com/W9LG6FnScmIn/?ref=app
0
this code is one's trying https://code.sololearn.com/WeBDLeHqsopX/?ref=app
0
Cheap your spelling and santax