+ 8
[SOLVED] JS project 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. The project description is really unclear. With "!" it is mentioned that output should begin and end with "
quot;. In the only one example that is not the case. The only one test case is hidden. Here is my code. I don't need a solution, if anyone understands what is the goal of the task and could explain it I will be grateful. https://code.sololearn.com/W0Kn137pFJuX/?ref=app15 Réponses
+ 13
It works for me if I append a dollar sign at the end of each output line in your code, i.e.
console.log( m + "quot; );
so I would guess the sample string in the description is off, but the note at the end is the correct one.
+ 20
class Add {
constructor(...words) {
this.words = words;
}
//your code goes here
print(){
let z="";
for(x of this.words){
z=z+"quot;+x;
}
console.log(z + "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();
+ 3
print() {
this.words.unshift("");
this.words.push("");
console.log(this.words.join("quot;));
}
+ 2
ako lang ba pinoy dito?HHAHAHAHA
+ 1
my answer is:
print(){
let y="";
for(x of this.words){
y=y+"quot;+x;
}
console.log(y + "quot;);
}
}
0
Shadow , tried it again, now it works 🐱 Thanks for your help.
0
Thanks to the 2 actually if you opt for both functions.
0
how did it work bro
0
$like$this$
0
TheWh¡teCat 🇧🇬 how did it work? Omg bro that caused me headache
0
var x=["$hehe$hoho$haha$hihi$huhuquot;];
var y=["$this$is$awesomequot;];
var z=["$lorem$ipsum$dolor$sit$amet$consectetur$adipiscing$elitquot;];
Console.log(""+x);
console.log(""+y);
console.log(""+z);
0
What is the correct answer for this question? Does any one know?
0
print() {
let str = this.words.join('#x27;);
console.log('#x27; + str + '#x27;);
}
- 1
Shadow , thank you for your effort, but unfortunately that is not the reason. Before I post the question I tried to add "quot; at the end, but the result is always wrong. The description in my opinion is not clear the given example (which does not have "quot; at the end) and the "!" part of the task claim two opposite things - both of them lead to wrong output.
- 1
Another Solution :
class Add {
constructor(...words) {
this.words = words;
}
//your code goes here
print() {
let answer = "quot;;
for (let word of this.words){
answer = answer + word + "quot;;
}
console.log(answer);
}
}
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();