Can someone please help me with my code! I have tried several method but, I am still stuck.
Your help will highly be appreciated
the instruction says: " 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 includes() method and the ! operator to do this."
Your code so far
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.
function cleanInputString(str) {
const strArray = str.split('');
const cleanStrArray = [];
for (let i = 0; i < strArray.length; i++) {
if (cleanStrArray = !["+", "-", " "].includes()){
}
}
}
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) 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
It seems like you misunderstood the way .includes() works, as well as the NOT (!) operator.
As said in the exercise, the .includes() method returns True if the element in between parenthesis is part of the Array of specified elements ["+", "-", " "]. To use it, you need 2 objects:
Your array of elements
The object you want to check (here it is the character with index i in the strArray)
Now let’s make the link with the NOT operator: since .includes() returns True or False, you don’t need to use an equal sign, the correct syntax in your case will be:
if (!["+", "-", " "].includes()) { // In between the parenthesis, put whatever you need to check!
// Your action (push the item in the cleanStrArray as specified in the task)
}
This can be translated in plain english as “If not this array ["+", "-", " "] include whatever object then do this”.
I tried my best to explain as clearly as possible, I really hope it is helpful for you and do not hesitate to ask more questions if necessary.