You doubt Function and Length?

Asked

Viewed 77 times

-1

Good evening Everyone,

I would like to help with the following code:

function tamanhoNomeCompleto(nome, sobrenome){
   return (nome + " " + sobrenome).length;
}

tamanhoNomeCompleto("Lucas", "Paixao");

console.log(tamanhoNomeCompleto.length + " digitos");

With this code, the answer I get is "2 digits", but wouldn’t it be right for me to receive "12 digits"? Can anyone help me with that question? Thanks for your help.

Att, Lucas

  • 2

    The code is running perfectly. Its function returns the LENGTH of what was passed, which is 12. Next you do console.log. length of 12 returned. That is "2". Try decreasing the strings so that the length is 9, for example. The length of 9 is 1.

  • 2

    This is asked almost every day here https://answall.com/search?q=tamanhoNomeCompleto.

1 answer

2

You call tamanhoNomeCompleto.length, That means you’re trying to get the size of the function.

But its function returns the sum size, nome + sobrenome + espaço = "Lucas Paixão" = 12 characters.

So are you instead of calling tamanhoNomeCompleto.length swap for tamanhoNomeCompleto("Lucas", "Paixao");

At the end your code should be:

function tamanhoNomeCompleto(nome, sobrenome){
   return (nome + " " + sobrenome).length;
}

console.log(tamanhoNomeCompleto("Lucas", "Paixao") + " digitos");

Browser other questions tagged

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