+ 1

Please guy's what is missing in my rest parameters code problem (...words)

class Add { constructor(...words) { this.words = words; } print() {console.log(this.words ); } } var x = new Add("$hehe

quot;, "$hoho
quot;, "$haha
quot;, "$hihi
quot;, "$huhu
quot;); var y = new Add("$this
quot;, "$is
quot;, "$awesome
quot;); var z = new Add("$lorem
quot;, "$ipsum
quot;, "$dolor
quot;, "$sit
quot;, "$amet
quot;, "$consectetur
quot;, "$adipiscing
quot;, "$elit
quot;); x.print(); y.print(); z.print();

28th Jul 2021, 1:26 PM
Noibisjunior
Noibisjunior - avatar
7 Antworten
+ 2
Noibisjunior join() function used to combine multiple words. join() function takes one parameter and it can be any separator like any symbol ($, #, @) anything. So in this practice you have to join words with $ so in print function just do this: console.log("
quot; + (this.words).join("
quot;) + "
quot;);
28th Jul 2021, 7:33 PM
A͢J
A͢J - avatar
+ 1
Noibisjunior Don't change anything in given code. Just change in print function. You have to add $ between words and start of the word and end of the word. So for this you can use join () function and to add before and after the word just concat $.
28th Jul 2021, 1:38 PM
A͢J
A͢J - avatar
+ 1
My expected output is to print multiple words joined with the dollar sign ($) Though I have already solved the code problem.
30th Jul 2021, 8:28 AM
Noibisjunior
Noibisjunior - avatar
0
Noibisjunior Where is your attempts?
28th Jul 2021, 1:29 PM
A͢J
A͢J - avatar
0
I tried using the print function to output the string altogether but it output is in different arrays
28th Jul 2021, 1:34 PM
Noibisjunior
Noibisjunior - avatar
0
AJ Which means am using two function join() print () Really need more explanation
28th Jul 2021, 1:47 PM
Noibisjunior
Noibisjunior - avatar
0
What is your current output , and what would you like to print?
29th Jul 2021, 4:26 PM
Mostafa
Mostafa - avatar