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

190
Visualizações
how can I solve this problem with sum function in javascript?

I am studying javascipt and meet a very small exercise like this.

Create a sum function with 2 parameters a and b. This is a function which mean they will make the summation between two numbers. The function will return the result of a + b.

Here is my code

function sum(a,b) {
c=a+b;
console.log(c);
}
writelog(sum);

But it said to me that there are some errors in my code, so could you please give me some ideas ? Thank you very much for your time.

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

Your instructions say that the function should return the result, not print it. The printing should be done by the caller.

You need to supply arguments when calling the function.

function sum(a, b) {
  c = a + b;
  return c;
}
console.log(sum(5, 10));

about 4 years ago · Juan Pablo Isaza Relatório

0

First, your code using wrong function console.log instead of writelog.

Second, your function should return value instead of console log inside it.

Third, when you call function need input parameter for it.

function sum(a,b) {
let c=a+b;
return c;
}
console.log(sum(5,6));

about 4 years ago · Juan Pablo Isaza Relatório

0

function sum(a,b) {
  return a+b;
}
const answer = sum(5,6)
console.log(answer)
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