// Since Node 10, we're using Mocha. // You can use `chai` for assertions. const chai = require("chai"); const assert = chai.assert; // Uncomment the following line to disable truncating failure messages for deep equals, do: // chai.config.truncateThreshold = 0; // Since Node 12, we no longer include assertions from our deprecated custom test framework by default. // Uncomment the following to use the old assertions: // const Test = require("@codewars/test-compat"); describe("evenOrOdd",function() { it("Basic tests",function() { assert.strictEqual((2).evenOrOdd(), 'Even') assert.strictEqual((3).evenOrOdd(), 'Odd') assert.strictEqual((9.2).evenOrOdd(), 'Not an integer') assert.strictEqual((9).evenOrOdd(), 'Odd') }); })
- // Since Node 10, we're using Mocha.
- // You can use `chai` for assertions.
- const chai = require("chai");
- const assert = chai.assert;
- // Uncomment the following line to disable truncating failure messages for deep equals, do:
- // chai.config.truncateThreshold = 0;
- // Since Node 12, we no longer include assertions from our deprecated custom test framework by default.
- // Uncomment the following to use the old assertions:
- // const Test = require("@codewars/test-compat");
- describe("evenOrOdd",function() {
- it("Basic tests",function() {
//assert.strictEqual(evenOrOdd(2), 'Even')//assert.strictEqual(evenOrOdd(3), 'Odd')//assert.strictEqual(evenOrOdd('adc'), 'Not an integer')//assert.strictEqual(evenOrOdd(9.2), 'Not an integer')//assert.strictEqual(evenOrOdd('4'), 'Even')//assert.strictEqual(evenOrOdd('9'), 'Odd')- assert.strictEqual((2).evenOrOdd(), 'Even')
- assert.strictEqual((3).evenOrOdd(), 'Odd')
- assert.strictEqual((9.2).evenOrOdd(), 'Not an integer')
- assert.strictEqual((9).evenOrOdd(), 'Odd')
- });
- })
I don't know how to write tests for this, pls help!
Number.prototype.evenOrOdd = function() { return (['Even', 'Odd'][this%2])||'Not an integer' }
const evenOrOdd=n=>(['Even', 'Odd'][n%2])||'Not an integer'- Number.prototype.evenOrOdd = function() {
- return (['Even', 'Odd'][this%2])||'Not an integer'
- }
// Since Node 10, we're using Mocha. // You can use `chai` for assertions. const chai = require("chai"); const assert = chai.assert; // Uncomment the following line to disable truncating failure messages for deep equals, do: // chai.config.truncateThreshold = 0; // Since Node 12, we no longer include assertions from our deprecated custom test framework by default. // Uncomment the following to use the old assertions: // const Test = require("@codewars/test-compat"); describe("evenOrOdd",function() { it("Basic tests",function() { //assert.strictEqual(evenOrOdd(2), 'Even') //assert.strictEqual(evenOrOdd(3), 'Odd') //assert.strictEqual(evenOrOdd('adc'), 'Not an integer') //assert.strictEqual(evenOrOdd(9.2), 'Not an integer') //assert.strictEqual(evenOrOdd('4'), 'Even') //assert.strictEqual(evenOrOdd('9'), 'Odd') }); })
- // Since Node 10, we're using Mocha.
- // You can use `chai` for assertions.
- const chai = require("chai");
- const assert = chai.assert;
- // Uncomment the following line to disable truncating failure messages for deep equals, do:
- // chai.config.truncateThreshold = 0;
- // Since Node 12, we no longer include assertions from our deprecated custom test framework by default.
- // Uncomment the following to use the old assertions:
- // const Test = require("@codewars/test-compat");
- describe("evenOrOdd",function() {
- it("Basic tests",function() {
assert.strictEqual(evenOrOdd(2), 'Even')assert.strictEqual(evenOrOdd(3), 'Odd')assert.strictEqual(evenOrOdd('adc'), 'Not an integer')assert.strictEqual(evenOrOdd(9.2), 'Not an integer')assert.strictEqual(evenOrOdd('4'), 'Even')assert.strictEqual(evenOrOdd('9'), 'Odd')- //assert.strictEqual(evenOrOdd(2), 'Even')
- //assert.strictEqual(evenOrOdd(3), 'Odd')
- //assert.strictEqual(evenOrOdd('adc'), 'Not an integer')
- //assert.strictEqual(evenOrOdd(9.2), 'Not an integer')
- //assert.strictEqual(evenOrOdd('4'), 'Even')
- //assert.strictEqual(evenOrOdd('9'), 'Odd')
- });
- })
Made it evenOrOdd, not isEven!
const evenOrOdd = n => Number.isInteger(+n) ? (!(n%2) ? 'Even' : 'Odd') : 'Not an integer';
const evenOrOdd = n => Number.isInteger(+n) ? !(n%2) : 'Not an integer';- const evenOrOdd = n => Number.isInteger(+n)
- ? (!(n%2) ? 'Even' : 'Odd')
- : 'Not an integer';
// Since Node 10, we're using Mocha. // You can use `chai` for assertions. const chai = require("chai"); const assert = chai.assert; // Uncomment the following line to disable truncating failure messages for deep equals, do: // chai.config.truncateThreshold = 0; // Since Node 12, we no longer include assertions from our deprecated custom test framework by default. // Uncomment the following to use the old assertions: // const Test = require("@codewars/test-compat"); describe("evenOrOdd",function() { it("Basic tests",function() { assert.strictEqual(evenOrOdd(2), 'Even') assert.strictEqual(evenOrOdd(3), 'Odd') assert.strictEqual(evenOrOdd('adc'), 'Not an integer') assert.strictEqual(evenOrOdd(9.2), 'Not an integer') assert.strictEqual(evenOrOdd('4'), 'Even') assert.strictEqual(evenOrOdd('9'), 'Odd') }); })
- // Since Node 10, we're using Mocha.
- // You can use `chai` for assertions.
- const chai = require("chai");
- const assert = chai.assert;
- // Uncomment the following line to disable truncating failure messages for deep equals, do:
- // chai.config.truncateThreshold = 0;
- // Since Node 12, we no longer include assertions from our deprecated custom test framework by default.
- // Uncomment the following to use the old assertions:
- // const Test = require("@codewars/test-compat");
- describe("evenOrOdd",function() {
- it("Basic tests",function() {
assert.strictEqual(evenOrOdd(2), true)assert.strictEqual(evenOrOdd(3), false)- assert.strictEqual(evenOrOdd(2), 'Even')
- assert.strictEqual(evenOrOdd(3), 'Odd')
- assert.strictEqual(evenOrOdd('adc'), 'Not an integer')
- assert.strictEqual(evenOrOdd(9.2), 'Not an integer')
assert.strictEqual(evenOrOdd('4'), true)assert.strictEqual(evenOrOdd('9'), false)- assert.strictEqual(evenOrOdd('4'), 'Even')
- assert.strictEqual(evenOrOdd('9'), 'Odd')
- });
- })
First time kumite
const evenOrOdd = n => Number.isInteger(+n) ? !(n%2) : 'Not an integer';
const evenOrOdd = n => !(n%2)- const evenOrOdd = n => Number.isInteger(+n) ? !(n%2) : 'Not an integer';
// Since Node 10, we're using Mocha. // You can use `chai` for assertions. const chai = require("chai"); const assert = chai.assert; // Uncomment the following line to disable truncating failure messages for deep equals, do: // chai.config.truncateThreshold = 0; // Since Node 12, we no longer include assertions from our deprecated custom test framework by default. // Uncomment the following to use the old assertions: // const Test = require("@codewars/test-compat"); describe("evenOrOdd",function() { it("Basic tests",function() { assert.strictEqual(evenOrOdd(2), true) assert.strictEqual(evenOrOdd(3), false) assert.strictEqual(evenOrOdd('adc'), 'Not an integer') assert.strictEqual(evenOrOdd(9.2), 'Not an integer') assert.strictEqual(evenOrOdd('4'), true) assert.strictEqual(evenOrOdd('9'), false) }); })
- // Since Node 10, we're using Mocha.
- // You can use `chai` for assertions.
- const chai = require("chai");
- const assert = chai.assert;
- // Uncomment the following line to disable truncating failure messages for deep equals, do:
- // chai.config.truncateThreshold = 0;
- // Since Node 12, we no longer include assertions from our deprecated custom test framework by default.
- // Uncomment the following to use the old assertions:
- // const Test = require("@codewars/test-compat");
describe("Solution", function() {it("should test for something", function() {// Test.assertEquals(1 + 1, 2);// assert.strictEqual(1 + 1, 2);- describe("evenOrOdd",function() {
- it("Basic tests",function() {
- assert.strictEqual(evenOrOdd(2), true)
- assert.strictEqual(evenOrOdd(3), false)
- assert.strictEqual(evenOrOdd('adc'), 'Not an integer')
- assert.strictEqual(evenOrOdd(9.2), 'Not an integer')
- assert.strictEqual(evenOrOdd('4'), true)
- assert.strictEqual(evenOrOdd('9'), false)
- });
});- })