+ 1

What is wrong with this js code?

Last ecmas6 project class Add { constructor(...words) { this.words = words; } print(){ var r = "" for(let w of this.words){ r+= "

quot;+w+"
quot; }return r } } 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();

19th Oct 2022, 8:26 PM
Thiago Silva
Thiago Silva - avatar
2 Answers
+ 2
Thanks mate! It did really help!
19th Oct 2022, 8:58 PM
Thiago Silva
Thiago Silva - avatar
+ 1
It does compile but doesn't print anything. you might be missing a console.log either console.log(x.print()); or print(){ // your code console.log(r); // instead of return r } I hope this helps :)
19th Oct 2022, 8:54 PM
Apollo-Roboto
Apollo-Roboto - avatar