Learn Form Validation by Building a Calorie Counter - Step 63

Tell us what’s happening:

Remember that return ends the execution of a function. After your if block, you need to handle the logic for when the input is valid. Because your if statement returns a value, you do not need an else statement.

Use the addition assignment operator to add currVal to your calories total. You’ll need to use the Number constructor to convert currVal to a number.

The Number constructor is a function that converts a value to a number. If the value cannot be converted, it returns NaN which stands for “Not a Number”.

Here is an example:

Number('10'); // returns the number 10

// running tests
You should pass currVal to the Number() constructor.
You should add the value of Number(currVal) to calories.
// tests completed

Your code so far

function getCaloriesFromInputs(list) {
let calories = 0;

for (let i = 0; i < list.length; i++) {
const currVal = cleanInputString(list[i].value);
const invalidInputMatch = isInvalidInput(currVal);

if (invalidInputMatch) {
  alert(`Invalid Input: ${invalidInputMatch[0]}`);
  isError = true;
  return null;
calories += number(currVal);


Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/ Safari/537.36 Edg/

Challenge Information:

Learn Form Validation by Building a Calorie Counter - Step 63

it’s Number(), not number()

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.