Title Case a Sentence: callback function problem

Title Case a Sentence: callback function problem
0

Well… I have this:
by the way: I really hate for loops

function upperChar (str) {
    return str.toUpperCase();
}

let a = "bernardo";
let b = a.replace(a.charAt(0), upperChar);
console.log(b) // --> Bernardo

It works. BUT, when I try to apply to the challenge: nothing…

function titleCase(str) {
  let myArr = str.split(" ");
  let x = [];
  let charTemp = [];
  let y = [];
  let a = [];
  
  
  for (let i = 0; i < myArr.length; i++){
    x.push(myArr[i].toLowerCase());
    a = x.replace(x.charAt(0), upperChar);//OR   a = x.replace(x[i].charAt(0), upperChar);
    console.log(a);
    charTemp.push(x[i].charAt(0).toUpperCase());
    y.push(charTemp[i] + x[i]);
  }

  function upperChar (str) {
    return str.toUpperCase();
}

   return a;
}


titleCase("sHoRt AnD sToUt");

A post was merged into an existing topic: Title Case a Sentence: callback function