[SOLVED] How would I have this sum print out it works

Issue

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

Solution

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()

Answered By – Sash Sinha

Answer Checked By – Gilberto Lyons (BugsFixing Admin)

Leave a Reply

Your email address will not be published.