[SOLVED] JS project Words | Sololearn: Learn to code for FREE!

+1

[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 "$". 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

12/1/2020 6:53:06 PM

TheWh¡teCat 🇧🇬

11 Answers

New Answer

+11

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 + "$" ); so I would guess the sample string in the description is off, but the note at the end is the correct one.

+7

class Add { constructor(...words) { this.words = words; } //your code goes here print(){ let z=""; for(x of this.words){ z=z+"$"+x; } console.log(z + "$"); } } 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

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

my answer is: print(){ let y=""; for(x of this.words){ y=y+"$"+x; } console.log(y + "$"); } }

0

var x=["$hehe$hoho$haha$hihi$huhu$"]; var y=["$this$is$awesome$"]; var z=["$lorem$ipsum$dolor$sit$amet$consectetur$adipiscing$elit$"]; Console.log(""+x); console.log(""+y); console.log(""+z);

0

ako lang ba pinoy dito?HHAHAHAHA

-1

Shadow , thank you for your effort, but unfortunately that is not the reason. Before I post the question I tried to add "$" at the end, but the result is always wrong. The description in my opinion is not clear the given example (which does not have "$" at the end) and the "!" part of the task claim two opposite things - both of them lead to wrong output.