3.8 KiB
Raw Blame History

id, title, challengeType, videoUrl, localeTitle
id title challengeType videoUrl localeTitle
5664820f61c48e80c9fa476c Golf Code 1 高尔夫码

Description

高尔夫比赛中,每个洞都具有par意义,即高尔夫球手为了将球沉入洞中以完成比赛所期望的平均strokes次数。根据你的strokes高出或低于par的距离,有一个不同的昵称。您的函数将通过parstrokes参数。根据此表返回正确的字符串,该表按优先级顺序列出笔划;顶部(最高)到底部(最低):
笔画返回
1 “一杆进洞!”
<= par - 2 “鹰”
par - 1 “小鸟”
平价 “相提并论”
par + 1 “柏忌”
par + 2 “双柏忌”
> = par + 3 “回家!”
parstrokes将始终为数字和正数。为方便起见,我们添加了所有名称的数组。

Instructions

Tests

tests:
  - text: '<code>golfScore(4, 1)</code>应该返回“Hole-in-one”'
    testString: 'assert(golfScore(4, 1) === "Hole-in-one!", "<code>golfScore(4, 1)</code> should return "Hole-in-one!"");'
  - text: '<code>golfScore(4, 2)</code>应该返回“Eagle”'
    testString: 'assert(golfScore(4, 2) === "Eagle", "<code>golfScore(4, 2)</code> should return "Eagle"");'
  - text: '<code>golfScore(5, 2)</code>应该返回“Eagle”'
    testString: 'assert(golfScore(5, 2) === "Eagle", "<code>golfScore(5, 2)</code> should return "Eagle"");'
  - text: '<code>golfScore(4, 3)</code>应该返回“Birdie”'
    testString: 'assert(golfScore(4, 3) === "Birdie", "<code>golfScore(4, 3)</code> should return "Birdie"");'
  - text: '<code>golfScore(4, 4)</code>应该返回“Par”'
    testString: 'assert(golfScore(4, 4) === "Par", "<code>golfScore(4, 4)</code> should return "Par"");'
  - text: '<code>golfScore(1, 1)</code>应该返回“Hole-in-one”'
    testString: 'assert(golfScore(1, 1) === "Hole-in-one!", "<code>golfScore(1, 1)</code> should return "Hole-in-one!"");'
  - text: '<code>golfScore(5, 5)</code>应该返回“Par”'
    testString: 'assert(golfScore(5, 5) === "Par", "<code>golfScore(5, 5)</code> should return "Par"");'
  - text: '<code>golfScore(4, 5)</code>应该返回“Bogey”'
    testString: 'assert(golfScore(4, 5) === "Bogey", "<code>golfScore(4, 5)</code> should return "Bogey"");'
  - text: '<code>golfScore(4, 6)</code>应该返回“Double Bogey”'
    testString: 'assert(golfScore(4, 6) === "Double Bogey", "<code>golfScore(4, 6)</code> should return "Double Bogey"");'
  - text: '<code>golfScore(4, 7)</code>应该返回“Go Home”'
    testString: 'assert(golfScore(4, 7) === "Go Home!", "<code>golfScore(4, 7)</code> should return "Go Home!"");'
  - text: '<code>golfScore(5, 9)</code>应该返回“Go Home”'
    testString: 'assert(golfScore(5, 9) === "Go Home!", "<code>golfScore(5, 9)</code> should return "Go Home!"");'

Challenge Seed

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
}

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

Solution

// solution required