); } } var x = new Add("hehe", "hoho", "ha"/> ); } } var x = new Add("hehe", "hoho", "ha"/> ); } } var x = new Add("hehe", "hoho", "ha"/>
+ 1

Class

class Add { constructor(...words) { this.words = words; } print() { console.log(`${this.words} ); } } 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(); This code must output like that: $hehe$hoho$haha$hihi$huhu$ $this$is$awesome$ $lorem$ipsum$dolor$sit$amet$consectetur$adipiscing$elit$ But it is not outputting: $hehe,hoho,haha,hihi,huhu$ $this,is,awesome, $lorem,ipsum,dolor,sit,amet,consectetur,adipiscing,elit$ Please, Could you solve the problem?

28th Mar 2021, 2:54 AM
0diljon Abduqaxxarov
0diljon Abduqaxxarov - avatar
3 odpowiedzi
+ 2
Try looking at what using this.words.join("
quot;) does for you. I'm sure you can finish the rest off 😉
28th Mar 2021, 8:53 AM
Russ
Russ - avatar
+ 2
...words is taking the arguments as Array. The comma are due to stringifying Array. As Russ suggested, you could use the String method join() Here is the mdn page for join() : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join
28th Mar 2021, 6:07 PM
Gordon
Gordon - avatar
+ 1
Thank you ver much.
28th Mar 2021, 6:09 PM
0diljon Abduqaxxarov
0diljon Abduqaxxarov - avatar