- 2

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". 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. class Add { constructor(...words) { this.words = words; } //your code goes here print(){ var y =""; for(x of this.words){ y += `${x}`; } 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(); It's showing error why don't know, test is also locked

3rd Dec 2020, 2:43 PM
sm pravin
sm pravin - avatar
29 Answers
+ 5
sm pravin Just do like for (x of this.words) { y += "
quot; + x; } y = y + "
quot;;
3rd Dec 2020, 4:16 PM
A͢J
A͢J - avatar
+ 34
class Add { constructor(...words) { this.words = words; } //your code goes here print(){ var y =""; for (x of this.words) { if(x == ","){ x = ""; } else{ 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();
3rd Dec 2020, 2:50 PM
ㅤㅤㅤ
+ 2
class Add { constructor(...words) { this.words = words; } //your code goes here print(){ var i = 0; var text = ""; while(i <= this.words.length-1){ text += "
quot;+this.words[i]; ++i; } console.log(text+"
quot;); } } 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();
18th May 2021, 8:01 AM
Rahul kamat
Rahul kamat - avatar
+ 1
sm pravin it does not work for me
22nd Dec 2020, 6:35 AM
Zhenis Otarbay
Zhenis Otarbay - avatar
+ 1
There was a recent update to the supplied code, and it breaks older attempts. My old code once passed, but now fails. There is an easy fix. See my full explanation in this post. https://www.sololearn.com/Discuss/2630096/?ref=app
22nd Dec 2020, 7:09 AM
Brian
Brian - avatar
+ 1
print(){ this.words.push("
quot;); var newWords = this.words.map((word)=> "
quot;+word).join(''); var a = newWords.slice(0, -1); console.log(a); } }
14th Mar 2021, 4:02 PM
Nick Triandafillidis
Nick Triandafillidis - avatar
+ 1
class Add { constructor(...words) { this.words = words; } //your code goes here print(){ var y ="
quot;; for(x of this.words){ y += `${x} ; } 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();
21st Jun 2022, 11:19 PM
Beshoy nady naguip
Beshoy nady naguip - avatar
+ 1
My one-line solution: class Add { constructor(...words) { this.words = words; } //your code goes here print(){ console.log("
quot;+this.words.join("
quot;)+"
quot;); } } 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();
26th Aug 2022, 6:29 PM
Dimitris Panopoulos
Dimitris Panopoulos - avatar
0
i tried lots of ways but it still doesnt work and i dont know what is its test :((
10th Dec 2020, 6:56 PM
h.g
h.g - avatar
0
I Am Groot ! How did it work?
22nd Dec 2020, 5:33 AM
Zhenis Otarbay
Zhenis Otarbay - avatar
0
Zhenis Otarbay Try to understand the problem, you will get the solution.
22nd Dec 2020, 5:52 AM
A͢J
A͢J - avatar
22nd Dec 2020, 5:56 AM
Zhenis Otarbay
Zhenis Otarbay - avatar
0
Zhenis Otarbay There is nothing wrong in your code even my code is also not working but I already solved. I think Sololearn added some new bug in this problem. Send mail.
22nd Dec 2020, 6:19 AM
A͢J
A͢J - avatar
0
I Am Groot ! How did you solved?
22nd Dec 2020, 6:22 AM
Zhenis Otarbay
Zhenis Otarbay - avatar
22nd Dec 2020, 7:12 AM
sm pravin
sm pravin - avatar
0
a simple one liner: console.log('
#x27;+this.words.join('
#x27;)+'
#x27;);
9th Apr 2021, 11:15 PM
Otto
Otto  - avatar
0
class Add { constructor(...words) { this.words = words; } //your code goes here#print(){ print(){ var hey=""; for(var i=0; i<this.words.length; i++){ hey+="
quot;+this.words[i]; } console.log(hey+ "
quot;); } } 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();
6th May 2021, 10:06 AM
Hamid Amachnoug
Hamid Amachnoug - avatar
7th Aug 2021, 12:44 PM
Onyedikachi Onu
Onyedikachi Onu - avatar
0
class Add { constructor(...words) { this.words = words; } //your code goes here print(){ var y =""; for (x of this.words) { if(x == ","){ x = ""; } else{ 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(); its working
17th Aug 2021, 12:18 PM
Swadhin Kumar
Swadhin Kumar - avatar
0
class Add { constructor(...words) { this.words = words; } //your code goes here print(){ var y =""; for (x of this.words) { if(x == ","){ x = ""; } else{ 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();
3rd Apr 2022, 1:30 PM
Rajkumar Shil
Rajkumar Shil - avatar