I do not understand this question.
I create a function or callable object that takes an integer as an argument and returns “Even” for even numbers or “Odd” for odd numbers. The function should also return “Even” or “Odd” when accessing a value at an integer index. This part is somewhat confusing because we are not accessing an array or passing an array through the function. My function is as follows:
function evenOrOdd(n) {
//'Even' or 'Odd'
if(n==0){
return 'Even';
}else if(n%2==0){
return 'Even';
}
else{
return 'Odd';
}
}
But then tests are like this:
const chai = require('chai');
const assert = chai.assert;
describe("Sample tests",() => {
it("[4] is even", () => {
assert.strictEqual(evenOrOdd[4], "Even"); //<--- How do I solv this? Test Fails
});
it("2 is even", () => {
assert.strictEqual(evenOrOdd(2), "Even"); //<--- Test Passd as expected
});
it("[11] is odd", () => {
assert.strictEqual(evenOrOdd[11], "Odd"); //<--- How do I solv this? Test Fails
});
it("7 is odd", () => {
assert.strictEqual(evenOrOdd(7), "Odd"); // Test Passd as expected
});
});
What am I not understanding here and how do I overcome this?