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 Build an Interactive Website Form Validation and Manipulation Modifying Attributes

geoffrey
geoffrey
28,736 Points

requiredFilledIn() true !?

Hello there is something I don't fully understand with this piece of code taken from "build an interactive website". It's about the requiredFilledIn() function as stated in the title.

Inside this function, there is a little check if(true)... disable the submit button. That's ok, nothing difficult.

This function is then called as well at the end of the page, this way, once the page is loaded, the function is called and the checking is done.

Thus, the submit button is disabled, because It seems to be "true".

But what I don't get is, what's "true" ? As there is no comparison or anything else... How could it be "true" ? For me, there is no true or false value at this stage, at least in my mind.

Shall I consider that, as there is nothing, no testing with the if, the result will be automatically true ? And so in this case the submit button is disabled as the code gets executed ?

Same with the keyup event, where we call the requireFilledIn() function ?

 var $submit = $(".submit input");

        function requiredFilledIn(){

             if(true){
                 $submit.attr("disabled","disabled");
             }
             else
             {
                $submit.removeAttr("disabled");
             }
        };

        $("#form span").hide();

        $("input, textarea").focus(function(){
            $(this).next().fadeIn("slow");
        })
        .blur(function(){
           $(this).next().fadeOut("slow"); 
        })
        .keyup(function(){
            //Check all required fields.
            requiredFilledIn();
        });

        // CHECK IF EMAIL ADRESS IS CORRECT

        $("#email").keyup(function(){
            if(false){
                $(this).next().removeClass("error").addClass("valid");

            }
            else
            {
                $(this).next().removeClass("valid").addClass("error");            


            }
        });

        requiredFilledIn(); 

    ```

2 Answers

Kazimierz Matan
Kazimierz Matan
13,257 Points

In this situation "true" is always boolean True and "false" is always a boolean False.

"Shall I consider that, as there is nothing, no testing with the if, the result will be automatically true ? And so in this case the submit button is disabled as the code gets executed ?" - yes, you are right.

geoffrey
geoffrey
28,736 Points

Thank you for your answer.