Change first letter of each word in an array to uppercase using JS

37 Views Asked by At

I'm a novice, so please forgive the basic question.

I'm trying to change the first letter in each word in an array to uppercase (readline is being used for the input phrases, the first of which is 'hello world').

The problem is, my output is 'Hello world' instead of 'Hello World') Can anyone tell me where I'm going wrong and how I can fix it?

My code

1

There are 1 best solutions below

0
tutacat On

Your current code does this:

print uppercase(string[0]) + string[1 to end]

Think through the steps logically, how your program does it.

You have a string and not an array. And you need to work on each word that's part of the string separately.

For example:

for(s of array) {
    
}

Or:

for (word of words) {
    array.push(word);
}

It's not just about understanding the language. It's also how to understand the problem.