Why isnt this passing?

Can someone tell me why my code isnt passing? I checked and the returned values are exactly what they want so I’m not sure why its not working. I may have done it differently from what they would have wanted but they ask to get the result in a specific manner

  **Your code so far**

function titleCase(str) {
let words = str.toLowerCase().split(" ");
let result = "";


for (let i = 0; i < words.length; i++) {
  result+= words[i][0].toUpperCase() + words[i].slice(1) + " "
}

return result
}

console.log(titleCase("HERE IS MY HANDLE HERE IS MY SPOUT"));
  **Your browser information:**

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

Challenge: Title Case a Sentence

Link to the challenge:

Try

console.log("*****|" + titleCase("HERE IS MY HANDLE HERE IS MY SPOUT") + "|*****");

I got

*****|Here Is My Handle Here Is My Spout |*****

Sorry Im a little lost

I’m mainly confused as to why when I try the tests they say Im failing, the value they expect is actually the result I get in the console. I thought perhaps a space or punctuation issue but its the exact same

It isn’t quite the same…

The challenge test on the left says

titleCase("I'm a little tea pot") should return the string I'm A Little Tea Pot

and when I console log using my code I get

I'm A Little Tea Pot

Am I that dull or are they really not the same

You don’t get
*****|I'm A Little Tea Pot|*****, you get *****|I'm A Little Tea Pot |*****. You have an extra space at the end.

1 Like

Whitespace can be really hard to debug. A pending and prepending those strings is a cool way to visually debug it @JeremyLT !

1 Like

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