Javascript-форум (https://javascript.ru/forum/)
-   Общие вопросы Javascript (https://javascript.ru/forum/misc/)
-   -   Застрял на задачке. Не понимаю логику задачи. (https://javascript.ru/forum/misc/67296-zastryal-na-zadachke-ne-ponimayu-logiku-zadachi.html)

mishapod 08.02.2017 22:34

Застрял на задачке. Не понимаю логику задачи.
 
(Перевод "Google переводчик")
Ваша функция будет передана "par" и "strokes" аргументы. Возвращает правильную строку в соответствии с этой таблицей , в которой перечислены штрихи в порядке очередности; верхний (самый высокий) до дна ( самый низкий):

Буду благодарен:thanks:


Это таблица для ГОЛЬФА : https://en.wikipedia.org/wiki/Golf


(таблицу не смог выровнять нормально)
Strokes ____Return

1 _________"Hole-in-one!"

<= par - 2 __"Eagle"

par - 1______"Birdie"

par ________"Par"

par + 1 _____"Bogey"

par + 2_____"Double Bogey"

>= par + 3__ "Go Home!"


"par" и "strokes" всегда будет числовой и положительный результат.

Есть начало задачи.

function golfScore(par, strokes) {
  // Only change code below this line
  
  
  return "Change Me";
  // Only change code above this line
}

// Change these values to test
golfScore(5, 4);


Условия:
golfScore(4, 1) should return "Hole-in-one!"

golfScore(4, 2) should return "Eagle"

golfScore(5, 2) should return "Eagle"

golfScore(4, 3) should return "Birdie"

golfScore(4, 4) should return "Par"

golfScore(1, 1) should return "Hole-in-one!"

golfScore(5, 5) should return "Par"

golfScore(4, 5) should return "Bogey"

golfScore(4, 6) should return "Double Bogey"

golfScore(4, 7) should return "Go Home!"

golfScore(5, 9) should return "Go Home!"

mishapod 08.02.2017 23:10

In the game of golf each hole has a par meaning the average number of strokes a golfer is expected to make in order to sink the ball in a hole to complete the play. Depending on how far above or below par your strokes are, there is a different nickname.

Your function will be passed par and strokes arguments. Return the correct string according to this table which lists the strokes in order of priority; top (highest) to bottom (lowest):




[IMG][/IMG]

рони 08.02.2017 23:11

mishapod,
function golfScore(par, strokes) {
 if(strokes == 1) return 'Hole-in-one!';
 strokes -= par;
 switch (strokes) {
   case -2: return  'Eagle'
   case -1: return 'Birdie'
   case 0: return 'Par'
   case 1: return 'Bogey'
   case 2: return 'Double Bogey'
   default: return 'Go Home!'

 }
}
alert(golfScore(5, 9));


Часовой пояс GMT +3, время: 08:46.