JavaScript Code coach problem...I am not actually able to get what am I supposed to do in this question????? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3

JavaScript Code coach problem...I am not actually able to get what am I supposed to do in this question?????

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. Note, that the dollar sign is placed at the beginning and at the end of the output...... My try https://code.sololearn.com/Wd5b1xcAs906/?ref=app

3rd Dec 2020, 2:11 AM
The INDIAN
The INDIAN - avatar
27 Answers
+ 11
Hi there.. your not supposed to write code outside of the class. Write your code where it says your code goes here. Also try to use join function. Or, go through each word and print dollar sign,then word. After the loop finish print a dollar sign here's my code... https://code.sololearn.com/cJgucC7EXB2f/?ref=app
3rd Dec 2020, 2:43 AM
Steve Sajeev
Steve Sajeev - avatar
+ 49
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();
8th Jan 2021, 11:05 AM
Vijayanathan Menakan
Vijayanathan Menakan - avatar
+ 13
//your code goes here print(){ var res=""; for(var i=0;i<this.words.length;i++){ res += "
quot;+this.words[i]; } console.log(res+"
quot;); }
31st Jan 2021, 10:07 AM
J.K.A
J.K.A - avatar
+ 9
class Add { constructor(...words) { this.words = words; } //my code print(){ console.log(`${this.words.join('
#x27;)} ) } }
24th Apr 2021, 10:25 AM
Vlad
Vlad - avatar
+ 4
Ans 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();
15th Mar 2021, 5:38 PM
Syed Fahad Ahmed
Syed Fahad Ahmed - avatar
+ 3
Steve Sajeev Thank you So much for the help I got what you explained me Thanks Steve for the answer
3rd Dec 2020, 2:50 AM
The INDIAN
The INDIAN - avatar
+ 3
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(); Good Luck
13th Dec 2021, 2:16 AM
Muhammad Alif Deva Rizqon
Muhammad Alif Deva Rizqon - avatar
+ 2
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();
2nd Dec 2021, 10:55 AM
么 ᴢᴀᴛᴇᴋᴀ
么 ᴢᴀᴛᴇᴋᴀ - avatar
+ 1
ᕙ(@°▽°@)ᕗ {inactive} I tried your method But still it is showing test case failed Bhai... Can you please tell what we are actually supposed to do in this question?
3rd Dec 2020, 2:39 AM
The INDIAN
The INDIAN - avatar
+ 1
class Add { constructor(...words) { this.words = words; } print(){ var result =""; for (let word of this.words) { result += "
quot;+word; } result += "
quot;; console.log(result); } } 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();
28th Apr 2021, 3:07 PM
Nantenaina Tsiory Randriamamonjisoa
+ 1
this my solution. class Add { constructor(...words) { this.words = words; } //your code goes here print(){ let result="" for (const e of this.words) { result+="
quot;+e } console.log(result+"
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();
27th May 2021, 9:24 PM
Rahul Tiwari
+ 1
class Add { constructor(...words) { this.words = words; } //your code goes here print(){ var new_T = ""; for(let i=0;i<this.words.length ; i++){ new_T += "
quot; + this.words[i]; } console.log(new_T+"
quot;); } }
22nd Jul 2021, 8:35 PM
Rajarshi Sinha
Rajarshi Sinha - avatar
+ 1
print(){ let res="
quot;; let w=this.words; for(let v of w){ res +=v+"
quot;; } console.log(res); }
21st Aug 2021, 1:11 AM
Qianhe Yu
Qianhe Yu - avatar
+ 1
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();]
18th Dec 2021, 4:04 PM
Mirmahmud Ilyosov
Mirmahmud Ilyosov - avatar
+ 1
print(){ var y =""; for (x of this.words) { if(x == ","){ x = ""; } else{ y += "
quot; + x; } } y = y + "
quot;; console.log(y); } } Try this☺️
1st Sep 2022, 2:22 PM
Pawan Kumar
Pawan Kumar - avatar
+ 1
You can also write it in this way with the for.. of iterator. print(){ var res = ""; for(let w of this.words){ res += "
quot;+w } console.log(res+"
quot;) }
3rd Jan 2023, 6:14 PM
NTADI MJ🇨🇬🌍🇨🇬
NTADI MJ🇨🇬🌍🇨🇬 - avatar
+ 1
class Add { constructor(...words) { this.words = words; } //your code goes here print(){ let res=""; for(let i=0; i< this.words.length;i++){ res=res+("
quot;+this.words[i]); } console.log(res+"
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();
9th Jan 2023, 5:05 PM
Aashiq Chalise
Aashiq Chalise - avatar
0
welcome
3rd Dec 2020, 2:52 AM
Steve Sajeev
Steve Sajeev - 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();
31st Jan 2021, 9:16 AM
Depanri Purba
Depanri Purba - avatar
0
@vlad your solution is the simplest :)
27th May 2021, 9:27 PM
Rahul Tiwari