Skip to content

Commit 370061a

Browse files
jdwilkin4Sembauke
andauthored
feat(curriculum): add functions calculator workshop (freeCodeCamp#55949)
Co-authored-by: Sem Bauke <[email protected]>
1 parent a90e84b commit 370061a

22 files changed

+1296
-1
lines changed

client/i18n/locales/english/intro.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1929,7 +1929,12 @@
19291929
"wjzt": { "title": "149", "intro": [] },
19301930
"tsdq": { "title": "150", "intro": [] },
19311931
"kkix": { "title": "151", "intro": [] },
1932-
"icxa": { "title": "152", "intro": [] },
1932+
"workshop-calculator": {
1933+
"title": "Build a Calculator",
1934+
"intro": [
1935+
"In this workshop, you will review working with functions by building a calculator."
1936+
]
1937+
},
19331938
"hqba": { "title": "153", "intro": [] },
19341939
"nnqa": { "title": "154", "intro": [] },
19351940
"cktz": { "title": "155", "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 Calculator
3+
block: workshop-calculator
4+
superBlock: front-end-development
5+
---
6+
7+
## Introduction to the Build a Calculator
8+
9+
This is a test for the new project-based curriculum.
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
{
2+
"name": "Build a Calculator",
3+
"blockType": "workshop",
4+
"isUpcomingChange": true,
5+
"usesMultifileEditor": true,
6+
"hasEditableBoundaries": true,
7+
"dashedName": "workshop-calculator",
8+
"order": 152,
9+
"superBlock": "front-end-development",
10+
"challengeOrder": [
11+
{
12+
"id": "66cc06012e46aa6bc9b8c001",
13+
"title": "Step 1"
14+
},
15+
{
16+
"id": "66cc095dfe1682753d2ab030",
17+
"title": "Step 2"
18+
},
19+
{
20+
"id": "66cc0a9e06e00b75d6782be9",
21+
"title": "Step 3"
22+
},
23+
{
24+
"id": "66cc0ba5881acb7692cfc4de",
25+
"title": "Step 4"
26+
},
27+
{
28+
"id": "66cc0de2920bec775f610424",
29+
"title": "Step 5"
30+
},
31+
{
32+
"id": "66cc0f1ae40802781b2ea972",
33+
"title": "Step 6"
34+
},
35+
{
36+
"id": "66cc10958d72e57907f898b2",
37+
"title": "Step 7"
38+
},
39+
{
40+
"id": "66cc12fa504b0479dac479a0",
41+
"title": "Step 8"
42+
},
43+
{
44+
"id": "66cdf76685e4cb5a8726e27b",
45+
"title": "Step 9"
46+
},
47+
{
48+
"id": "66cc14ca14e65e7a9ebecb80",
49+
"title": "Step 10"
50+
},
51+
{
52+
"id": "66cc16abc30b367ba1d1f9ef",
53+
"title": "Step 11"
54+
},
55+
{
56+
"id": "66cc172af7159a7c67804544",
57+
"title": "Step 12"
58+
},
59+
{
60+
"id": "66cc1a3a39aef47d6473cb2f",
61+
"title": "Step 13"
62+
},
63+
{
64+
"id": "66cc1ccfefdd727e18c2ab20",
65+
"title": "Step 14"
66+
},
67+
{
68+
"id": "66cc1deb1f04647f2aabee2b",
69+
"title": "Step 15"
70+
},
71+
{
72+
"id": "66cc21d23238dc8240a8a182",
73+
"title": "Step 16"
74+
},
75+
{
76+
"id": "66cc26907ff6908402af0149",
77+
"title": "Step 17"
78+
},
79+
{
80+
"id": "66cc2739f687e484d50bb6f1",
81+
"title": "Step 18"
82+
},
83+
{
84+
"id": "66cc281d687975858049fd8d",
85+
"title": "Step 19"
86+
}
87+
],
88+
"helpCategory": "JavaScript"
89+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
id: 66cc06012e46aa6bc9b8c001
3+
title: Step 1
4+
challengeType: 1
5+
dashedName: step-1
6+
---
7+
8+
# --description--
9+
10+
In this workshop, you will review how to work with functions by building a calculator app.
11+
12+
In the previous lecture videos, you learned how to declare functions like this:
13+
14+
```js
15+
// regular function
16+
function myFunction(){
17+
18+
}
19+
20+
// arrow function
21+
const myArrowFunction = () => {
22+
23+
}
24+
```
25+
26+
Start by creating a function called `addTwoAndSeven`.
27+
28+
You can choose to use the regular function syntax or the arrow function syntax.
29+
30+
31+
# --hints--
32+
33+
You should declare a function called `addTwoAndSeven`.
34+
35+
```js
36+
assert.isFunction(addTwoAndSeven);
37+
```
38+
39+
# --seed--
40+
41+
## --seed-contents--
42+
43+
```js
44+
--fcc-editable-region--
45+
46+
--fcc-editable-region--
47+
```
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
---
2+
id: 66cc095dfe1682753d2ab030
3+
title: Step 2
4+
challengeType: 1
5+
dashedName: step-2
6+
---
7+
8+
# --description--
9+
10+
One of concepts you learned in the previous lecture videos was how to return values from a function.
11+
12+
Here is a reminder of how to return a value from a function:
13+
14+
```js
15+
function myFunction(){
16+
return 'Hello World';
17+
}
18+
```
19+
20+
Inside your `addTwoAndSeven` function, return the sum of `2` and `7`.
21+
22+
# --hints--
23+
24+
Your `addTwoAndSeven` function should return the sum of `2` and `7`
25+
26+
```js
27+
assert.strictEqual(addTwoAndSeven(), 9);
28+
```
29+
30+
# --seed--
31+
32+
## --seed-contents--
33+
34+
```js
35+
--fcc-editable-region--
36+
function addTwoAndSeven() {
37+
38+
}
39+
--fcc-editable-region--
40+
```
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
---
2+
id: 66cc0a9e06e00b75d6782be9
3+
title: Step 3
4+
challengeType: 1
5+
dashedName: step-3
6+
---
7+
8+
# --description--
9+
10+
In the previous lecture videos, you learned how to call(invoke) a function. Calling a function means to execute the code inside the function.
11+
12+
Here is a reminder of how to call a function:
13+
14+
```js
15+
function myFunction(){
16+
return 'Hello World';
17+
}
18+
19+
// function call
20+
myFunction();
21+
```
22+
23+
Add a `console.log` statement, and inside it, call the `addTwoAndSeven` function.
24+
25+
You should now see the sum of `2` and `7` logged to the console.
26+
27+
# --hints--
28+
29+
You should have a `console.log` in your code.
30+
31+
```js
32+
assert.match(code, /console\.log(.*)/);
33+
```
34+
35+
You should call the `addTwoAndSeven` function inside the `console.log`.
36+
37+
```js
38+
assert.match(code, /console\.log\(\s*addTwoAndSeven\(\s*\)\s*\)/);
39+
```
40+
41+
# --seed--
42+
43+
## --seed-contents--
44+
45+
```js
46+
function addTwoAndSeven() {
47+
return 2 + 7;
48+
}
49+
--fcc-editable-region--
50+
51+
--fcc-editable-region--
52+
```
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
id: 66cc0ba5881acb7692cfc4de
3+
title: Step 4
4+
challengeType: 1
5+
dashedName: step-4
6+
---
7+
8+
# --description--
9+
10+
Now, it is time to add another function.
11+
12+
Declare a function called `addThreeAndFour` that returns the sum of `3` and `4`.
13+
14+
Then call the `addThreeAndFour` function inside a `console.log` to see the result.
15+
16+
# --hints--
17+
18+
You should declare a function called `addThreeAndFour`.
19+
20+
```js
21+
assert.isFunction(addThreeAndFour);
22+
```
23+
24+
Your `addThreeAndFour` function should return the sum of `3` and `4`.
25+
26+
```js
27+
assert.equal(addThreeAndFour(), 7);
28+
```
29+
30+
You should call the `addThreeAndFour` function inside a `console.log`.
31+
32+
```js
33+
assert.match(code, /console\.log\(\s*addThreeAndFour\(\s*\)\s*\)/);
34+
```
35+
36+
# --seed--
37+
38+
## --seed-contents--
39+
40+
```js
41+
function addTwoAndSeven() {
42+
return 2 + 7;
43+
}
44+
45+
console.log(addTwoAndSeven());
46+
--fcc-editable-region--
47+
48+
--fcc-editable-region--
49+
```
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
---
2+
id: 66cc0de2920bec775f610424
3+
title: Step 5
4+
challengeType: 1
5+
dashedName: step-5
6+
---
7+
8+
# --description--
9+
10+
Even though the functions work as expected, there is a lot of repetition in your code.
11+
12+
Since you are building a calculator, you don't want to have to create a function for every possible combination of numbers you want to add together.
13+
14+
It would be better to create a single reusable function that can add any two numbers together.
15+
16+
Remove all of the code you have written so far.
17+
18+
In the next step, you will review how to work with parameters and arguments in functions.
19+
20+
# --hints--
21+
22+
You should not have a function called `addTwoAndSeven`.
23+
24+
```js
25+
assert.notMatch(code, /function\s+addTwoAndSeven\s*\(\s*\)\s*{/);
26+
```
27+
28+
You should not have a function call to `addTwoAndSeven`.
29+
30+
```js
31+
assert.notMatch(code, /console\.log\(\s*addTwoAndSeven\(\s*\)\s*\)/);
32+
```
33+
34+
You should not have a function called `addThreeAndFour`.
35+
36+
```js
37+
assert.notMatch(code, /function\s+addThreeAndFour\s*\(\s*\)\s*{/);
38+
```
39+
40+
You should not have a function call to `addThreeAndFour`.
41+
42+
```js
43+
assert.notMatch(code, /console\.log\(\s*addThreeAndFour\(\s*\)\s*\)/);
44+
```
45+
46+
# --seed--
47+
48+
## --seed-contents--
49+
50+
```js
51+
--fcc-editable-region--
52+
function addTwoAndSeven() {
53+
return 2 + 7;
54+
}
55+
56+
console.log(addTwoAndSeven());
57+
58+
function addThreeAndFour() {
59+
return 3 + 4;
60+
}
61+
62+
console.log(addThreeAndFour());
63+
--fcc-editable-region--
64+
```

0 commit comments

Comments
 (0)