I'm trying to create a custom function for a google docs spreadsheet. I feel like this is a really simple problem, and I've quickly moved out of my depth. Please help me. A point in the right direction would be much appreciated.
The googledocs script editor gives this error:
TypeError: Cannot call method "replace" of undefined. (line 50)
For this code:
function replaceGender(name, gender, comment) {
var genderedComment = String();
var name;
var gender;
var comment;
if(gender == "m")
{
genderedComment = ungenderedComment.replace("(name)", name).replace(/\(He\/She\)/g,"He").replace(/\(His\/\Her\)/g,"His").replace(/\(his\/\her\)/g,"his").replace(/\(him\/\her\)/g,"him").replace(/\(he\/\she\)/g,"he");
}
else
{
genderedComment = ungenderedComment.replace("(name)", name).replace(/\(He\/She\)/g,"She").replace(/\(His\/\Her\)/g,"Her").replace(/\(his\/\her\)/g,"her").replace(/\(him\/\her\)/g,"her").replace(/\(he\/\she\)/g,"she");
}
return genderedComment;
};
I think its easy, but I'm doing something wrong.
I've changed the code and it works now without error, but the last.replace(/\(he\/\she\)/g,"she");
and .replace(/\(he\/\she\)/g,"he");
don't replace.?? no idea...
thanks again for all your help... as i said im learning a lot.
here is the code now
function replaceGender(name, gender, comment) {
if(gender == "m")
{
comment = comment.replace(/\(name\)/g, name).replace(/\(He\/She\)/g,"He").replace(/\(His\/\Her\)/g,"His").replace(/\(his\/\her\)/g,"his").replace(/\(him\/\her\)/g,"him").replace(/\(he\/\she\)/g,"he");
}
else if(gender == "f")
{
comment = comment.replace(/\(name\)/g, name).replace(/\(He\/She\)/g,"She").replace(/\(His\/\Her\)/g,"Her").replace(/\(his\/\her\)/g,"her").replace(/\(him\/\her\)/g,"her").replace(/\(he\/\she\)/g,"she");
}
return comment;
};