Get Programming with JavaScript - Listing 6.03

Listing 6.03 - Using the return value as an argument

var getHelloTo; getHelloTo = function (name) { return "Hello to " + name; }; console.log(getHelloTo("Kandra")); console.log(getHelloTo("Dax"));

Further Adventures

Listing 6.03 - Using the return value as an argument - Task 1

var getHelloTo; getHelloTo = function (name) { var template; // declare a variable return "Hello to " + name; }; console.log(getHelloTo("Kandra")); console.log(getHelloTo("Dax"));

Listing 6.03 - Using the return value as an argument - Task 2

var getHelloTo; getHelloTo = function (name) { var template; template = "Hello to {{name}}"; // assign a value return "Hello to " + name; }; console.log(getHelloTo("Kandra")); console.log(getHelloTo("Dax"));

Listing 6.03 - Using the return value as an argument - Task 3

var getHelloTo; getHelloTo = function (name) { var template; template = "Hello to {{name}}"; // replace the placeholder template = template.replace("{{name}}", name); return "Hello to " + name; }; console.log(getHelloTo("Kandra")); console.log(getHelloTo("Dax"));

Listing 6.03 - Using the return value as an argument - Task 4

var getHelloTo; getHelloTo = function (name) { var template; template = "Hello to {{name}}"; template = template.replace("{{name}}", name); return template; // return the filled template }; console.log(getHelloTo("Kandra")); console.log(getHelloTo("Dax"));