I made a calculator in JS with the following parameter list to return the following results

Asked

Viewed 32 times

-1

Today I tried to create a calculator with the following function called with the following parameters :

calc(1, 4) -> retorna 5; 
calc(1, 4, 'sum') -> retorna 5; 
calc(6, 2, 'mul') -> retorna 12; 
calc(8, 2, 'div') -> retorna 4; 
calc(15, 10, 'sub') -> retorna 5.

Function below :

var assert = require('assert');

//
// Funções...
//

var somar = function(num, add) {
    return num + add;
}

var subtrair = function(num, sub) {
    return num - sub;
}

var multiplicar = function(num, mult) {
    return num * mult;
}

var dividir = function(num, divisor) {
    return num / divisor;
}

//
// Testes
//
try {
    var num = 15;

    assert.equal(1,4 somar(num, 5));
    assert.equal(15,10 subtrair(num, 5));
    assert.equal(6,2 multiplicar(num, 12));
    assert.equal(8,2 dividir(num, 4));
} catch(e) {
    console.log(e);
}

Error in the output parameter :

{ AssertionError: 15

    at Object.<anonymous> (/home/KDMe7u/prog.js:36:12)

    at Module._compile (module.js:571:32)

    at Object.Module._extensions..js (module.js:580:10)

    at Module.load (module.js:488:32)

    at tryModuleLoad (module.js:447:12)

    at Function.Module._load (module.js:439:3)

    at Module.runMain (module.js:605:10)

    at run (bootstrap_node.js:420:7)

    at startup (bootstrap_node.js:139:9)

    at bootstrap_node.js:535:3


  name: 'AssertionError',

  actual: 1,

  expected: 4,

  operator: '==',

  message: 15,

  generatedMessage: false }
  • It would be interesting to attach the code, the tests you’ve done, as much detail as possible. So just with the mistake and no more information, it gets a little difficult to help you.

  • 1

    assert.equal(1,4 somar(num, 5)), what would be 4 somar?

  • @Mariaalice, it’s worth checking your assert.equal - Function reference: assert.equal(actual, expected[, message])

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.