feat(curriculum): add golf code lab (#61837)

Co-authored-by: Ilenia <26656284+ilenia-magoni@users.noreply.github.com>
Co-authored-by: Kolade Chris <65571316+Ksound22@users.noreply.github.com>
This commit is contained in:
Anna
2025-08-19 07:26:15 -04:00
committed by GitHub
parent a33bc0b4b5
commit 28eb50b2d1
5 changed files with 185 additions and 0 deletions
+6
View File
@@ -4751,6 +4751,12 @@
"title": "Certified Full Stack Developer Exam",
"intro": ["Pass this exam to become a Certified Full Stack Developer."]
},
"lab-golf-score-translator": {
"title": "Build a Golf Score Translator",
"intro": [
"For this lab, you will use array methods to translate golf scores into their nickname."
]
},
"lab-record-collection": {
"title": "Build a Record Collection",
"intro": [
@@ -0,0 +1,9 @@
---
title: Introduction to the Build a Golf Score Translator
block: lab-golf-score-translator
superBlock: full-stack-developer
---
## Introduction to the Build a Golf Score Translator
For this lab, you will use array methods to translate golf pars and strokes into their nicknames.
@@ -0,0 +1,11 @@
{
"name": "Build a Golf Score Translator",
"isUpcomingChange": false,
"dashedName": "lab-golf-score-translator",
"superBlock": "full-stack-developer",
"helpCategory": "JavaScript",
"challengeOrder": [{ "id": "689f7996426c1534fa5bea66", "title": "Build a Golf Score Translator" }],
"blockType": "lab",
"blockLayout": "link",
"usesMultifileEditor": true
}
@@ -0,0 +1,156 @@
---
id: 689f7996426c1534fa5bea66
title: Build a Golf Score Translator
challengeType: 26
dashedName: build-a-golf-score-translator
---
# --description--
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 the hole to complete the play. Depending on how far above or below `par` your `strokes` are, there is a different nickname.
In this lab, you will write a function that converts the `par` and `strokes` to their nickname.
**Objective:** Fulfill the user stories below and get all the tests to pass to complete the lab.
**User Stories:**
1. You should create a function named `golfScore`.
1. `golfScore` should take two numeric arguments, which are the par for the course and the amount of strokes made
1. `golfScore` should return a string.
1. `golfScore` should `"Hole-in-one!"` if `strokes` is `1`.
1. `golfScore` should return `"Eagle"` if `strokes` is less than or equal to `par` minus `2`.
1. `golfScore` should return `"Birdie"` if `strokes` is equal to `par` minus `1`.
1. `golfScore` should return `"Par"` if `strokes` is equal to `par`
1. `golfScore` should return `"Bogey"` if `strokes` is equal to `par` plus `1`.
1. `golfScore` should return `"Double Bogey"` if `strokes` is equal to `par` plus `2`.
1. `golfScore` should return `"Go Home!"` if `strokes` is greater than `par` plus `3`.
# --hints--
You should create a function named `golfScore`.
```js
assert.isFunction(golfScore);
```
`golfScore` should take two parameters.
```js
assert.lengthOf(golfScore, 2);
```
`golfScore` should return a string
```js
assert.isString(golfScore(4,1));
```
`golfScore(4, 1)` should return the string `Hole-in-one!`
```js
assert.strictEqual(golfScore(4,1), 'Hole-in-one!');
```
`golfScore(4, 2)` should return the string `Eagle`
```js
assert.strictEqual(golfScore(4,2), 'Eagle');
```
`golfScore(5, 2)` should return the string `Eagle`
```js
assert.strictEqual(golfScore(5,2), 'Eagle');
```
`golfScore(4, 3)` should return the string `Birdie`
```js
assert.strictEqual(golfScore(4,3), 'Birdie');
```
`golfScore(4, 4)` should return the string `Par`
```js
assert.strictEqual(golfScore(4,4), 'Par');
```
`golfScore(1, 1)` should return the string `Hole-in-one!`
```js
assert.strictEqual(golfScore(1,1), 'Hole-in-one!');
```
`golfScore(5, 5)` should return the string `Par`
```js
assert.strictEqual(golfScore(5,5), 'Par');
```
`golfScore(4, 5)` should return the string `Bogey`
```js
assert.strictEqual(golfScore(4,5), 'Bogey');
```
`golfScore(4, 6)` should return the string `Double Bogey`
```js
assert.strictEqual(golfScore(4,6), 'Double Bogey');
```
`golfScore(4, 7)` should return the string `Go Home!`
```js
assert.strictEqual(golfScore(4,7), 'Go Home!');
```
`golfScore(5, 9)` should return the string `Go Home!`
```js
assert.strictEqual(golfScore(5,9), 'Go Home!');
```
# --seed--
## --seed-contents--
```js
const names = ["Hole-in-one!", "Eagle", "Birdie", "Par", "Bogey", "Double Bogey", "Go Home!"];
```
# --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!";
}
```
@@ -689,6 +689,9 @@
{
"dashedName": "lab-lunch-picker-program"
},
{
"dashedName": "lab-golf-score-translator"
},
{
"dashedName": "lab-reverse-a-string"
},