Quotes help make search much faster. Example: "Practice Makes Perfect"

Wednesday, December 5, 2012

Codecademy: Codeyear Splitting Names (Part 2)


//sample solution

var name = "John Doe";
var getFirstName = function(fullName){
var next = fullName[0];
var i = 0;
var length = fullName.length;
while(i<length){
if(next===" "){ //note be careful to assign "(space)" and not "" (which represents an empty string)
break;
} else {
console.log(fullName[i]);
i++;
next = fullName[i];
}
}
};
//test
getFirstName(name);

No comments:

Post a Comment


This is an example of scrolling text using Javascript.

Popular Posts