2018-10-10 18:03:03 -04:00
|
|
|
---
|
|
|
|
id: 5664820f61c48e80c9fa476c
|
2020-12-16 00:37:30 -07:00
|
|
|
title: 高尔夫代码
|
2018-10-10 18:03:03 -04:00
|
|
|
challengeType: 1
|
2020-04-29 18:29:13 +08:00
|
|
|
videoUrl: 'https://scrimba.com/c/c9ykNUR'
|
|
|
|
forumTopicId: 18195
|
2018-10-10 18:03:03 -04:00
|
|
|
---
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
# --description--
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
在高尔夫[golf](https://en.wikipedia.org/wiki/Golf)游戏中,每个洞都有自己的标准杆数`par`,代表着距离。根据你把球打进洞所挥杆的次数`strokes`,可以计算出你的高尔夫水平。
|
|
|
|
|
|
|
|
函数将会传送 2 个参数,分别是标准杆数`par`和挥杆次数`strokes`,根据下面的表格返回正确的水平段位。
|
|
|
|
|
|
|
|
<table class='table table-striped'><thead><tr><th>Strokes</th><th>Return</th></tr></thead><tbody><tr><td>1</td><td>"Hole-in-one!"</td></tr><tr><td><= par - 2</td><td>"Eagle"</td></tr><tr><td>par - 1</td><td>"Birdie"</td></tr><tr><td>par</td><td>"Par"</td></tr><tr><td>par + 1</td><td>"Bogey"</td></tr><tr><td>par + 2</td><td>"Double Bogey"</td></tr><tr><td>>= par + 3</td><td>"Go Home!"</td></tr></tbody></table>
|
|
|
|
|
|
|
|
`par`和`strokes`必须是数字而且是正数。
|
|
|
|
|
|
|
|
# --hints--
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
`golfScore(4, 1)`应该返回 "Hole-in-one!"。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
```js
|
|
|
|
assert(golfScore(4, 1) === 'Hole-in-one!');
|
|
|
|
```
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
`golfScore(4, 2)`应该返回 "Eagle"。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
|
|
|
```js
|
2020-12-16 00:37:30 -07:00
|
|
|
assert(golfScore(4, 2) === 'Eagle');
|
|
|
|
```
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
`golfScore(5, 2)`应该返回 "Eagle"。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
```js
|
|
|
|
assert(golfScore(5, 2) === 'Eagle');
|
|
|
|
```
|
|
|
|
|
|
|
|
`golfScore(4, 3)`应该返回 "Birdie"。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
```js
|
|
|
|
assert(golfScore(4, 3) === 'Birdie');
|
2018-10-10 18:03:03 -04:00
|
|
|
```
|
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
`golfScore(4, 4)`应该返回 "Par"。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
```js
|
|
|
|
assert(golfScore(4, 4) === 'Par');
|
|
|
|
```
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
`golfScore(1, 1)`应该返回 "Hole-in-one!"。
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
```js
|
|
|
|
assert(golfScore(1, 1) === 'Hole-in-one!');
|
|
|
|
```
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
`golfScore(5, 5)`应该返回 "Par"。
|
|
|
|
|
|
|
|
```js
|
|
|
|
assert(golfScore(5, 5) === 'Par');
|
|
|
|
```
|
2018-10-10 18:03:03 -04:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
`golfScore(4, 5)`应该返回 "Bogey"。
|
2020-04-29 18:29:13 +08:00
|
|
|
|
2018-10-10 18:03:03 -04:00
|
|
|
```js
|
2020-12-16 00:37:30 -07:00
|
|
|
assert(golfScore(4, 5) === 'Bogey');
|
|
|
|
```
|
2020-04-29 18:29:13 +08:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
`golfScore(4, 6)`应该返回 "Double Bogey"。
|
2020-04-29 18:29:13 +08:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
```js
|
|
|
|
assert(golfScore(4, 6) === 'Double Bogey');
|
|
|
|
```
|
2020-04-29 18:29:13 +08:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
`golfScore(4, 7)`应该返回 "Go Home!"。
|
2020-04-29 18:29:13 +08:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
```js
|
|
|
|
assert(golfScore(4, 7) === 'Go Home!');
|
|
|
|
```
|
2020-04-29 18:29:13 +08:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
`golfScore(5, 9)`应该返回 "Go Home!"。
|
2020-04-29 18:29:13 +08:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
```js
|
|
|
|
assert(golfScore(5, 9) === 'Go Home!');
|
2018-10-10 18:03:03 -04:00
|
|
|
```
|
2020-04-29 18:29:13 +08:00
|
|
|
|
2020-12-16 00:37:30 -07:00
|
|
|
# --solutions--
|
|
|
|
|