fix(curriculum): Update description for step 22 of calorie counter project (#53554)

This commit is contained in:
Zishan Panchal
2024-02-06 19:05:40 +05:30
committed by GitHub
parent 08769a144c
commit 2024104e08

View File

@@ -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*\{)?/);