Skip to content
Advertisement

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

Advertisement

Answer

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()
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement