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

185
Views
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 answers
Answer question

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 Report

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 Report

0

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