1 Even or Odd 8 kyu


Posted by mijouhsieh on 2024-01-05

題目

題目說明:

函式帶入數字判斷是奇數還是偶數

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");
  });
});

#? : #條件運算子 #TypeScript







Related Posts

認識資料庫的推薦閱讀

認識資料庫的推薦閱讀

AI輔導室|靈活運用鏡射工具

AI輔導室|靈活運用鏡射工具

JavaScript If /else -如果我不會寫程式,你還會愛我嗎?

JavaScript If /else -如果我不會寫程式,你還會愛我嗎?


Comments