Get Programming with JavaScript - Listing 6.02
Listing 6.02 - Using an argument to determine the return value
JS Bin
var getHelloTo;
var fullMessage;
getHelloTo = function (name) {
return "Hello to " + name;
};
fullMessage = getHelloTo("Kandra");
console.log(fullMessage);
Further Adventures
Listing 6.02 - Using an argument to determine the return value - Task 1
- Change the definition of getHelloTo to accept two parameters, name1 and name2.
var getHelloTo;
var fullMessage;
getHelloTo = function (name1, name2) { // accept two parameters
return "Hello to " + name;
};
fullMessage = getHelloTo("Kandra");
console.log(fullMessage);
Listing 6.02 - Using an argument to determine the return value - Task 2
- Make the function return a string of the form "Hello to Kandra and Dax"
var getHelloTo;
var fullMessage;
getHelloTo = function (name1, name2) {
return "Hello to " + name1 + " and " + name2; // update the return value
};
fullMessage = getHelloTo("Kandra", "Dax"); // use two arguments
console.log(fullMessage);