I am unable to grasp ECMA6 ,can anyone help me with this project with single line comments explaining how to do this? | Sololearn: Learn to code for FREE!

0

I am unable to grasp ECMA6 ,can anyone help me with this project with single line comments explaining how to do this?

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. //My code : class Add { constructor(...words) { this.words = words; } //What method to use and how? } 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/1/2021 8:27:47 PM

Rubayet Kamal

1 Answer

New Answer

0

nevermind it was easier than I thought,this worked out class Add { constructor(...words) { this.words = words; } print(){ console.log('$' + 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"); x.print(); y.print(); z.print();