Back to Freecodecamp

Challenge 183: 2026 Winter Games Day 4: Ski Jumping

curriculum/challenges/english/blocks/daily-coding-challenges-javascript/697a49e6ff50d756c9b69360.md

latest2.0 KB
Original Source

--description--

Given distance points, style points, a wind compensation value, and K-point bonus value, calculate your score for the ski jump and determine if you won a medal or not.

  • Your score is calculated by summing the above four values.

The current total scores of the other jumpers are:

sh
165.5
172.0
158.0
180.0
169.5
175.0
162.0
170.0
  • If your score is the best, return "Gold"
  • If it's second best, return "Silver"
  • If it's third best, return "Bronze"
  • Otherwise, return "No Medal"

--hints--

skiJumpMedal(125.0, 58.0, 0.0, 6.0) should return "Gold".

js
assert.equal(skiJumpMedal(125.0, 58.0, 0.0, 6.0), "Gold");

skiJumpMedal(119.0, 50.0, 1.0, 4.0) should return "Bronze".

js
assert.equal(skiJumpMedal(119.0, 50.0, 1.0, 4.0), "Bronze");

skiJumpMedal(122.0, 52.0, -1.0, 4.0) should return "Silver".

js
assert.equal(skiJumpMedal(122.0, 52.0, -1.0, 4.0), "Silver");

skiJumpMedal(118.0, 50.5, -1.5, 4.0) should return "No Medal".

js
assert.equal(skiJumpMedal(118.0, 50.5, -1.5, 4.0), "No Medal");

skiJumpMedal(124.0, 50.5, 2.0, 5.0) should return "Gold".

js
assert.equal(skiJumpMedal(124.0, 50.5, 2.0, 5.0), "Gold");

skiJumpMedal(119.0, 49.5, 0.0, 3.0) should return "No Medal".

js
assert.equal(skiJumpMedal(119.0, 49.5, 0.0, 3.0), "No Medal");

--seed--

--seed-contents--

js
function skiJumpMedal(distancePoints, stylePoints, windComp, kPointBonus) {

  return distancePoints;
}

--solutions--

js
function skiJumpMedal(distancePoints, stylePoints, windComp, kPointBonus) {
  const myScore = distancePoints + stylePoints + windComp + kPointBonus;
  const otherScores = [165.5, 172.0, 158.0, 180.0, 169.5, 175.0, 162.0, 170.0];
  const allScores = [...otherScores, myScore];
  allScores.sort((a, b) => b - a);
  const rank = allScores.indexOf(myScore) + 1;

  if (rank === 1) return "Gold";
  if (rank === 2) return "Silver";
  if (rank === 3) return "Bronze";
  return "No Medal";
}