Hi all, please advise what am i doing wrong. It keeps telling me i shouldn’t add an else statement. I think it’s about the placement of the code. I tried so many variations. Is it not after the return statement?
currVal = Number(currVal)+=calories;
Your code so far
<!-- file: index.html -->
/* file: script.js */
// User Editable Region
function getCaloriesFromInputs(list) {
let calories = 0;
for (const item of list) {
const currVal = cleanInputString(item.value);
const invalidInputMatch = isInvalidInput(currVal);
if (invalidInputMatch) {
alert(`Invalid Input: ${invalidInputMatch[0]}`);
isError = true;
return null;
currVal = Number(currVal)+=calories;
}
}
}
// User Editable Region
/* file: styles.css */
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/129.0.0.0 Safari/537.36
Challenge Information:
Learn Form Validation by Building a Calorie Counter - Step 65
Thanks for your quick reply!
I am confused about " 1. You can’t have two assignments on the same line", because you mentioned to someone else that it should be done on the same line.
I have tried like this:
‘’‘’‘’‘’‘’‘’
if (invalidInputMatch) {
alert(Invalid Input: ${invalidInputMatch[0]});
isError = true;
currVal=Number(currVal);
calories += currVal;
return null;
}
‘’‘’‘’‘’‘’‘’‘’’
and also like this, but it still says: " 2. After your if statement, you should use the addition assignment operator on calories ."
‘’‘’‘’‘’‘’‘’‘’‘’‘’
if (invalidInputMatch) {
alert(Invalid Input: ${invalidInputMatch[0]});
isError = true;
calories += Number(currVal);
return null;
}
if (invalidInputMatch) {
alert(`Invalid Input: ${invalidInputMatch[0]}`);
isError = true;
calories += Number(currVal);
return null;
}
// here is after the if
I am taking your code and adding a comment after the if to show where that is, because it doesn’t look like it is clear to you, after the if is not inside the if.
this is much better, but you need to put it in the right place