Oliver Eyton-Williams ee1e8abd87
feat(curriculum): restore seed + solution to Chinese (#40683)
* feat(tools): add seed/solution restore script

* chore(curriculum): remove empty sections' markers

* chore(curriculum): add seed + solution to Chinese

* chore: remove old formatter

* fix: update getChallenges

parse translated challenges separately, without reference to the source

* chore(curriculum): add dashedName to English

* chore(curriculum): add dashedName to Chinese

* refactor: remove unused challenge property 'name'

* fix: relax dashedName requirement

* fix: stray tag

Remove stray `pre` tag from challenge file.

Signed-off-by: nhcarrigan <nhcarrigan@gmail.com>

Co-authored-by: nhcarrigan <nhcarrigan@gmail.com>
2021-01-12 19:31:00 -07:00

2.7 KiB

id, title, challengeType, videoUrl, forumTopicId, dashedName
id title challengeType videoUrl forumTopicId dashedName
5664820f61c48e80c9fa476c 高尔夫代码 1 https://scrimba.com/c/c9ykNUR 18195 golf-code

--description--

在高尔夫golf游戏中,每个洞都有自己的标准杆数par,代表着距离。根据你把球打进洞所挥杆的次数strokes,可以计算出你的高尔夫水平。

函数将会传送 2 个参数,分别是标准杆数par和挥杆次数strokes,根据下面的表格返回正确的水平段位。

StrokesReturn
1"Hole-in-one!"
<= par - 2"Eagle"
par - 1"Birdie"
par"Par"
par + 1"Bogey"
par + 2"Double Bogey"
>= par + 3"Go Home!"

parstrokes必须是数字而且是正数。

--hints--

golfScore(4, 1)应该返回 "Hole-in-one!"。

assert(golfScore(4, 1) === 'Hole-in-one!');

golfScore(4, 2)应该返回 "Eagle"。

assert(golfScore(4, 2) === 'Eagle');

golfScore(5, 2)应该返回 "Eagle"。

assert(golfScore(5, 2) === 'Eagle');

golfScore(4, 3)应该返回 "Birdie"。

assert(golfScore(4, 3) === 'Birdie');

golfScore(4, 4)应该返回 "Par"。

assert(golfScore(4, 4) === 'Par');

golfScore(1, 1)应该返回 "Hole-in-one!"。

assert(golfScore(1, 1) === 'Hole-in-one!');

golfScore(5, 5)应该返回 "Par"。

assert(golfScore(5, 5) === 'Par');

golfScore(4, 5)应该返回 "Bogey"。

assert(golfScore(4, 5) === 'Bogey');

golfScore(4, 6)应该返回 "Double Bogey"。

assert(golfScore(4, 6) === 'Double Bogey');

golfScore(4, 7)应该返回 "Go Home!"。

assert(golfScore(4, 7) === 'Go Home!');

golfScore(5, 9)应该返回 "Go Home!"。

assert(golfScore(5, 9) === 'Go Home!');

--seed--

--seed-contents--

var names = ["Hole-in-one!", "Eagle", "Birdie", "Par", "Bogey", "Double Bogey", "Go Home!"];
function golfScore(par, strokes) {
  // Only change code below this line


  return "Change Me";
  // Only change code above this line
}

golfScore(5, 4);

--solutions--

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!";
}