I'm making a maze generator. 
my code is something like this:
function generate() {
    //generate one iteration of a maze
}
function createmaze() {
    interval = window.setInterval(function() {
        //create the maze by calling generate repeatedly, and some other stuff (which works!)
        if(stop condition) {
            draw(maze);
            return(maze);
            window.clearInterval(interval);
        }
    }, 0);
}
alert(createmaze());
function draw() {
    //draws maze
}
my problem is, while the draw function runs fine and draws the maze it is supposed to, but createmaze returns undefined. it wouldn't be a problem, except i need the maze for some more code that won't draw it.
edit: i know i was using setinterval wrong with 0, but somehow things still worked
 
    