+ 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?3 Respostas
+ 2
Try looking at what using
this.words.join("quot;)
does for you. I'm sure you can finish the rest off 😉
+ 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
+ 1
Thank you ver much.