Correct answers but answer not accepted

Tell us what’s happening:
I have written a code that gets what is asked for, which is capitalise only the first letter of each word.

I have done that in a totally different working way but the website doesnt accept it.
Your code so far

function titleCase(str) {
  let string = str.toLowerCase();
  let arr = string.split(' ');
  let upperCase;
  let sentence = '';
  let newArr = [];
  for(let i=0; i<arr.length; i++){
    upperCase = arr[i][0].toUpperCase();
     newArr.push(upperCase + arr[i].slice(1));
     sentence += newArr[i] + ' ';
  return sentence;

titleCase("sHoRt AnD sToUt");
  **Your browser information:**

User Agent is: Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/89.0.4389.128 Safari/537.36.

Challenge: Title Case a Sentence

Link to the challenge:

if I do this, do you see the issue?

1 Like

I see that its false, but…I dont understand why :face_with_thermometer:

Should there be a space at the end?

1 Like

:sweat_smile: little things can change everything. Thansk

1 Like

What does the {} do in console.log(output);

it’s shorthand object literal, it’s creating an object with the variable name as property name and the variable content as property value

Its something like destructuring . Rigth?

no, destructuring extract values from objects or arrays, that creates the object

OK, I understand.
Thanks for helping.

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