Created
March 5, 2012 06:03
-
-
Save msbukkuri/1976962 to your computer and use it in GitHub Desktop.
Messing around with Javascript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var fullName = ""; | |
var firstLetter; | |
/* | |
fixName function definition should go here. | |
*/ | |
var fixName = function(name, nameType) { | |
/***** Begin repeated code block *****/ | |
var appendString; | |
firstLetter = name.substring(0, 1); | |
appendString = firstLetter.toUpperCase() + name.substring(1); | |
switch(nameType){ | |
case "first": | |
case "last": | |
appendString = firstLetter.toUpperCase() + name.substring(1); | |
break; | |
case "middle": | |
appendString = firstLetter.toUpperCase(); | |
break; | |
} | |
fullName = fullName + " " + appendString; | |
/***** End repeated code block *****/ | |
}; | |
var firstName = prompt("Enter your first name (all in lower case):"); | |
fixName(firstName, "first"); | |
var middleName = prompt("Enter your middle name (all in lower case): ") | |
fixName(middleName, "middle"); | |
var lastName = prompt("Enter your second name (all in lower case):"); | |
fixName(lastName, "last"); | |
console.log("And your full name is:" + fullName); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment