Help is needed with ES6 with loops and functions | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Help is needed with ES6 with loops and functions

I created multiple loops with JS, but in the last loop I put 3 values Blue, Red, and Green, but for some reason, only the last value of the list is output does anyone knows why? I'm trying to make all the values to display does anyone know how to do that as well? Here is the link to the code https://code.sololearn.com/W2XAVzvtwAYL/#js

2nd Feb 2020, 12:44 AM
Danial Azadpour
Danial Azadpour - avatar
3 Answers
+ 5
you used () when you want to create an array. it will cause the last "green" be stored in x as a string. use [, ] instead.
2nd Feb 2020, 12:56 AM
Gordon
Gordon - avatar
+ 3
You are using parentheses instead of brackets. This... let x = ("Blue", "Red", "Green"); ... should be this: let x = ["Blue", "Red", "Green"]; Please also read this latest discussion to understand what's going on here: https://www.sololearn.com/discuss/2152749/?ref=app
2nd Feb 2020, 12:54 AM
HonFu
HonFu - avatar
0
Thank you again, Gordon!
2nd Feb 2020, 11:43 PM
Danial Azadpour
Danial Azadpour - avatar