How to use spread operator in Modern JavaScript | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to use spread operator in Modern JavaScript

You are making a text encryptor. It should take multiple words and output a combined version, where each word is separated by a dollar sign $. For example, for the words "hello", "how", "are", "you", the output should be "$hello$how$are$you

quot;. The given code declares a class named Add, with a constructor that takes one rest parameter. Complete the code by adding a print() method to the class, which should generate the requested output.

10th Aug 2022, 2:22 PM
Chandan Rajai
2 Answers
+ 3
Can you add your code? What isn't working in what you have tried to do?
10th Aug 2022, 3:47 PM
Ausgrindtube
Ausgrindtube - avatar
0
class Add { constructor(...words) { this.words = words; } //your code goes here print(){ var y =""; for (x of words){ if(x == ","){ x = ""; } else{ y += "
quot; + x; } } y = y + "
quot;; console.log(y); } }
10th Aug 2022, 4:01 PM
Chandan Rajai