2026 Winter Games Day 14: Ski Mountaineering

This is how I approached the challenge! Can you give me advice to improve my coding?
Thanks

function avalancheRisk(snowDepth, slope) {

  const depth =[/*depth array*/];
  const getIndexDepth =// get the index of  snowDepth in depth

  const slopeObject = //  {"Gentle":[/*risk*/]  ....}
  
  const risk = slopeObject[slope][getIndexDepth];
  return risk;
}

We have blurred this solution (with [spoiler][/spoiler] tags) so that users who have not completed this challenge can read the discussion in this thread without giving away the solution.

1 Like

You can use ternary operator

function avalancheRisk(snowDepth, slope) {
  return snowDepth == 'Shallow' || slope == 'Gentle' ? 'Safe' : 'Risky';
}
1 Like

I don’t have conditions(if(){}else(){}) in my solution just indexOf() then map it to return the risk, In what part I needed to use the ternary operator? , thank you !

Hi @joseephraimbatacan

@gonza is showing an example of using the ternary operator for the coding challenge. There are many ways to solve this challenge.

Which part of your approach do you need help with?

Happy coding

1 Like

I checked how your code works and admired how you reduce the possibilities , thank you for this pov of thinking. Through this I learned new way of thinking today!

My code is working fine! his solution is absolutely brilliant! I just want to learn new ways of coding and thinking