Back to Freecodecamp

Challenge 189: 2026 Winter Games Day 10: Alpine Skiing

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

latest2.0 KB
Original Source

--description--

Given a ski hill's vertical drop, horizontal distance, and type, determine the difficulty rating of the hill.

To determine the rating:

  • Calculate the steepness of the hill by taking the drop divided by the distance.
  • Then, calculate the adjusted steepness based on the hill type:
    • "Downhill": multiply steepness by 1.2
    • "Slalom": multiply steepness by 0.9
    • "Giant Slalom": multiply steepness by 1.0

Return:

  • "Green" if the adjusted steepness is less than or equal to 0.1
  • "Blue" if the adjusted steepness is greater than 0.1 and less than or equal to 0.25
  • "Black" if the adjusted steepness is greater than 0.25

--hints--

getHillRating(95, 900, "Slalom") should return "Green".

js
assert.equal(getHillRating(95, 900, "Slalom"), "Green");

getHillRating(620, 2800, "Downhill") should return "Black".

js
assert.equal(getHillRating(620, 2800, "Downhill"), "Black");

getHillRating(420, 1680, "Giant Slalom") should return "Blue".

js
assert.equal(getHillRating(420, 1680, "Giant Slalom"), "Blue");

getHillRating(250, 3000, "Downhill") should return "Green".

js
assert.equal(getHillRating(250, 3000, "Downhill"), "Green");

getHillRating(110, 900, "Slalom") should return "Blue".

js
assert.equal(getHillRating(110, 900, "Slalom"), "Blue");

getHillRating(380, 1500, "Giant Slalom") should return "Black".

js
assert.equal(getHillRating(380, 1500, "Giant Slalom"), "Black");

--seed--

--seed-contents--

js
function getHillRating(drop, distance, type) {

  return drop;
}

--solutions--

js
function getHillRating(drop, distance, type) {
  let steepness = drop / distance;

  if (type === "Downhill") {
    steepness *= 1.2;
  } else if (type === "Slalom") {
    steepness *= 0.9;
  } else if (type === "Giant Slalom") {
    steepness *= 1.0;
  }

  if (steepness <= 0.1) {
    return "Green";
  } else if (steepness <= 0.25) {
    return "Blue";
  } else {
    return "Black";
  }
}