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

My conditional statement goes straight to 'Else'

I have an input bar where if I write 'hello' inside of it, when I hit the button, I want it to turn the button text color to red, but it just goes straight to my else statement.

Heres my JS code:

const button = document.querySelector('button'); const input = document.querySelector('#input');

button.addEventListener('click', () => { if (input === 'hello') { button.style.color = 'red'; } else { alert('thats not valid'); } }

1 Answer

Hi Obe,

You’re currently checking if input is equal to a string in your if condition. But input will be a node.

I think what you want to check is if input.textContent === “hello”.

Try making that change to see if things work out better for you.

Yes! I actually added 'input.value' and than fixed not for me. I stopped coding for 5 days and I already forgot the basics lol. Thank you

Right. input.valué. Nice job fixing your bug. 👍🏾