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

184
Views
How i can print this in one?

I would like to know, how I can write this in one line with the symbol of dollar($) separating each word and with this symbol in the end?I've tried to change " " to $ with replace - no success. In this example it is printing $ before every word but still in a column :/

class Add {
  constructor(...words) {
    this.words = words;
  }
  print() {
    var a = this.words;

    for (let v of a) {
      v = "$" + v;
      console.log(v);
    }
  }
}

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
1 answers
Answer question

0

Unless you need the object for other things, put the strings in an array and use array.join() with '$' as the join argument, and concatentate ? to the end.

Working snippet:

let x = ["hehe", "hoho", "haha", "hihi", "huhu"];

console.log(`${x.join('$')}?`);

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!