Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need to know what is wrong with this funtion!!!

Status
Not open for further replies.

Guerrilla

Technical User
Nov 10, 2002
2
0
0
US
Could someone look over this funtion and let me know what is wrong with it. Except for the comments, I know that there are some mistakes on the comments.



function GetCustomer(strCustomerName) {
// the customer name will be like "Smith, or "John Smith"
// this function parses the given customer name into last and first name
// it then looks up the birthday for that customer and figures if today is there birthday
// returned object will have 4 properties: firstName, lastName, birthDate, and isBirthday
var obj = new Object();
// check that its a string!
if (typeof strCustomerName != 'str')
throw new Error(101, 'GetCustomer requires a string paramater');
// parse name into last and first
var intCommaPosition = strCustomerName.indexof(', ');
if (intCommaPosition != -1) {
// it's in the form "Smith, John"
obj.lastName = strCustomerName.substr(0, intCommaPosition);
obj.firstName = strCustomerName.substr(intCommaPosition + 1);
} else {
// it's in the form "John Smith"
var intLastSpacePosition = strCustomerName.lastIndexOf(' ');
if (intLastSpacePosition = -1)
throw new Error(102, 'GetCustomer requires a first and last name');
obj.firstName = strCustomerName.substr(0, intLastSpacePosition);
obj.lastName = strCustomerName.substr(intLastSpacePosition + 1);
}
// now, get birthdate and see if it's today
obj.birthDate = GetCustomerBirthDate(obj.LastName, obj.FirstName); //returns Date object
var datToday = Date();
obj.isBirthday =
datToday.getMonth == obj.birthDate.getMonth &&
datToday.getDate == obj.birthDate.getDate;
return obj;
}


I would be grateful for any help.

Sincerely,

Rkings
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top