+ 4
How to solve javascript words coach problem ??
class Add { constructor(...words) { this.words = words; this.print = print; } } function print() { var a = this.words.map((word) => "$"+word); var b = a.join(""); console.log(b+"$"); } 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();
11 Antworten
+ 6
This will help you:
https://code.sololearn.com/WXLXZ2Qi1XIo/?ref=app
+ 2
Hasintha Ranaweera
Just do
console.log("$" + (this.words).join("$") + "$");
+ 2
Hasintha Ranaweera It should work. How did you write show me.
+ 2
Hasintha Ranaweera
I did the same but now my code is also not working. I think there is bug because everyone solved this with same code.
+ 2
What does "print(eachtem)" in the code does.
Well I thought it defines the $ thing to be in the words and needs a simple console.log statement. But if so, then isn't another $ placement in the function being a wrong code?
Anyone with me?
+ 1
class Add {
constructor(...words) {
this.words = words;
}
//your code goes here
print(){
let doller = "$";
for(let value of this.words)
doller = doller+(value+"$");
console.log(doller);
}
}
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();
0
Not working
0
function print() {
var a = this.words.map((word) => "$"+word);
console.log("$" + (this.words).join("$") + "$");
}
0
Which of the code coach is this one?
0
print(){
console.log('$'+this.words.join('$')+'$')
}
0
the solution is very simple .
class Add {
constructor(...words) {
this.words = words;
}
//your code goes here
print (){
return `$${this.words.join('$')}$`
}
}
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");
console.log(x.print());
console.log(y.print());
console.log(z.print());