Get Programming with JavaScript - Listing 5.03
Listing 5.03 - Passing information to a function
JS Bin
var showMessage;
showMessage = function (message) {
console.log("The message is: " + message);
};
showMessage("It's full of stars!");
Further Adventures
Listing 5.03 - Passing information to a function - Task 1
- Change the message in the parentheses when showMessage is called.
var showMessage;
showMessage = function (message) {
console.log("The message is: " + message);
};
showMessage("We choose to go."); // Change the message
Listing 5.03 - Passing information to a function - Task 2
- Add two more calls to the showMessage function with different arguments each time.
var showMessage;
showMessage = function (message) {
console.log("The message is: " + message);
};
showMessage("We choose to go.");
// Call the showMessage function twice
showMessage("It's full of stars!");
showMessage("I'm going on an adventure!");
Listing 5.03 - Passing information to a function - Task 3
- Change the showMessage function itself. Make it add some extra text after the message passed in.
var showMessage;
// Change the showMessage function
showMessage = function (message) {
console.log('"' + message + '" is the message.');
};
showMessage("We choose to go.");
showMessage("It's full of stars!");
showMessage("I'm going on an adventure!");