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
Joshua Bowden
Full Stack JavaScript Techdegree Graduate 29,312 PointsAdding a class if my variable is false!
Currently, I have my variable isValid - true; but when I trigger a false response that I have proven and I use the code if(isValid = false); { .addClass("false") doesn't apply.
1 Answer
Nick Trabue
Courses Plus Student 12,666 PointsBased on what you're describing your code looks like this?
if(isValid = false); { .addClass("false")
A couple of things wrong with this. You don't want a semicolon after the if condition. You can also short-hand this a little bit.
if(!isValid){
}
The second thing you need to do is specify the element that you're adding a class to.
if(!isValid){
element.addClass("false")
}
Andrew Young
Courses Plus Student 639 PointsAndrew Young
Courses Plus Student 639 PointsHi Josh would you be likely to add your code or create a workspace and take a snapshot so we know what's your code and what you want to achieve and what part of code is causing your issue thanks :)