Golf Code Exercise

Tell us what’s happening:
Describe your issue in detail here.

So I was wondering about what might have been my Problems with why it was not correct my Code. I reviewed the Solutions and @sonofadoc response: which helped me have another Perspective hehe.
As well, a comment on the defined const in Solution 2 suggests, can not really be changed right? Since it is a constant, only var and let allow you to do so.

  **Your code so far**

const names = ["Hole-in-one!", "Eagle", "Birdie", "Par", "Bogey", "Double Bogey", "Go Home!"];

function golfScore(par, strokes) {
// Only change code below this line

if (strokes == 1) {
    return "Hole-in-one!";
  } else if (strokes <= par - 2) {
    return "Eagle";
  } else if (strokes == par - 1) {
    return "Birdie";
  } else if (strokes == par) {
    return "Par";
  } else if (strokes == par + 1) {
    return "Bogey";
  } else if (strokes == par + 2) {
    return "Double Bogey";
  } else {
return "Change Me";
// Only change code above this line

golfScore(5, 4);
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/97.0.4692.71 Safari/537.36

Challenge: Golf Code

Link to the challenge:

var is a dated keyword in JS. You will still come across it in older code so it is important to understand it. It was replaced with const as you mentioned as well as let, which will serve as a mutable variable, one that can be changed after being declared.

With this exercise it shouldn’t really matter though as nothing is getting changed, only interpreted.

Your logic for your solution should work except for two things. Instead of returning “Go Home”, it returns (With your code an error because of a syntax error). You are missing a closing bracket on your else statement.

However even fixing that, it will return “Change Me” instead of the expected output of “Go Home!”

In my solution, I accessed the responses from the names array given above.
Example: if (strokes == 1) return names[0]

Thank you, much appreciated the input!

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.