Last active
December 21, 2017 18:44
-
-
Save rayinla/438cabe1f531c9ec5041dab936633198 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function sayMyName(firstName, middleName, lastName){ | |
var praiseList = ["beautiful", "awesome", "splendid", "fantastic", "jaw-dropping"]; | |
//this first closure called combineName() has access to the parameters | |
//of the outer function and its variable | |
function combineName(){ | |
var min = 0; | |
var max = praiseList.length - 1; | |
//this second getRandomInt() closure has access to the variables in combineName() | |
function getRandomInt(){ | |
return Math.floor(Math.random() * (max - min) + min); | |
} | |
return "Your" + " " + praiseList[getRandomInt()] + " name is " + firstName + " " + middleName + " " + lastName; | |
} | |
return combineName(); | |
} | |
sayMyName("Beyonce", "Giselle", "Knowles-Carter"); // Your beautiful/awesome/splendid... name is Beyonce Giselle Knowles-Carter |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment