mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-09-24 23:01:18 +08:00
fix(curriculum): minor improvements to Calculator Workshop (#56600)
This commit is contained in:
-1
@@ -27,7 +27,6 @@ Start by creating a function called `addTwoAndSeven`.
|
||||
|
||||
You can choose to use the regular function syntax or the arrow function syntax.
|
||||
|
||||
|
||||
# --hints--
|
||||
|
||||
You should declare a function called `addTwoAndSeven`.
|
||||
|
||||
+2
-2
@@ -13,7 +13,7 @@ Here is a reminder of how to return a value from a function:
|
||||
|
||||
```js
|
||||
function myFunction() {
|
||||
return 'Hello World';
|
||||
return "Hello World";
|
||||
}
|
||||
```
|
||||
|
||||
@@ -21,7 +21,7 @@ Inside your `addTwoAndSeven` function, return the sum of `2` and `7`.
|
||||
|
||||
# --hints--
|
||||
|
||||
Your `addTwoAndSeven` function should return the sum of `2` and `7`
|
||||
Your `addTwoAndSeven` function should return the sum of `2` and `7`.
|
||||
|
||||
```js
|
||||
assert.strictEqual(addTwoAndSeven(), 9);
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ dashedName: step-3
|
||||
|
||||
# --description--
|
||||
|
||||
In the previous lecture videos, you learned how to call(invoke) a function. Calling a function means to execute the code inside the function.
|
||||
In the previous lecture videos, you learned how to call (invoke) a function. Calling a function means to execute the code inside the function.
|
||||
|
||||
Here is a reminder of how to call a function:
|
||||
|
||||
|
||||
+1
-1
@@ -14,7 +14,7 @@ A function parameter is a variable that is defined in the function's declaration
|
||||
Here is an example of a function that has a parameter:
|
||||
|
||||
```js
|
||||
// The parameter is 'name'
|
||||
// The parameter is `name`
|
||||
function greetUser(name) {
|
||||
return `Hello, ${name}!`;
|
||||
}
|
||||
|
||||
+2
-2
@@ -18,8 +18,8 @@ function greetUser(name) {
|
||||
}
|
||||
|
||||
// function calls
|
||||
greetUser('John'); // 'Hello John!'
|
||||
greetUser('Jane'); // 'Hello Jane!'
|
||||
greetUser("John"); // "Hello John!"
|
||||
greetUser("Jane"); // "Hello Jane!"
|
||||
```
|
||||
|
||||
Add a `console.log` that calls the `calculateSum` function with the arguments `2` and `5`.
|
||||
|
||||
+1
-1
@@ -7,7 +7,7 @@ dashedName: step-14
|
||||
|
||||
# --description--
|
||||
|
||||
Your `calculateQuotient` appears to working correctly but there is one case that you have not tested yet.
|
||||
Your `calculateQuotient` appears to be working correctly but there is one case that you have not tested yet.
|
||||
|
||||
Add a `console.log` that calls the `calculateQuotient` function with the arguments `3` and `0`.
|
||||
|
||||
|
||||
+2
-2
@@ -13,11 +13,11 @@ The division by zero is not a valid operation in mathematics.
|
||||
|
||||
To account for this edge case, you should update your `calculateQuotient` function to instead check if `num2` is zero.
|
||||
|
||||
If it is, the function should return the string `'Error: Division by zero'`. Otherwise, it should return the result of dividing `num1` by `num2`.
|
||||
If it is, the function should return the string `"Error: Division by zero"`. Otherwise, it should return the result of dividing `num1` by `num2`.
|
||||
|
||||
# --hints--
|
||||
|
||||
Your `calculateQuotient` function should return the string `'Error: Division by zero'` if `num2` is zero.
|
||||
Your `calculateQuotient` function should return the string `"Error: Division by zero"` if `num2` is zero.
|
||||
|
||||
```js
|
||||
assert.strictEqual(calculateQuotient(10, 0), 'Error: Division by zero');
|
||||
|
||||
-1
@@ -20,7 +20,6 @@ Here is an example:
|
||||
// the exponent is 2
|
||||
Math.pow(5, 2); // 25
|
||||
|
||||
|
||||
// using the exponentiation operator
|
||||
5 ** 2; // 25
|
||||
```
|
||||
|
||||
Reference in New Issue
Block a user