Hi there!
Would this code be considered to be a more elegant execution of this mission, or is this way of writing redundant?
What would be the most optimal way to write that kind of code?
Thanks in advance.
My application of the code
function golfScore(par, strokes) {
// Only change code below this line
var conditions = {
"Hole-in-one!": (strokes == 1),
"Eagle": (strokes <= par - 2),
"Birdie": (strokes == par - 1),
"Par": (strokes == par),
"Bogey": (strokes == (par + 1)),
"Double Bogey": (strokes == (par + 2)),
"Go Home!": (strokes >= (par + 3))
};
for (var key in conditions) {
if (conditions[key]) {
return key;
}
}
// Only change code above this line
}
// Change these values to test
golfScore(4, 1);
Your browser information:
Your Browser User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:56.0) Gecko/20100101 Firefox/56.0
.
Link to the challenge: