2012-04-14 08:44:00Morris
[JavaScript] Defining Functions
var hello = function () {
// Print hello on the console.
console.log("i am saying hello");
};
hello();
hello();
var hi = function () {
console.log("hi");
};
hi();
var myFirstFunction = function() {
console.log("yourName");
}
myFirstFunction();
var fullName = "";
var name;
var firstLetter;
/*
fixName function definition should go here.
*/
var fixName = function() {
/***** Begin repeated code block *****/
firstLetter = name.substring(0, 1);
name = firstLetter.toUpperCase() + name.substring(1);
fullName = fullName + " " + name;
/***** End repeated code block *****/
}
name = prompt("Enter your first name (all in lower case):");
fixName();
name = prompt("Enter your second name (all in lower case):");
fixName();
console.log("And your full name is:" + fullName);
// Print hello on the console.
console.log("i am saying hello");
};
hello();
hello();
var hi = function () {
console.log("hi");
};
hi();
var myFirstFunction = function() {
console.log("yourName");
}
myFirstFunction();
var fullName = "";
var name;
var firstLetter;
/*
fixName function definition should go here.
*/
var fixName = function() {
/***** Begin repeated code block *****/
firstLetter = name.substring(0, 1);
name = firstLetter.toUpperCase() + name.substring(1);
fullName = fullName + " " + name;
/***** End repeated code block *****/
}
name = prompt("Enter your first name (all in lower case):");
fixName();
name = prompt("Enter your second name (all in lower case):");
fixName();
console.log("And your full name is:" + fullName);