Learn localStorage by Building a Todo App - Step 59

Tell us what’s happening:

I’m sorry… I know this should be obvious but I can’t figure the solution to this step. So farI’ve tried

if(taskData.length === 0) {
  updateTaskContainer();
}

And

if(taskData.length !== 0) {
  updateTaskContainer();
}

but it doesn’t work…

1 Like

Hi @happyClam, thanks for your question!

Your logic is good in the second example, but you are not using the correct relational operator.

In Javascript you can check for equality/inequality in four ways:

a == b // equality operator = checks for equality ,('1' == 1) would evaluate to 'true
a === b // strict equality operator = checks for equality of data types as well, ('1' === 1) would evaluate to 'false', since '1' is a string and 1 is an integer
a != b // inequality operator = checks if the two variables are different
a !== // strict inequality operator = perceives different data types as not equal

The condition in an if statement can be represented in 2 ways - either ‘true’/‘false’ or (any number)/0, which are functionally the same.

Let’s now look at your problem. You have to run updateTaskContainer() if taskData is NOT empty.

So in your first example you’re actually running the code when taskData is empty

if(taskData.length === 0) { // evaluates to TRUE if taskData is empty
  updateTaskContainer();
}

In your second example the logic is correct, you want to run the code when taskData is empty but you’re using different logic than the task requires.

if(taskData.length !== 0) {
    updateTaskContainer();
}

You just need to provide the length in the condition and let it evaluate.

if(taskData.length) {
  updateTaskContainer();
}

Because if taskData.length is 0, that’s a false, any other value is evaluated as ‘true’.

Hope this gets you moving forward again :slight_smile:

Have a nice day!

Because 0 is a falsy value all you need for the condition is the array length.

So all you need for the condition is the array length. If it evaluates to 0 it is coerced to a falsy value.


@Jacobs322

Strict inequality !== is most definitely an operator in JS.

1 Like

Hi @lasjorg ,

thank you for the correction. I did not know that, I have edited my answer so it is not misleading for future readers :slight_smile:

Thank you both! I figured it out. Have a nice day!

1 Like

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