Skip to content

Are instructions on challenge/exercise #9 clear enough? #19

@lmuzquiz

Description

@lmuzquiz

Hello im doing your exercises, to learn JS.
On number 9 you say:

calculate(operation, x, y)

Prints out the equation: (i.e.) "1 + 5 = 6" or "8 / 2 = 4".
Returns the result.

Parameters

operation: string, "add", "subtract", "multiply", or "divide"

x: number

y: number

Returns: number, the result

So i wrote this:

function calculate (x,y,operation) {

    if (operation === 'add') {
        var add = x + y;
        console.log(x + ' + ' + y + ' = ' + add);
        return x + y;
    }

    else if (operation === 'subtract') {
        var subtract = x - y;
        console.log(x + ' - ' + y + ' = ' + subtract);
        return x - y;
    }

    else if (operation === 'multiply') {
        var multiply = x * y;
        console.log(x + ' * ' + y + ' = ' + multiply);
        return x * y;
    }

    else if (operation === 'divide') {
        var divide = x / y;
        console.log(x + ' / ' + y + ' = ' + divide);
        return x / y;
    }
 }
calculate(8,2,'add');

Which i think complies to what you are asking for. (you are asking to print out the equation and return the result). Am i right?

But i get these errors:

AssertError: expected log to be called with exact arguments 4 + 7 = 11
at Object.fail (http://127.0.0.1:8080/lib/js/sinon.js:4758:25)
at failAssertion (http://127.0.0.1:8080/lib/js/sinon.js:4719:20)
at Object.assert.(anonymous function) [as calledWithExactly] (http://127.0.0.1:8080/lib/js/sinon.js:4742:17)
at context. (http://127.0.0.1:8080/test/specs/functions.spec.js:132:20)
at callFn (http://127.0.0.1:8080/lib/js/mocha.js:4387:21)
at Test.Runnable.run (http://127.0.0.1:8080/lib/js/mocha.js:4380:7)
at Runner.runTest (http://127.0.0.1:8080/lib/js/mocha.js:4782:10)
at http://127.0.0.1:8080/lib/js/mocha.js:4860:12
at next (http://127.0.0.1:8080/lib/js/mocha.js:4707:14)
at http://127.0.0.1:8080/lib/js/mocha.js:4717:7

AssertionError: expected undefined to equal 11
at context. (http://127.0.0.1:8080/test/specs/functions.spec.js:145:41)
at callFn (http://127.0.0.1:8080/lib/js/mocha.js:4387:21)
at Test.Runnable.run (http://127.0.0.1:8080/lib/js/mocha.js:4380:7)
at Runner.runTest (http://127.0.0.1:8080/lib/js/mocha.js:4782:10)
at http://127.0.0.1:8080/lib/js/mocha.js:4860:12
at next (http://127.0.0.1:8080/lib/js/mocha.js:4707:14)
at http://127.0.0.1:8080/lib/js/mocha.js:4717:7
at next (http://127.0.0.1:8080/lib/js/mocha.js:4655:23)
at http://127.0.0.1:8080/lib/js/mocha.js:4684:5
at timeslice (http://127.0.0.1:8080/lib/js/mocha.js:5904:27)

Can you clarify?
Thanks in advanced

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions