Files
wehub-resource-sync dde272c4b8
i18n - Build Validation / Validate i18n Builds (24) (push) Has been cancelled
CI - Node.js / Lint (24) (push) Has been cancelled
CI - Node.js / Build (24) (push) Has been cancelled
CI - Node.js / Test (24) (push) Has been cancelled
CI - Node.js / Test - Upcoming Changes (24) (push) Has been cancelled
CI - Node.js / Test - i18n (italian, 24) (push) Has been cancelled
CI - Node.js / Test - i18n (portuguese, 24) (push) Has been cancelled
CD - Docker - GHCR Images / Build and Push Images (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 11:55:53 +08:00

1.4 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
6a2037a68a0bc2aef0006000 Challenge 338: Pet Age Calculator 28 challenge-338

--description--

Given a pet type and age in human years, return the equivalent age in pet years using the following conversion table:

Pet Multiplier
"dog" 7
"cat" 6
"rabbit" 8
"hamster" 30
"guinea pig" 12
"goldfish" 6
"bird" 5

--hints--

petYears("dog", 5) should return 35.

assert.equal(petYears("dog", 5), 35);

petYears("cat", 9) should return 54.

assert.equal(petYears("cat", 9), 54);

petYears("rabbit", 3) should return 24.

assert.equal(petYears("rabbit", 3), 24);

petYears("hamster", 4) should return 120.

assert.equal(petYears("hamster", 4), 120);

petYears("guinea pig", 5) should return 60.

assert.equal(petYears("guinea pig", 5), 60);

petYears("goldfish", 2) should return 12.

assert.equal(petYears("goldfish", 2), 12);

petYears("bird", 1) should return 5.

assert.equal(petYears("bird", 1), 5);

--seed--

--seed-contents--

function petYears(pet, age) {

  return pet;
}

--solutions--

function petYears(pet, age) {
  const table = {
    dog: 7,
    cat: 6,
    rabbit: 8,
    hamster: 30,
    "guinea pig": 12,
    goldfish: 6,
    bird: 5,
  };

  return age * table[pet];
}