Understanding Simple Functions

So far we have looked at reasons why we want to use functions. Now let’s see how functions work.

Remove the three logMessage lines from the code. Write the following after the var log = makeLog line.

 
logMessage(hello(​'President Obama'​), log);
 
logMessage(hello(​'Mom'​), log);
 
logMessage(hello(​'Your Name'​), log);
 
 
function​ hello(name) {
 
return​ ​'Hello, '​ + name + ​'! You look very pretty today :)'​;
 
}

The result of this hello function would be to first return the phrase “Hello, President Obama! You look very pretty today :).” Logging these phrases should look something like this:

images/functions/hello_you_are_pretty.png

There is a lot going ...

Get 3D Game Programming for Kids now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.