Tell us what’s happening:
step 22, I don’t know what is wrong.
### Your code so far
function cleanInputString(str) {
const strArray = str.split(‘’);
const cleanStrArray = ;
for (let i = 0; i < strArray.length; i++) {
if(![“+”, “-”, " "].includes(strArray[i])) {
cleanStrArray.push(strArray[i]);
}
}
}
WARNING
The challenge seed code and/or your solution exceeded the maximum length we can port over from the challenge.
You will need to take an additional step here so the code you wrote presents in an easy to read format.
Please copy/paste all the editor code showing in the challenge from where you just linked.
Replace these two sentences with your copied code.
Please leave the ``` line above and the ``` line below,
because they allow your code to properly format in the post.
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36
Challenge Information:
Learn Form Validation by Building a Calorie Counter - Step 22
ios-man
December 21, 2023, 9:05pm
2
Hello @hungozada ! Welcome to the forum!
I just tried a similar version of your code as below, which also will not pass the tests, but logs the expected output IMHO.
function cleanInputStrings(str) {
const strArray = str.split("");
const cleanStrArray = [];
for (let i = 0; i < strArray.length; i++) {
const element = strArray[i];
if (!["+", "-", " "].includes(element)) {
cleanStrArray.push(element);
}
}
console.log("cleanStrArray:", cleanStrArray);
}
cleanInputStrings("123 +9-8"); // ["1","2","3","9","8"]
Might be a candidate for a PR?
sanity
December 21, 2023, 9:07pm
3
There appear to be error in the test, if you remove semicolon from the following line, test will pass.
cleanStrArray.push(strArray[i])
2 Likes
Thank you sanity, you are right.
1 Like
An issue has been created to update the tests
opened 09:25PM - 21 Dec 23 UTC
type: bug
help wanted
scope: curriculum
### Describe the Issue
The following valid code does not pass for [step 22](h… ttps://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures-v8/learn-form-validation-by-building-a-calorie-counter/step-22) of calorie counter project.
```js
function cleanInputString(str) {
const strArray = str.split('');
const cleanStrArray = [];
for (let i = 0; i < strArray.length; i++) {
if (!['+', '-', " "].includes(strArray[i])) {
cleanStrArray.push(strArray[i]);
}
}
}
```
The issue is with this line here
```js
cleanStrArray.push(strArray[i]);
```
If you remove the semicolon then the test will pass
We will need to fix the test to make semicolons optional so the camper can pass with or without semicolons.
here is the file you need to fix
https://github.com/freeCodeCamp/freeCodeCamp/blob/main/curriculum/challenges/english/15-javascript-algorithms-and-data-structures-22/learn-form-validation-by-building-a-calorie-counter/63bf45ce0dc8d4270760c6d0.md
Please read through the [contributing](https://github.com/freeCodeCamp/freeCodeCamp/blob/5fcff2f96782794b2b31f573f6bcaaa21f5fa59b/CONTRIBUTING.md) docs first.
And we don't assign issues.
If you are interested in working on this, work on the fix and create a PR.
Happy coding!
### Affected Page
https://www.freecodecamp.org/learn/javascript-algorithms-and-data-structures-v8/learn-form-validation-by-building-a-calorie-counter/step-22
### Your code
This code does not pass even though it is valid
```js
function cleanInputString(str) {
const strArray = str.split('');
const cleanStrArray = [];
for (let i = 0; i < strArray.length; i++) {
if (!['+', '-', " "].includes(strArray[i])) {
cleanStrArray.push(strArray[i]);
}
}
}
```
### Expected behavior
Semicolons should be optional and the code above should pass
### Screenshots
_No response_
### System
- Device: [e.g. iPhone 6, Laptop]
- OS: [e.g. iOS 14, Windows 10, Ubuntu 20.04]
- Browser: [e.g. Chrome, Safari]
- Version: [e.g. 22]
### Additional context
_No response_
2 Likes
system
Closed
June 21, 2024, 9:28am
6
This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.