Вход

Просмотр полной версии : Застрял на задачке. Не понимаю логику задачи.


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):

http://i.piccy.info/i9/9523d3ecafa5b38be19db3273e08e94c/1486584282/6317/1117042/golf_240.jpg (http://piccy.info/view3/10824610/f2d829c04be6edbd52d1bc218a87cd52/)http://i.piccy.info/a3/2017-02-08-20-09/i9-10824610/240x218-r/i.gif (http://i.piccy.info/a3c/2017-02-08-20-09/i9-10824610/240x218-r)


http://i.piccy.info/i9/8ab49db4089290106359b8db93da99a6/1486584485/8052/1117042/golf2_240.jpg (http://piccy.info/view3/10824623/4cbe8dd294197e03d23d5b2691b1bfca/)http://i.piccy.info/a3/2017-02-08-20-08/i9-10824623/182x240-r/i.gif (http://i.piccy.info/a3c/2017-02-08-20-08/i9-10824623/182x240-r)

рони
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));