Get Programming with JavaScript - Listing 4.06
Listing 4.06 - Calling the sayHello function three times
var sayHello;
sayHello = function () {
console.log("Hello World!");
};
sayHello();
sayHello();
sayHello();
Further Adventures
Listing 4.06 - Calling the sayHello function three times - Task 1
- Change the message from the sayHello function.
var sayHello;
sayHello = function () {
console.log("I'm going on an adventure!"); // Change the message
};
sayHello();
sayHello();
sayHello();
Listing 4.06 - Calling the sayHello function three times - Task 2
- Break the Hello World! message across two lines.
var sayHello;
sayHello = function () {
console.log("Hello\nWorld!"); // Use a line-break
};
sayHello();
sayHello();
sayHello();
Listing 4.06 - Calling the sayHello function three times - Task 3
- Create a function that prints the letters of "Hello World!" one by one down the page.
var sayHello;
sayHello = function () {
console.log("H\ne\nl\nl\no\nW\no\nr\nl\nd\n!"); // Use line-breaks
};
sayHello();
sayHello();
sayHello();
You could also use a separate call to console.log for each letter.