Edit in JSFiddle

function sayHello(name) {
    var text = 'Hello, ' + name + '!';
    var sayAlert = function() { console.log(text); }
    sayAlert();
}

sayHello("Han Solo");