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 trialJessica Moszkowicz
3,112 PointsCheck for legal input
How would I add a check to app.js that would alert the user if they enter something in myTextInput.value that isn't a color? I tried adding a function that would return the inputted color if it is a color and null if it isn't, but it isn't working as expected. Here is my event listener and the checkColor function:
myButton.addEventListener('click', () => { myHeading.style.color = checkColor(myTextInput.value) });
function checkColor(strColor){ var s = new Option().style; s.color = strColor.toLowerCase; if (s.color == strColor) { return strColor; } else { alert("Please input a color."); return null; } }
1 Answer
Steven Parker
231,270 PointsWhen you invoke a function (like "toLowerCase"), you need to add parentheses after the name even when no arguments are being passed.
And don't forget to convert case for the comparison also, or you may get a "false negative".