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

GraphQL 學習手冊(繁體書版本)- 了解什麼是 GraphQL

GraphQL 學習手冊(繁體書版本)- 了解什麼是 GraphQL

SCSS - map vs list / @for vs @each

SCSS - map vs list / @for vs @each

如何合併Sitecore Server Roles

如何合併Sitecore Server Roles


Comments