+ 6

JavaScript last project(Words)

I can’t seem to solve this challenge. It seems like its impossible, I did every iteration there is possible. Can someone help me solve it? You can look the challenge in my profile(Challenge section draft). class Add { constructor(...words) { this.words = words; } //your code goes here print(){ var wtf=""; for(var i=0; i<this.words.length; i++){ wtf+="

quot;+this.words[i]; } console.log(wtf); } } 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 2020, 7:40 AM
BatOchir Artur
BatOchir Artur - avatar
23 Answers
+ 9
You need to add another dollar sign at the end of each line, like the note next to the exclamation mark at the end of the exercise suggests. The example in the description seems to be incorrect in this regard.
2nd Dec 2020, 8:42 AM
Shadow
Shadow - avatar
+ 20
Ofc you can use loops here, but in this case it's not nessesary. class Add { constructor(...words) { this.words = words; } print() { var s = this.words.join('
#x27;); //step 1 console.log('
#x27;+s+'
#x27;); //step 2 } } 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();
17th May 2021, 12:23 AM
z3r0
+ 12
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:09 AM
Vijayanathan Menakan
Vijayanathan Menakan - avatar
+ 2
class Add { constructor(...words) { this.words = words; } //your code goes here print() { let newstring =""; for(let i=0 ; i< this.words.length ; i++ ) { newstring = newstring + '
#x27; + this.words[i] ; } newstring = newstring + '
#x27; ; console.log(newstring) ; } } 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 Jan 2021, 11:56 AM
Sheharyar Nadeem
Sheharyar Nadeem - avatar
+ 1
My solution. print() { let crypto = "
quot;; this.words.forEach((w) => crypto += w + "
quot;); console.log(crypto); }
25th Apr 2021, 5:10 AM
Luis ZacarĂ­as
Luis ZacarĂ­as - avatar
+ 1
i can't solve this project
3rd Aug 2021, 7:19 AM
saloni soni
saloni soni - avatar
+ 1
UIUUUUU OKEY THANK YOU!!!!!
4th Oct 2021, 9:54 PM
Erli
Erli - avatar
+ 1
This works too and it's just one line class Add { constructor(...words) { this.words = words; } print(){ console.log('
#x27; + this.words.join('
#x27;)+'
#x27;) } } 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();
20th Sep 2022, 12:47 PM
Rodrigo Jourdan
Rodrigo Jourdan - avatar
0
Some of the JavaScript solutions that work on fiddle, or on Webmaker do not work on SoloLearn. Maybe some server differences.
10th Dec 2020, 7:12 PM
Rafique
Rafique - avatar
0
My code is quite simple but works just fine: class Add { constructor(...words) { this.words = words; } print() { const wordsWithDolars = this.words.map(word=>`${word} ); const reducedWordsWithDolars = wordsWithDolars.reduce((acc,currentValue)=>acc+currentValue,'
#x27;); console.log(reducedWordsWithDolars); } } 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();
11th Jan 2021, 8:31 PM
Tomasz Zarankiewicz
Tomasz Zarankiewicz - avatar
0
Your code is right. Just need to hardcode an $ un the last place. Right after the loop.
1st Feb 2021, 6:51 AM
Juan Pablo Mersuglia
Juan Pablo Mersuglia - avatar
0
class Add { constructor(...words) { this.words = words; } //your code goes here print() { var _words = ""; for (var i = 0; i < this.words.length; i++) { _words += "
quot; + this.words[i]; if(i == this.words.length -1){ _words += "
quot;; } } console.log(_words); } } 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();
19th Jul 2021, 6:18 AM
Abdullah Alsalem
Abdullah Alsalem - avatar
0
use the join method
3rd Aug 2021, 4:22 PM
othmane ghayouti
othmane ghayouti - avatar
0
I can’t seem to solve this challenge. It seems like its impossible, I did every iteration there is possible. Can someone help me solve it? You can look the challenge in my profile(Challenge section draft). class Add { constructor(...words) { this.words = words; } //your code goes here print(){ var wtf=""; for(var i=0; i<this.words.length; i++){ wtf+="
quot;+this.words[i]; } console.log(wtf); } } 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();
13th Oct 2021, 7:00 PM
АлДĐșŃĐ°ĐœĐŽŃ€ Đ”Đ”Ń€ĐŒĐ°Đœ
0
This is how i solved that: class Add { constructor(...words) { this.words = words; } //your code goes here print() { let len = this.words.length; let otp = ""; let col = ""; let i = 0; for (i = 0; i < len; i++) { let otp = this.words[i] + "
quot;; col += otp; } console.log("
quot; + col); } } 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();
22nd Jan 2022, 7:35 PM
Giorgi Bekurashvili
Giorgi Bekurashvili - avatar
0
I have try this too the outputs are corrects but its showing me no input pls someone help class Add { constructor(...words) { this.words = words; } //your code goes here print() { for(let word of this.words){ console.log("
quot;+word+"
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();
28th Jan 2022, 4:00 PM
Abdullahi Bashir
Abdullahi Bashir  - avatar
0
class Add { constructor(...words) { this.words = words; } print() { let line = ""; for(let k =0; k< this.words.length ; k++){ line += "
quot; + this.words[k]; } console.log(line + "
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();
16th Feb 2022, 12:10 AM
Ukechi Dikio
0
class Add { constructor(...words) { this.words = words; } 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();
22nd Mar 2022, 2:09 PM
Mahmoud Al Hussain
Mahmoud Al Hussain - avatar
0
Solved: class Add { constructor(...words) { this.words = words; } //your code goes here print() { console.log('
#x27;+this.words.join('
#x27;)+'
#x27;); }; } 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 Jan 2023, 4:32 AM
Ivan Bodurov
0
My example is also good, just learn array .join() method: class Add { constructor(...words) { this.words = words; } //your code goes here print() { console.log('
#x27;+this.words.join('
#x27;)+'
#x27;); } } 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 Jan 2023, 4:58 AM
Ivan Bodurov