Wrong answer ?!

Tell us what’s happening:
Describe your issue in detail here.

in JavaScript Algorithms and Data Structures course in Title Case a Sentence, I wrote the code, but I don’t understand why my code is wrong, it gives you the required from the challenge.

**Your code so far**

function titleCase(str) {
let arr = str.split(" ");
let result = "";
for (let i = 0; i< arr.length; i++) {
    for (let j = 0; j < arr[i].length; j++) {
        if (arr[i][j] === arr[i][0])
            result += arr[i][j].toUpperCase();
            result += arr[i][j].toLowerCase();
    result += " ";
return result;

titleCase("I'm a little tea pot");
**Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36

Challenge: Title Case a Sentence

Link to the challenge:

Looking at what function returns, when wrapped in quotes (or any other character), should help see the issue:

console.log('"' + titleCase("I'm a little tea pot") + '"');

the function return string

Yes… but is it exactly, perfectly, character for character the precise result required, or do you have an extra character in your string?

Thanks, I found the porblem

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.