Javascript add character

function pluralize(input){
const updated = [];
for (let i=0;i < pluralize.length; i++) {

updated.push(input[i] + "s")};
  return updated;


// Uncomment these to check your work!
const animals = ["dog", "cat", "tree frog"];
console.log(pluralize(animals)); // should log: ["dogs", "cats", "tree frogs"]

I am trying to create a function that will add an “s” to the end of every word in the array. Right now, it is only putting the “s” on dog and stopping there. Can someone please tell me why and how to fix this?

What is pluralize the name of?

pluralize is the name of the function…

Exactly! So what does pluralize.length give you?

My thinking was that it would give me the number of elements in the array after running the function Pluralize…

i should have done updated.length??

You are wanting to add an ‘s’ to each element of your animals array. You have correctly passed the array as an argument to the pluralize function where it is assigned to the parameter input. In order to iterate over each element of the array assigned to input, you should use input.length.

WOWWWWWW!!! Smh… This is gonna be a long year haha… Thanks again man(or woman) … So because i had pluralize.length was it just stopping after it added “dog”? Or how would you explain it? I want to understand Javascript and everything about it to the best of my abilities.

1 Like

I didn’t actually know for sure what the .length of a function was until just now. I added this line to your code

console.log(`pluralize.length = ${pluralize.length}`);

as the first line inside the pluralize function. Then I ran your code, and got the following printed to the console:

pluralize.length = 1
[ ‘dogs’ ]

So, now we both know. Your for loop finished executing after 1 iteration because the length of the function is 1. :slightly_smiling_face:

It’s man. You’re welcome!

1 Like