2021-06-15 00:49:18 -07:00
---
id: 5664820f61c48e80c9fa476c
2021-08-05 23:31:15 +09:00
title: Jogar golfe de código
2021-06-15 00:49:18 -07:00
challengeType: 1
videoUrl: 'https://scrimba.com/c/c9ykNUR'
forumTopicId: 18195
dashedName: golf-code
---
# --description--
2021-07-26 23:39:21 +09:00
No jogo de [golfe ](https://en.wikipedia.org/wiki/Golf ), cada buraco tem um `par` , significando o número médio de `strokes` que se espera que golfista faça a fim de derrubar a bola no buraco para completar a jogada. Dependendo da distância acima ou abaixo de `par` que seu número de `strokes` estiver, há diferentes apelidos.
2021-06-15 00:49:18 -07:00
2021-07-26 23:39:21 +09:00
Sua função receberá os argumentos `par` e `strokes` . Retorne a string correta de acordo com esta tabela que lista os strokes em ordem de prioridade; superior (mais alta) para o final (mais baixo):
2021-06-15 00:49:18 -07:00
2021-07-09 21:23:54 -07:00
< table class = 'table table-striped' >< thead >< tr >< th > Strokes</ th >< th > Retorno</ th ></ tr ></ thead >< tbody >< tr >< td > 1</ td >< td > "Hole-in-one!"</ td ></ tr >< tr >< td > & #x3C ; = 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 >
2021-06-15 00:49:18 -07:00
2021-07-09 21:23:54 -07:00
`par` e `strokes` sempre será um número e positivo. Nós adicionamos um array com todos os nomes para sua conveniência.
2021-06-15 00:49:18 -07:00
# --hints--
2021-07-09 21:23:54 -07:00
`golfScore(4, 1)` deve retornar a string `Hole-in-one!`
2021-06-15 00:49:18 -07:00
```js
assert(golfScore(4, 1) === 'Hole-in-one!');
```
2021-07-09 21:23:54 -07:00
`golfScore(4, 2)` deve retornar a string `Eagle`
2021-06-15 00:49:18 -07:00
```js
assert(golfScore(4, 2) === 'Eagle');
```
2021-07-09 21:23:54 -07:00
`golfScore(5, 2)` deve retornar a string `Eagle`
2021-06-15 00:49:18 -07:00
```js
assert(golfScore(5, 2) === 'Eagle');
```
2021-07-09 21:23:54 -07:00
`golfScore(4, 3)` deve retornar a string `Birdie`
2021-06-15 00:49:18 -07:00
```js
assert(golfScore(4, 3) === 'Birdie');
```
2021-07-09 21:23:54 -07:00
`golfScore(4, 4)` deve retornar a string `Par`
2021-06-15 00:49:18 -07:00
```js
assert(golfScore(4, 4) === 'Par');
```
2021-07-09 21:23:54 -07:00
`golfScore(1, 1)` deve retornar a string `Hole-in-one!`
2021-06-15 00:49:18 -07:00
```js
assert(golfScore(1, 1) === 'Hole-in-one!');
```
2021-07-09 21:23:54 -07:00
`golfScore(5, 5)` deve retornar a string `Par`
2021-06-15 00:49:18 -07:00
```js
assert(golfScore(5, 5) === 'Par');
```
2021-07-09 21:23:54 -07:00
`golfScore(4, 5)` deve retornar a string `Bogey`
2021-06-15 00:49:18 -07:00
```js
assert(golfScore(4, 5) === 'Bogey');
```
2021-07-09 21:23:54 -07:00
`golfScore(4, 6)` deve retornar a string `Double Bogey`
2021-06-15 00:49:18 -07:00
```js
assert(golfScore(4, 6) === 'Double Bogey');
```
2021-07-09 21:23:54 -07:00
`golfScore(4, 7)` deve retornar a string `Go Home!`
2021-06-15 00:49:18 -07:00
```js
assert(golfScore(4, 7) === 'Go Home!');
```
2021-07-09 21:23:54 -07:00
`golfScore(5, 9)` deve retornar a string `Go Home!`
2021-06-15 00:49:18 -07:00
```js
assert(golfScore(5, 9) === 'Go Home!');
```
# --seed--
## --seed-contents--
```js
2021-10-27 15:10:57 +00:00
const names = ["Hole-in-one!", "Eagle", "Birdie", "Par", "Bogey", "Double Bogey", "Go Home!"];
2021-06-15 00:49:18 -07:00
function golfScore(par, strokes) {
// Only change code below this line
return "Change Me";
// Only change code above this line
}
golfScore(5, 4);
```
# --solutions--
```js
function golfScore(par, strokes) {
if (strokes === 1) {
return "Hole-in-one!";
}
if (strokes < = par - 2) {
return "Eagle";
}
if (strokes === par - 1) {
return "Birdie";
}
if (strokes === par) {
return "Par";
}
if (strokes === par + 1) {
return "Bogey";
}
if(strokes === par + 2) {
return "Double Bogey";
}
return "Go Home!";
}
```