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') {
        resultArray.push(input[inputIndex]);
      }
      if (input[inputIndex] === 'u') {
        resultArray.push(input[inputIndex]);
      }
      for (let vowelsIndex = 0; vowelsIndex < vowels.length; vowelsIndex++) {
      //console.log(`vowelsIndex is ${vowelsIndex}`)
      if (input[inputIndex] === vowels[vowelsIndex])
        // console.log(input[inputIndex])
        resultArray.push(input[inputIndex])
          // console.log(resultArray)
      }
    }
    
     console.log(resultArray.join('').toUpperCase());

This is the correct form.

This is what I tried first:
console.log(resultArray.join(’’).toUpperCase());

This also didn’t work:
console.log(resultArray.toUpperCase());

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?

2 Likes

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

Hint

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 :
resultArray[i].toUpperCase()
?

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.