Get Programming with JavaScript - Listing 5.02
Listing 5.02 - Breaking a function by changing a variable name
JS Bin
var msg;
var showMessage;
msg = "It's full of stars!";
showMessage = function () {
console.log(message);
};
showMessage();
Further Adventures
Listing 5.02 - Breaking a function by changing a variable name - Task 1
- Update the console.log so the program works.
var msg;
var showMessage;
msg = "It's full of stars!";
showMessage = function () {
console.log(msg); // Use the correct variable
};
showMessage();
Listing 5.02 - Breaking a function by changing a variable name - Tasks 2 & 3
- Declare another message variable and assign it a value.
- Display the new message as well as the old one.
var msg;
var msg2; // Declare a variable
var showMessage;
msg = "It's full of stars!";
msg2 = "We choose to go."; // Assign a value
showMessage = function () {
console.log(msg);
console.log(msg2); // Display the new message
};
showMessage();
Listing 5.02 - Breaking a function by changing a variable name - Task 4
- Display a single message created by joining the two strings.
var msg;
var msg2;
var showMessage;
msg = "It's full of stars!";
msg2 = "We choose to go.";
showMessage = function () {
console.log(msg + " " + msg2); // Display a single message
};
showMessage();