Golf kod pomoć u rješavanju

Tell us what’s happening:
Gdje griješim?Molim vas da pomognete.

Your code so far


var 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 <= -2){
return "Eagle";
}else if(strokes == -1){
return"Birdie";
}else if(strokes == par){
return "Par";
}else if(strokes == +1){
return "Bogey";
}else if(strokes == +2){
return "Double Bogey";
}else {
return "Go home!";
}


// Only change code above this line
}

golfScore(5, 4);

Your browser information:

User Agent is: Mozilla/5.0 (iPad; CPU OS 14_0 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/86.0.4240.93 Mobile/15E148 Safari/604.1.

Challenge: Golf Code

Link to the challenge:

The + in here is not valid syntax.

Još uvijek ne razumijem.Čitala sam kako su drugi radili.Pokušavala sam mijenjati,poništavala kod ali neće.U svakom slučaju hvala.

Your logic is not correct. You are only checking the value of strokes. You need to check the difference between the par and the number of strokes.

Hvala vam na ukazanom greškama ali bi meni a i drugim(neznalicama koje su krenule od nule) više pomoglo da ste naveli neki primjer.Sve sam poništila pa ću pokušati kasnije.U svakom slučaju hvala!

You are really close. You just have a syntax problem which was mentioned earlier. Try to see if you can incorporate par into you if else statements. Also careful of casing here.

1 Like

also don’t return “Hole-in-one!”… access it from the array called names like names[0] for
“Hole-in-one!” and names[1] for “Eagle”…so on
Happy Coding.

1 Like

The tests for this one accept both forms of the answers. name[0] or “Hole-in-one!” will both pass.

oh ok… but then since the array is already declared in solution we can use it.

Yeah the test seem pretty flexible here. So it will except both forms of the answer. But yes in the future usually you will write it array[0]

I will give you an example of where your logic is wrong.

else if(strokes <= -2){
  return "Eagle";
}

An Eagle in golf is when the number of strokes is 2 less than the par. Right now you are checking if strokes is less than or equal to -2. That will never be the case because strokes will always be a positive number. What you want to check is if the number of strokes is 2 less than the par.

And then you’ll need to make the same sort of changes for Birdie, Bogey, and Double Bogey. Notice that you have Par correct though because you are checking if the number of strokes equals the par. And Hole-in-one is correct because you don’t need to compare the number of strokes to the par, a hole in one is always one stroke.

2 Likes

Hvala javit ću vam kad(ako)riješim.

Hvala na pomoći.Pokušat ću kasnije zbog drugih obaveza jer ja sam žena i majka.

Hvala vama i drugima koji mi pomažu.Polako ću raditi korak po korak jer mi je bitno da shvatim.

prvo pokušajte sami riješiti izazov. napišite kod koji znate i potražite greške i ispravite ih. kada ne dobijete traženi izlaz, postoji problem u logici, potražite savjet i naučite i promijenite kôd.

Sretno kodiranje.

problem with translation its google’s fault!!