How to include "space" on cards

Asked

Viewed 127 times

-1

I need to include spaces between the person’s title, name and surname.

function cartao(titulo, nome, sobrenome) {
return titulo + nome + sobrenome
}

The result of this is: Dr.Matheuspeixoto without spaces and I can’t put spaces using blank quotes in "Return" does anyone help me? I’m starting now and this is an exercise in a course that I’m doing, but I can’t find explanations for what has already been said in it.

1 answer

4


Matheus,

There are several ways to do this in javascript.

One of them is using Template String:

function cartao(titulo, nome, sobrenome) {
  return `${titulo} ${nome} ${sobrenome}`;
}

let cartaoFormatado = cartao("Dr.", "Matheus", "Peixoto");

console.log(cartaoFormatado);

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/template_strings


You can also do it in the most common way by concatenating the strings with the operator (+):

function cartao(titulo, nome, sobrenome) {
  return titulo + " " + nome + " " + sobrenome;
}

let cartaoFormatado = cartao("Dr.", "Matheus", "Peixoto");

console.log(cartaoFormatado);


Finally, there is also the String Concat method:

function cartao(titulo, nome, sobrenome) {
  return titulo.concat(" ", nome, " ", sobrenome);
}

let cartaoFormatado = cartao("Dr.", "Matheus", "Peixoto");

console.log(cartaoFormatado);

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/concat

  • Daniel, thank you for answering. Looking at your solutions, I noticed what I was missing, I’m using the most common method and what I was forgetting was just the space between the quotation marks. By the way thanks for teaching me other methods.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.