Title Case a Sentence - awkward Solution

What do you think of my solution? I hope its not a mess.

function titleCase(str) {
  let lower = str.toLowerCase();
  let newStr = "";
  let flag = false;
  
  if(lower.charAt(0) !== " ") {
    newStr += lower.charAt(0).toUpperCase();
  }

  for(let i = 1; i < lower.length; i++) {
    if(flag === true) {
      newStr += lower.charAt(i).toUpperCase();
      flag = false;
      continue;
    }
    
    if(lower.charAt(i) === " ") {
      newStr += " ";
      flag = true;
      continue;
    }
    
    newStr += lower.charAt(i)
  }
  console.log(newStr)
  return newStr;
}

titleCase("sHort and STout");

Your code has been blurred out to avoid spoiling a full working solution for other campers who may not yet want to see a complete solution. In the future, if you post a full passing solution to a challenge and have questions about it, please surround it with [spoiler] and [/spoiler] tags on the line above and below your solution code.

Thank you.