What's wrong with my for loop? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

What's wrong with my for loop?

class Add { constructor(...words) { this.words = words; } //your code goes here print() { let x = "" for (let word of this.words) { if (word == this.words.length - 1) { x += "

quot; + word + "
quot; console.log(word) } else { x += "
quot; + word } } console.log(x) } } var x = new Add("hehe", "hoho", "haha", "hihi", "huhu"); var y = new Add("this", "is", "awesome"); var z = new Add("lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing", "elit"); x.print(); y.print(); z.print();

30th Jul 2022, 5:00 AM
rabbitdniro
3 Answers
+ 1
What do you not like about this cycle?
30th Jul 2022, 5:28 AM
Solo
Solo - avatar
0
It outputs nothing in sololearn's JavaScript ECMA6 practice test
31st Jul 2022, 6:45 AM
rabbitdniro
0
You don't have a $ sign at the end, and you're too clever with the code, no conditional expressions are needed here.
31st Jul 2022, 10:02 AM
Solo
Solo - avatar