Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lmuzquiz opened this issue Oct 24, 2017 · 3 comments
Open

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

lmuzquiz opened this issue Oct 24, 2017 · 3 comments

Comments

@lmuzquiz
Copy link

lmuzquiz commented Oct 24, 2017

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

@lmuzquiz
Copy link
Author

If this is not an issue, and since im trying to learn, instead of telling me what im doing wrong could you just point me in the right direction? Thanks!

@theRemix
Copy link
Contributor

hi @lmuzquiz it looks like your code is correct. the test suite is using sinon and weird things may be happening. can you remove the last line calculate(8,2,'add'); and test again?

@lmuzquiz
Copy link
Author

Removed the line, but i get the same result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants