Question: So I have a javascript function that basically calls another function. This other function returns true or false and then I have an if statement however the function does not wait for the value to be returned it just keeps plowing through the code. What is the solution around this?

So my first function has:

```
confirmmation = show_confirmation("<some text>", "245px");
    if (confirmmation) {
       return true;
    }
    else {
       return false;
    }

```

and that calls:

```
function show_confirmation(message, height) {
        var contentPosition = $('.content').position();
        var contentHeight = $('.content').height();
        var bottomPosition = contentPosition.top + contentHeight;
        $('.confirmBox').css("top", (bottomPosition - ($('.confirmBox').outerHeight()+100)) + "px");
        $('.confirmBox').css("left", (($('.content').width() - $('.confirmBox').outerWidth()) / 2) + $('.content').scrollLeft() + "px");
        $('.confirmBox').css("height", height);
        $('.confirmBox .confirmationMessage').html(message)
        $('.confirmBox').css("display", "block");

        $('#yesButton').click(function (e) {
            e.preventDefault();
            $('.confirmBox').hide("slow");
            return true;
        });
        $('#noButton').click(function (e) {
            e.preventDefault();
            $('.confirmBox').hide("slow");       
            return false;
        });
    }

```

Answer: 
You should use a callback:

```
function show_confirmation(message, height, callback) {
    // ...

    $('#yesButton').click(function (e) {
        e.preventDefault();
        $('.confirmBox').hide("slow");
        callback(true);
    });
    $('#noButton').click(function (e) {
        e.preventDefault();
        $('.confirmBox').hide("slow");
        callback(false);
    });
}

show_confirmation("<some text>", "245px", function(confirmation) {
    if (confirmation) {
        // yes button clicked
    }
    else {
        // no button clicked
    }
});

```
The solution is to use callbacks. You can't feasibly have a blocking function in a browser.

Have your show\_confirmation function take in a function argument that gets called with the return value.