mirror of
https://github.com/freeCodeCamp/freeCodeCamp.git
synced 2026-05-20 12:03:11 -04:00
fix(curriculum): Update description for step 22 of calorie counter project (#53554)
This commit is contained in:
@@ -7,24 +7,26 @@ dashedName: step-22
|
||||
|
||||
# --description--
|
||||
|
||||
Within your loop, you need to check if the character in `strArray` at index `i` is not a `+`, `-`, or a space. If it is not, `push` it to the `cleanStrArray`.
|
||||
|
||||
You will need to check if the array `["+", "-", " "]` does not include the current character. You can use a combination of the <dfn>includes()</dfn> method and the <dfn>!</dfn> operator to do this.
|
||||
|
||||
The `.includes()` method returns `true` if the array contains the character, and `false` if not. The logical NOT operator (`!`) will return the opposite of the value of the `.includes()` method.
|
||||
|
||||
Here is an example:
|
||||
Here is an example checking if the current character is not in the vowels array. If it is not, that current character is pushed into the `consonantArray`:
|
||||
|
||||
```js
|
||||
const numbersArray = [1, 2, 3, 4, 5]
|
||||
const number = 6
|
||||
const inputString = "Hello World";
|
||||
const charArray = inputString.split('');
|
||||
const consonantArray = [];
|
||||
|
||||
if (!numbersArray.includes(number)) {
|
||||
console.log("The number is not in the array.")
|
||||
for (let i = 0; i < charArray.length; i++) {
|
||||
if (!['a', 'e', 'i', 'o', 'u'].includes(charArray[i])) {
|
||||
consonantArray.push(charArray[i]);
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
Within your loop, you need to check if the character in `strArray` at index `i` is not a `+`, `-`, or a space. If it is not, `push` it to the `cleanStrArray`.
|
||||
|
||||
# --hints--
|
||||
|
||||
Your `for` loop should have an `if` statement.
|
||||
@@ -40,7 +42,7 @@ Your `for` loop should use `!["+", "-", " "].includes()`.
|
||||
assert.match(code, /for\s*\(\s*(let|var)\s+i\s*=\s*0\s*;\s*i\s*<\s*strArray\.length\s*;\s*i\s*\+\+\s*\)\s*\{\s*if\s*\(\s*!\s*\[\s*("|')\+\2\s*,\s*("|')-\3\s*,\s*("|')\s\4\s*\]\s*\.includes\(/);
|
||||
```
|
||||
|
||||
Your `for` loop should see if `strArray[i]` is found in `["+", "-", " "]`.
|
||||
Your `for` loop should see if `!["+", "-", " "].includes(strArray[i])`.
|
||||
|
||||
```js
|
||||
assert.match(code, /for\s*\(\s*(let|var)\s+i\s*=\s*0\s*;\s*i\s*<\s*strArray\.length\s*;\s*i\s*\+\+\s*\)\s*\{\s*if\s*\(\s*!\s*\[\s*("|')\+\2\s*,\s*("|')-\3\s*,\s*("|')\s\4\s*\]\s*\.includes\(\s*strArray\s*\[\s*i\s*\]\s*\)\s*\)(\s*\{)?/);
|
||||
|
||||
Reference in New Issue
Block a user