Basic Algorithm Scripting #11: Title Case a Sentence

Tell us what’s happening:

I always look at the challenge guide page after I’ve completed an exercise to compare my (awful) solutions against the ones provided. I try to avoid it otherwise. That has changed since I started the basic algorithm scripting section of the JavaScript course. Now I’ll usually find myself looking at some pseudocode or steps I’ve written, unable to translate it into JavaScript without googling methods or syntax, et cetera.

I guess my question is, is this to be expected during this section? Or is the assumption that I should have retained enough information from the previous exercises to be able to solve these algorithms without a search engine? For context, I’ve added my working solution and one solution from the challenge guide page:

  **Your code so far**
function titleCase(str) {
  let lowerArray = str.split(' ');
  let upperStr = ``;

  for (let i in lowerArray) {
    lowerArray[i] =
      lowerArray[i][0].toUpperCase() + lowerArray[i].slice(1).toLowerCase();
  }
  for (let j = 0; j < lowerArray.length; j++) {
    upperStr += `${lowerArray[j]} `;
  }
  return upperStr.trimEnd();
}

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

  **Challenge Guide Solution**
function titleCase(str) {
  return str
    .toLowerCase()
    .replace(/(^|\s)\S/g, L => L.toUpperCase());
}
  **Your browser information:**

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

Challenge: Title Case a Sentence

Link to the challenge:

if you don’t do this, you are doing programming wrong
so, you are doing fine.

As long as what you google is the pieces you need, and not the whole solution, you are doing great!

1 Like

It’s absolutely ok to look for some methods or recall some syntax, you just can’t keep everything in your mind. The most important about these algorithmic tasks is to come up with the right algorithm, even if you write it on paper in simple words. Translating it to some programming language is secondary, in my opinion, less important.

Ehh, I agree that designing the solution without Google is important, but translation to code and getting it finally working is also a big piece. You should be using Google to help you during that second part, but you definitely need to practice those skills. Working and debugging until it does what it needs is critical practice.

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