題目說明:
函式帶入數字判斷是奇數還是偶數
code
function evenOrOdd(number) {
return number % 2 === 0 ? 'Even' : 'Odd'
}
測試
import { evenOrOdd } from "./solution";
import { assert } from "chai";
describe("Example tests", function() {
it("evenOrOdd(1) should return 'Odd'", function(){
assert.equal(evenOrOdd(1), "Odd");
});
it("evenOrOdd(2) should return 'Even'", function(){
assert.equal(evenOrOdd(2), "Even");
});
it("evenOrOdd(-1) should return 'Odd'", function(){
assert.equal(evenOrOdd(-1), "Odd");
});
it("evenOrOdd(-2) should return 'Even'", function(){
assert.equal(evenOrOdd(-2), "Even");
});
it("evenOrOdd(0) should return 'Even'", function(){
assert.equal(evenOrOdd(0), "Even");
});
});