+ 7

[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=app

1st Dec 2020, 6:53 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
14 Answers
+ 12
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.
1st Dec 2020, 7:11 PM
Shadow - avatar
+ 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();
11th Mar 2021, 2:53 PM
solomon clark
solomon clark - avatar
+ 3
print() { this.words.unshift(""); this.words.push(""); console.log(this.words.join("
quot;)); }
28th Oct 2021, 11:22 PM
Kevin Alexander Alvarez Echeverri
Kevin Alexander Alvarez Echeverri - avatar
+ 2
ako lang ba pinoy dito?HHAHAHAHA
16th Jul 2021, 4:21 AM
Romar P. Castro
Romar P. Castro - avatar
+ 1
my answer is: print(){ let y=""; for(x of this.words){ y=y+"
quot;+x; } console.log(y + "
quot;); } }
5th Jan 2021, 9:19 AM
Danny Wanyoike
Danny Wanyoike - avatar
Shadow , tried it again, now it works 🐱 Thanks for your help.
1st Dec 2020, 7:23 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar
Thanks to the 2 actually if you opt for both functions.
10th Dec 2020, 4:21 AM
David Romero Vaca
David Romero Vaca - avatar
how did it work bro
11th Dec 2020, 5:11 PM
Emmanuel Osemudiamen
Emmanuel Osemudiamen - avatar
14th Dec 2020, 9:53 PM
Jordan Wendell
Jordan Wendell - avatar
TheWh¡teCat 🇧🇬 how did it work? Omg bro that caused me headache
22nd Dec 2020, 5:10 AM
Zhenis Otarbay
Zhenis Otarbay - avatar
var x=["$hehe$hoho$haha$hihi$huhu
quot;]; var y=["$this$is$awesome
quot;]; var z=["$lorem$ipsum$dolor$sit$amet$consectetur$adipiscing$elit
quot;]; Console.log(""+x); console.log(""+y); console.log(""+z);
7th Mar 2021, 12:34 PM
marisetti leela
marisetti leela - avatar
What is the correct answer for this question? Does any one know?
13th Dec 2021, 5:50 PM
Samantha Bell
Samantha Bell - avatar
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();
12th Nov 2022, 2:37 PM
Gokay BURUC - avatar
- 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.
1st Dec 2020, 7:18 PM
TheWh¡teCat 🇧🇬
TheWh¡teCat 🇧🇬 - avatar