Skip to content

Commit 55184e9

Browse files
Dario-DCjdwilkin4
andauthored
feat(curriculum): add gradebook app lab (freeCodeCamp#55843)
Co-authored-by: Jessica Wilkins <[email protected]>
1 parent c7a9bf3 commit 55184e9

File tree

4 files changed

+262
-1
lines changed

4 files changed

+262
-1
lines changed

client/i18n/locales/english/intro.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1927,7 +1927,10 @@
19271927
"ccnu": { "title": "175", "intro": [] },
19281928
"skiq": { "title": "176", "intro": [] },
19291929
"epfc": { "title": "177", "intro": [] },
1930-
"gsfr": { "title": "178", "intro": [] },
1930+
"lab-gradebook-app": {
1931+
"title": "Build a Gradebook App",
1932+
"intro": ["For this lab, you will create a gradebook app."]
1933+
},
19311934
"fbbn": { "title": "179", "intro": [] },
19321935
"lnmg": { "title": "180", "intro": [] },
19331936
"wead": { "title": "181", "intro": [] },
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
---
2+
title: Introduction to the Build a Gradebook App
3+
block: lab-gradebook-app
4+
superBlock: front-end-development
5+
---
6+
7+
## Introduction to the Build a Gradebook App
8+
9+
For this lab, you will create a gradebook app.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"name": "Build a Gradebook App",
3+
"blockType": "lab",
4+
"isUpcomingChange": true,
5+
"usesMultifileEditor": true,
6+
"dashedName": "lab-gradebook-app",
7+
"order": 178,
8+
"superBlock": "front-end-development",
9+
"challengeOrder": [{ "id": "66bb6a9c2dd58b73cd759034", "title": "Build a Gradebook App" }],
10+
"helpCategory": "JavaScript"
11+
}
Lines changed: 238 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,238 @@
1+
---
2+
id: 66bb6a9c2dd58b73cd759034
3+
title: Build a Gradebook App
4+
challengeType: 14
5+
dashedName: build-a-gradebook-app
6+
---
7+
8+
# --description--
9+
10+
**Objective:** Fulfill the user stories below and get all the tests to pass to complete the lab.
11+
12+
**User Stories:**
13+
14+
1. You should have a function named `getAverage` that takes an array of test scores as a parameter and returns the average score.
15+
1. You should have a function named `getGrade` that takes a student score as a parameter and returns a string representing a letter grade based on the score. Here are the scores and their corresponding letter grades:
16+
17+
| Score Range | Grade |
18+
| ----------- | ------- |
19+
| `100` | `"A+"` |
20+
| `90 - 99` | `"A"` |
21+
| `80 - 89` | `"B"` |
22+
| `70 - 79` | `"C"` |
23+
| `60 - 69` | `"D"` |
24+
| `0 - 59` | `"F"` |
25+
26+
1. You should have a function named `hasPassingGrade` that takes a score as a parameter and returns either `true` or `false` depending on if the score corresponds to a passing grade.
27+
1. The `hasPassingGrade` function should use the `getGrade` function to get the letter grade, and use it to determine if the grade is passing. A passing grade is anything different from `"F"`.
28+
1. You should have a function named `studentMsg` that takes an array of scores and a student score as the parameters. The function should return a string with the format:
29+
30+
- `"Class average: average-goes-here. Your grade: grade-goes-here. You passed the course."`, if the student passed the course.
31+
- `"Class average: average-goes-here. Your grade: grade-goes-here. You failed the course."`, if the student failed the course.
32+
33+
Replace `average-goes-here` with the average of total scores and `grade-goes-here` with the student's grade.
34+
Use `getAverage` to get the average score and `getGrade` to get the student's grade.
35+
36+
# --hints--
37+
38+
You should have a function named `getAverage`.
39+
40+
```js
41+
assert.isFunction(getAverage);
42+
```
43+
44+
Your `getAverage` function should return a number.
45+
46+
```js
47+
assert.isNumber(getAverage([92, 88, 12, 77, 57, 100, 67, 38, 97, 89]));
48+
```
49+
50+
`getAverage([92, 88, 12, 77, 57, 100, 67, 38, 97, 89])` should return `71.7`.
51+
52+
```js
53+
assert.strictEqual(getAverage([92, 88, 12, 77, 57, 100, 67, 38, 97, 89]), 71.7);
54+
```
55+
56+
`getAverage([45, 87, 98, 100, 86, 94, 67, 88, 94, 95])` should return `85.4`.
57+
58+
```js
59+
assert.strictEqual(getAverage([45, 87, 98, 100, 86, 94, 67, 88, 94, 95]), 85.4);
60+
```
61+
62+
`getAverage([38, 99, 87, 100, 100, 100, 100, 100, 100, 100])` should return `92.4`.
63+
64+
```js
65+
assert.strictEqual(getAverage([38, 99, 87, 100, 100, 100, 100, 100, 100, 100]), 92.4);
66+
```
67+
68+
Your `getAverage` function should return the average score of the test scores.
69+
70+
```js
71+
assert.strictEqual(getAverage([52, 56, 60, 65, 70, 75, 80, 85, 90, 95]), 72.8);
72+
assert.strictEqual(getAverage([45, 50, 55, 60, 65, 70, 75, 80, 85, 90]), 67.5);
73+
assert.strictEqual(getAverage([38, 42, 46, 50, 54, 58, 62, 66, 70, 74]), 56);
74+
```
75+
76+
You should have a function named `getGrade`.
77+
78+
```js
79+
assert.isFunction(getGrade);
80+
```
81+
82+
Your `getGrade` function should return `"A+"` if the score is `100`.
83+
84+
```js
85+
assert.strictEqual(getGrade(100), "A+");
86+
```
87+
88+
Your `getGrade` function should return `"A"` if the score is between `90` and `99`.
89+
90+
```js
91+
assert.strictEqual(getGrade(90), "A");
92+
assert.strictEqual(getGrade(94), "A");
93+
assert.strictEqual(getGrade(99), "A");
94+
```
95+
96+
Your `getGrade` function should return `"B"` if the score is between `80` and `89`.
97+
98+
```js
99+
assert.strictEqual(getGrade(80), "B");
100+
assert.strictEqual(getGrade(83), "B");
101+
assert.strictEqual(getGrade(88), "B");
102+
```
103+
104+
Your `getGrade` function should return `"C"` if the score is between `70` and `79`.
105+
106+
```js
107+
assert.strictEqual(getGrade(70), "C");
108+
assert.strictEqual(getGrade(75), "C");
109+
assert.strictEqual(getGrade(79), "C");
110+
```
111+
112+
Your `getGrade` function should return `"D"` if the score is between `60` and `69`.
113+
114+
```js
115+
assert.strictEqual(getGrade(60), "D");
116+
assert.strictEqual(getGrade(63), "D");
117+
assert.strictEqual(getGrade(68), "D");
118+
```
119+
120+
Your `getGrade` function should return `"F"` if the score is between `0` and `59`.
121+
122+
```js
123+
assert.strictEqual(getGrade(0), "F");
124+
assert.strictEqual(getGrade(30), "F");
125+
assert.strictEqual(getGrade(43), "F");
126+
assert.strictEqual(getGrade(59), "F");
127+
```
128+
129+
130+
You should have a function named `hasPassingGrade`.
131+
132+
```js
133+
assert.isFunction(hasPassingGrade);
134+
```
135+
136+
Your `hasPassingGrade` function should return a boolean value.
137+
138+
```js
139+
assert.isBoolean(hasPassingGrade(100));
140+
```
141+
142+
Your `hasPassingGrade` function should return `true` if the grade is an `"A"`.
143+
144+
```js
145+
assert.isTrue(hasPassingGrade(100));
146+
```
147+
148+
Your `hasPassingGrade` function should return `false` if the grade is an `"F"`.
149+
150+
```js
151+
assert.isFalse(hasPassingGrade(53));
152+
```
153+
154+
Your `hasPassingGrade` function should return `true` for all passing grades.
155+
156+
```js
157+
assert.isTrue(hasPassingGrade(87));
158+
assert.isTrue(hasPassingGrade(60));
159+
assert.isTrue(hasPassingGrade(73));
160+
assert.isTrue(hasPassingGrade(96));
161+
```
162+
163+
You should have a function named `studentMsg`.
164+
165+
```js
166+
assert.isFunction(studentMsg);
167+
```
168+
169+
Your function call of `studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37)` should return the following message: `"Class average: 71.7. Your grade: F. You failed the course."`.
170+
171+
```js
172+
assert.strictEqual(studentMsg([92, 88, 12, 77, 57, 100, 67, 38, 97, 89], 37), "Class average: 71.7. Your grade: F. You failed the course.");
173+
```
174+
175+
Your function call of `studentMsg([56, 23, 89, 42, 75, 11, 68, 34, 91, 19], 100)` should return the following message: `"Class average: 50.8. Your grade: A+. You passed the course."`.
176+
177+
```js
178+
assert.strictEqual(studentMsg([56, 23, 89, 42, 75, 11, 68, 34, 91, 19], 100), "Class average: 50.8. Your grade: A+. You passed the course.");
179+
```
180+
181+
Your `studentMsg` function should return the correct message based on the student's score and the class average.
182+
183+
```js
184+
assert.strictEqual(studentMsg([33, 44, 55, 66, 77, 88, 99, 100], 92), "Class average: 70.25. Your grade: A. You passed the course.");
185+
assert.strictEqual(studentMsg([33, 44, 55, 66, 77, 88, 99, 100], 57), "Class average: 70.25. Your grade: F. You failed the course.");
186+
```
187+
188+
189+
# --seed--
190+
191+
## --seed-contents--
192+
193+
```js
194+
195+
```
196+
197+
# --solutions--
198+
199+
```js
200+
function getAverage(scores) {
201+
let sum = 0;
202+
203+
for (const score of scores) {
204+
sum += score;
205+
}
206+
207+
return sum / scores.length;
208+
}
209+
210+
function getGrade(score) {
211+
if (score === 100) {
212+
return "A+";
213+
} else if (score >= 90) {
214+
return "A";
215+
} else if (score >= 80) {
216+
return "B";
217+
} else if (score >= 70) {
218+
return "C";
219+
} else if (score >= 60) {
220+
return "D";
221+
} else {
222+
return "F";
223+
}
224+
}
225+
226+
function hasPassingGrade(score) {
227+
return getGrade(score) !== "F";
228+
}
229+
230+
function studentMsg(totalScores, studentScore) {
231+
let average = getAverage(totalScores);
232+
let grade = getGrade(studentScore);
233+
234+
return `Class average: ${average}. Your grade: ${grade}. You ${
235+
hasPassingGrade(studentScore) ? "passed" : "failed"
236+
} the course.`;
237+
}
238+
```

0 commit comments

Comments
 (0)