Why it is not passing the test

Tell us what’s happening:
I have run this code and i am getting the same result as shown in the test but still it is not passing the test . Is something wrong with my code or is it the test failing??
i know i shou

Your code so far

function titleCase(str) {
return str.toLowerCase().split(' ')
.reduce(function (acc,cur){
  let cap=  cur.charAt(0).toUpperCase();
  // console.log(cap)
  let newCap= cur.replace(cur.charAt(0),cap);
  // console.log(newCap);
  return acc + " " + newCap;

titleCase("I'm a little tea pot");

Your browser information:

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

Challenge: Title Case a Sentence

Link to the challenge:

You are putting an extra space at the beginning.

1 Like

I have done this to check what it is returning:

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

And what is printed to the console is --> I'm A Little Tea Pot<--
do you see the issue?

It looks like you may be preappending a space, which causes incorrect results.

 I'm A Little Tea Pot


I'm A Little Tea Pot
1 Like

got it ! Thanks A LOT

1 Like