Challenge for Functions, Scope and Closures


You found a mysterious piece of convoluted code that calculates and prints theAnswer. What will it print?

universe = 1;  //global variable

function getEverything(){
    var life = 22; //declared in function
    return life;

function doubleUniverse(){
    universe = universe * 2;

//double universe 4 times
for(var life=0; life<4; life++){  

var everything = getEverything();
var theAnswer = life + universe + everything;

Please sign in or sign up to submit answers.

Alternatively, you can try out Learneroo before signing up.

Contact Us
Sign in or email us at [email protected]