Back to Freecodecamp

Challenge 193: 2026 Winter Games Day 14: Ski Mountaineering

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

latest2.1 KB
Original Source

--description--

Given the snow depth and slope of a mountain, determine if there's an avalanche risk.

  • The snow depth values are "Shallow", "Moderate", or "Deep".
  • Slope values are "Gentle", "Steep", or "Very Steep".

Return "Safe" or "Risky" based on this table:

"Shallow""Moderate""Deep"
"Gentle""Safe""Safe""Safe"
"Steep""Safe""Risky""Risky"
"Very Steep""Safe""Risky""Risky"

--hints--

avalancheRisk("Shallow", "Gentle") should return "Safe".

js
assert.equal(avalancheRisk("Shallow", "Gentle"), "Safe");

avalancheRisk("Shallow", "Steep") should return "Safe".

js
assert.equal(avalancheRisk("Shallow", "Steep"), "Safe");

avalancheRisk("Shallow", "Very Steep") should return "Safe".

js
assert.equal(avalancheRisk("Shallow", "Very Steep"), "Safe");

avalancheRisk("Moderate", "Gentle") should return "Safe".

js
assert.equal(avalancheRisk("Moderate", "Gentle"), "Safe");

avalancheRisk("Moderate", "Steep") should return "Risky".

js
assert.equal(avalancheRisk("Moderate", "Steep"), "Risky");

avalancheRisk("Moderate", "Very Steep") should return "Risky".

js
assert.equal(avalancheRisk("Moderate", "Very Steep"), "Risky");

avalancheRisk("Deep", "Gentle") should return "Safe".

js
assert.equal(avalancheRisk("Deep", "Gentle"), "Safe");

avalancheRisk("Deep", "Steep") should return "Risky".

js
assert.equal(avalancheRisk("Deep", "Steep"), "Risky");

avalancheRisk("Deep", "Very Steep") should return "Risky".

js
assert.equal(avalancheRisk("Deep", "Very Steep"), "Risky");

--seed--

--seed-contents--

js
function avalancheRisk(snowDepth, slope) {

  return snowDepth;
}

--solutions--

js
function avalancheRisk(snowDepth, slope) {
  const riskTable = {
    Gentle: {
      Shallow: "Safe",
      Moderate: "Safe",
      Deep: "Safe",
    },
    Steep: {
      Shallow: "Safe",
      Moderate: "Risky",
      Deep: "Risky",
    },
    "Very Steep": {
      Shallow: "Safe",
      Moderate: "Risky",
      Deep: "Risky",
    },
  };

  return riskTable[slope][snowDepth];
}