Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript Interactive Web Pages with JavaScript Traversing and Manipulating the DOM with JavaScript Perfect

james rochabrun
PLUS
james rochabrun
Courses Plus Student 22,726 Points

Why does something like this wont work?

Hello to everyone caan someone tell me PLEASE, why something like this doesnt work? for disable the add button if there is not input value .

// a variable that returns true or false if the taskInput.value.lenght is <= than 0

function inputLength() { return taskInput.value.length <= 0; }

//a function that changes the property calling the inputLenghth function.

function disableButton() { addButton.disabled = inputLength(); }

// call the disableButton function

disableButton();

thank you very much

Bram Dijkhuis
Bram Dijkhuis
5,746 Points

It looks like your checking whether something is true or false without using any conditional statement. Why not use something like:

function disableButton() {
  if (inputLength.value.length == 0) {
    addButton.disabled = true;
  }
}
disableButton();

You might also want to expand this a bit by adding some code to check if (on keyup perhaps) the input has received a value and then enable the button, but I don't know if that's what you're looking for.

1 Answer

james rochabrun
PLUS
james rochabrun
Courses Plus Student 22,726 Points

thanks for your answer i tried your function but still dont works , do you know why?

Bram Dijkhuis
Bram Dijkhuis
5,746 Points

Can you paste some of your code in a codepen or post more of it here (especially the html).