Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

185
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda