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

163
Views
How would I have this sum print out it works
function testSum(){
    var expected = 7
    var actual = sum(5, 2)

    if (actual != expected) {
        console.log("It's broken..")
    } else {
        console.log("It works!")
    }
}

I don't know how to work this out, please help

about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

In a python programming language, you can use sum as the sum of array elements such as sum(iterable, start). However, in javascript sum is "undefined" unless you define that function. Just sum as 2+7.

about 4 years ago · Juan Pablo Isaza Report

0

Your code gives the expected output after calling the function. Though you haven't provided details on your sum function. So I can't speak on whether your sum function is returning the correct result.

I gave an example implementation of sum that checks whether a and b are numeric.

function sum(a, b) {
  if (!isNaN(a) && !isNaN(b)) 
  {
    return a + b;
  }
}

function testSum(){
  var expected = 7
  var actual = sum(5,2)

  if (actual != expected) {
      console.log("It's broken..")
  } else {
      console.log("It works!")
  }
}

testSum();

about 4 years ago · Juan Pablo Isaza Report

0

You could define a sum function that takes two numbers and returns the sum i.e.,

the total amount resulting from the addition of two or more numbers, amounts, or items.
"the sum of two prime numbers"

function sum(a, b) {
    return a + b
}

function testSum() {
    var expected = 7
    var actual = sum(5, 2)
    if (actual != expected) {
        console.log("It's broken..")
    } else {
        console.log("It works!")
    }
}

testSum()

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!