Q:

jQuery var not entering function

I need an element to toggle when I press menu-toggle, then when I press anywhere on the page (on the wrapper element), I need it to toggle again.
This is my code:
var bodyclick = 0;
console.log(bodyclick);

//If you clicks the menu toggle, then activate toggle and bodyclick should be 1
$("#menu-toggle").click(function(e) {
    e.preventDefault();
    $("#wrapper").toggleClass("toggled");
    bodyclick = 1;
    console.log(bodyclick);
});

//Now, that the bodyclick is 1, user should click anywhere on the wrapper to activate the toggle again
if (bodyclick === 1) {
    console.log("The wrapper is toggled");
    $("#wrapper").click(function(e) {
        //e.preventDefault();
        $("#wrapper").toggleClass("toggled");
        bodyclick = 0;
    });
}

When the user clicks on the #menu-toggle element, the wrapper should toggle and the bodyclick var should be 1. 
Now the second function should work. If the user clicks ANYWHERE on the #wrapper, it should toggle it again and change the bodyclick back to 0.
This is not working for some reason. It won't start the if statement. The console log shows bodyclick is 1, but the if is not working.
I tried using == but it doesn't change anything. Why isn't the if working?
EDIT
After adding @Nikhil Aggarwal answer:
var bodyclick = 0;
console.log(bodyclick);

$("#menu-toggle").click(function (e) {
    e.preventDefault();
    $("#wrapper").toggleClass("toggled");
    bodyclick = 1;
    console.log(bodyclick);
});

$("#wrapper").click(function(e) {
    if (bodyclick === 1) {
        console.log("The wrapper is toggled");
       //e.preventDefault();
       $("#wrapper").toggleClass("toggled");
       bodyclick = 0; 
    }
});

The toggle works on #menu-toggle, it even sets the bodyclick to 1.
But when I click anywhere on the wrapper now (after the toggle on #menu-toggle), it won't toggle the element or change the bodyclick value back to zero.
I apologize for this but I just don't see the logic.
FIXED, thanks to @Nikhil Aggarwal:
Just needed to add the e.stopPropagation(); in the #menu-toggle function.

A:

Update your code to following
$("#wrapper").click(function(e) {
    if (bodyclick === 1) {
        console.log("The wrapper is toggled");
       //e.preventDefault();
       $("#wrapper").toggleClass("toggled");
       bodyclick = 0; 
    }
});

Reason - At the time of load, value of bodyclick was 0, hence, the if condition was never executed which also means the binding never happened. Hence, you should move the condition inside the event handler so that event handler exists at the time of load and is executed conditionally as required.

