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

2.0 KiB

id, title, challengeType, dashedName
id title challengeType dashedName
699c8e045ee7cb94ed2322da Challenge 219: Anniversary Milestones 28 challenge-219

--description--

Given an integer representing the number of years a couple has been married, return their most recent anniversary milestone according to this chart:

Years Married Milestone
1 "Paper"
5 "Wood"
10 "Tin"
25 "Silver"
40 "Ruby"
50 "Gold"
60 "Diamond"
70 "Platinum"
  • If they haven't reached the first milestone, return "Newlyweds".

--hints--

getMilestone(0) should return "Newlyweds".

assert.equal(getMilestone(0), "Newlyweds");

getMilestone(1) should return "Paper".

assert.equal(getMilestone(1), "Paper");

getMilestone(8) should return "Wood".

assert.equal(getMilestone(8), "Wood");

getMilestone(10) should return "Tin".

assert.equal(getMilestone(10), "Tin");

getMilestone(26) should return "Silver".

assert.equal(getMilestone(26), "Silver");

getMilestone(45) should return "Ruby".

assert.equal(getMilestone(45), "Ruby");

getMilestone(50) should return "Gold".

assert.equal(getMilestone(50), "Gold");

getMilestone(64) should return "Diamond".

assert.equal(getMilestone(64), "Diamond");

getMilestone(71) should return "Platinum".

assert.equal(getMilestone(71), "Platinum");

--seed--

--seed-contents--

function getMilestone(years) {

  return years;
}

--solutions--

function getMilestone(years) {
  if (years < 1) return "Newlyweds";

  const milestones = [
    [1, "Paper"],
    [5, "Wood"],
    [10, "Tin"],
    [25, "Silver"],
    [40, "Ruby"],
    [50, "Gold"],
    [60, "Diamond"],
    [70, "Platinum"]
  ];

  for (let i = milestones.length - 1; i >= 0; i--) {
    if (years >= milestones[i][0]) {
      return milestones[i][1];
    }
  }
}