I am trying to create a function pluralizeParam(n, word, pluralWord) with these requirements:
- If n is 1, return the non-plural word (parameter word);otherwise, add an “s” to the plural word;
- If the pluralWord parameter is provided, instead of adding an “s,” return the pluralWord.
What I have done so far is following:
function returnPluralWord(n, word, pluralWord) {
if (n === 1) {
return word;
} else if (n === 1 && (word.lastIndexOf("s")) || (word.lastIndexOf("ess"))) {
return word + "s";
} else if (n !== 1 && word.length - 2 === "es") {
return word + "s";
} else if (pluralWord !== 'undefined') {
return pluralWord;
}
}
var result = returnPluralWord(2, "lioness", "lionesses");
console.log(result);
My problem is: it is not printing pluralWord. How do I do that? Thanks
n === 1, but more to the point, move your 4th case second.