Get Programming with JavaScript - Listing 6.01
Listing 6.01 - Returning a value from a function
var getMessage;
var response;
getMessage = function () {
return "I’m going on an adventure!";
};
response = getMessage();
console.log(response);
Further Adventures
Listing 6.01 - Returning a value from a function - Task 1
- Write a getMyMessage function that returns a message of your choosing.
var getMessage;
var getMyMessage; // declare a variable
var response;
getMessage = function () {
return "I’m going on an adventure!";
};
// define a function and
// assign it to your variable
getMyMessage = function () {
return "Wassup!";
};
response = getMessage();
console.log(response);
You can add code to test your function, or test it at the console prompt.
var getMessage;
var getMyMessage;
var response;
getMessage = function () {
return "I’m going on an adventure!";
};
// define a function and
// assign it to your variable
getMyMessage = function () {
return "Wassup!";
};
response = getMyMessage(); // assign the return value of your function to response
console.log(response);