Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

450
Views
How do I take multiple words and output a combined version, where each word is separated by a dollar sign $ using ECMA6?

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();
about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

If this.words is an array of words, then the print method would simply join the words together with a "$" separator as seen here in this code snippet:

//My code :

class Add {
      constructor(...words)      {
              
this.words = words;
  

}
 //What method to use and how?
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();

about 4 years ago · Juan Pablo Isaza Report

0

class Add {
  constructor(...words) {        
    this.words = words;
  }
 //What method to use and how?
  print(divider = '$') {
    console.log(`${divider}${this.words.join(divider)}${divider}`);
  }
}

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();
// $hehe$hoho$haha$hihi$huhu$
y.print();
// $this$is$awesome$
z.print();
// $lorem$ipsum$dolor$sit$amet$consectetur$adipiscing$elit$
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!