Build a Todo App using Local Storage - Step 34

Tell us what’s happening:

Hey, I am stuck on step 34 of the todo-app workshop. It asks write some logic so that a modal is shown if either titleInput, dateInput, or descriptionInput have a value.

I am failing on the following test:

If any of the input fields has a value, then the confirmation dialog should display. Otherwise, the reset function should be called.

I have tried both

closeTaskFormBtn.addEventListener("click", () => {
  if ( titleInput.value.length > 0 || dateInput.value.length > 0  || description.value.length > 0 ) {
    confirmCloseDialog.showModal()
  } else {
    reset()
  };
  
});

as well as

closeTaskFormBtn.addEventListener("click", () => {
  if ( titleInput.value !== "" || dateInput.value !== "" || description.value !== "") {
    confirmCloseDialog.showModal()
  } else {
    reset()
  };
  
});

Thank you!

Your code so far

<!-- file: index.html -->

/* file: styles.css */

/* file: script.js */
// User Editable Region

closeTaskFormBtn.addEventListener("click", () => {
  if ( titleInput.value.length > 0 || dateInput.value.length > 0  || description.value.length > 0 ) {
    confirmCloseDialog.showModal()
  } else {
    reset()
  };
  
});

// User Editable Region

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:146.0) Gecko/20100101 Firefox/146.0

Challenge Information:

Build a Todo App using Local Storage - Step 34

Hi,
I recently joined the forum, literally a few minutes ago and I was curious.
I saw your case and the requirement was:
write some logic to check if there is a value in the titleInput, dateInput or the descriptionInput field.

Solution hint:
Try another way to check if any of the values is actually empty.

You don’t need to compare against an empty string.
You can rely on the truthy/falsy behavior of values.

For example, this checks whether a variable actually has content:
if (variable) {
doSomething();
}
and it calls the doSomething() function.

while this code snippet checks whether it doesn’t contain a real value:
if (!variable) {
doSomething();
}

Have a nice day!

3 Likes

This worked, thanks a lot!

1 Like