//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