0

Words

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. ________&________ mycode ________&________ class Add { constructor(...words) { this.words = words; } //your code goes here } 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();

10th Feb 2022, 11:57 AM
Shai Shab
Shai Shab - avatar
4 Antworten
0
class Add { constructor(...words) { this.words = words; } //your code goes here print(){ var y =""; for(x of this.words){ y += "
quot; + x; } y = y + "
quot; console.log(y); } } 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();
10th Feb 2022, 2:37 PM
Shai Shab
Shai Shab - avatar
+ 1
What is your try there? Implement print function. You can use a loop to print values.. s="
quot;; for(let i of x) { s = i + s ; } console.log(s) ; or you can use join() method..
10th Feb 2022, 12:38 PM
Jayakrishna 🇮🇳
+ 1
add and run this //your code goes here print() { console.log("
quot; + this.words.join ("
quot;) + "
quot;); } }
11th Feb 2022, 12:59 AM
Philip Onuchukwu
Philip Onuchukwu - avatar