+ 5
May I know what's wrong with the answer???
every word in the string must be printed with dollar sign https://code.sololearn.com/W34EeghYpW1O/?ref=app
12 ответов
+ 3
yeah, now that's ok. really simple.
+ 2
You are probably trying to complete the javascript exercise.
You must do it in your own.
Tip: Store the complete text in a variable and output it using console.log instead of document.write at the end.
+ 2
Thank you so much!
+ 1
But it doesn't ok if I use 'console.log(). I
+ 1
Wah Wah Shwe I have suggested console.log because I thought you are trying to complete the exercise. If you are doing something else then please tell?
Note: you have to implement the logic yourself, like this question.
https://www.sololearn.com/Discuss/2640770/?ref=app
0
Here is my code! help me why it doesn't work.
/*HETE IS THE PROBLEM
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$youquot;.
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() {
for (let k = 0; k<this.words.length; k++) {
document.write("quot;+this.words[k]);
}
document.write("quot;);
document.write("\n");
}
}
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
What is the problem?
Do you want it to print to DOM or what?
print(){
var p="";
for (let i=0;i<this.words.length ;i++){
p = p + "quot; + this.words[i];
}
let r=p+"quot;;
console.log(r)
}
or
print(){
console.log('#x27;+this.words.join('#x27;)+'#x27;)
}
0
That's OK when I check this code with IDE. But why??? I can't solve the problem?
0
Wah Wah Shwe Do let me know what is the actual problem?
0
The test case is hidden and so I can't explain.
Thank you so much any way!
0
Wah Wah Shwe It's against community rules to ask for your homework.
https://www.sololearn.com/Blog/38/8-simple-rules-to-get-help-from-the-community
However, I have already given you the answer.
Just paste print method I have shared earlier in your Add class and it will pass the test.
Further, your input in var z seems to be wrong.
(Line 19: There is one "," extra input)
Reset the code and try again or copy & paste this code.
☺
https://code.sololearn.com/cZdFvYpR2O91/?ref=app
0
Here is the explanation.
https://www.sololearn.com/post/838036/?ref=app