Why can't I capitalize items in an array before I join them?

While doing the Whale Talk project, I noticed I’m not able to capitalize items in the array until after I join them.

    const input = 'Sunshine and Roses and I love you to the moon and back';
    let vowels = ['a', 'e', 'i', 'o', 'u'];
    const resultArray = [];
    for (let inputIndex = 0; inputIndex < input.length; inputIndex++) {
      //console.log(inputIndex) -- 17
      if (input[inputIndex] === 'e') {
      if (input[inputIndex] === 'u') {
      for (let vowelsIndex = 0; vowelsIndex < vowels.length; vowelsIndex++) {
      //console.log(`vowelsIndex is ${vowelsIndex}`)
      if (input[inputIndex] === vowels[vowelsIndex])
        // console.log(input[inputIndex])
          // console.log(resultArray)

This is the correct form.

This is what I tried first:

This also didn’t work:

What if I wanted to capitalize the items in the array and NOT join? What am I doing wrong?

What kind of data type are you able to call .toUpperCase() on? And what data type is resultArray?


You’d need to access each item in the array, and use the toUpperCase() method on the individual items.


You could either loop through the array with a for loop, or use the map() method.

1 Like

Oh I see, so create a for loop for the result array and :

That would work (as long as you reassign the values to the array indices). If you are familiar with the map() method, that would be more concise, but the for loop works just as well.