Tell us what’s happening:
Please ignore my terrible variable naming - minimalist names just compute better in my brain for some reason, especially for short tests like this.
This is a bit of a difficult one - as you can see, I’ve logged all of the given tests to the console at the bottom and what is logged is exactly what each of the user stories say should be returned when their respective string is passed in. The brief is simple - convert a string to title case (much simpler than some of the labs in the back half of the Loops section, that’s for sure!). I’ve read it over multiple times and I fail to see how the code I’ve written does not meet the requirements, or indeed come up with any string to pass in to the code for which the output would be anything other than a title-cased version of that string.
And yet, this code fails to pass the lab tests - which means either there’s a bug (an accusation I never like to make given the people that put the curriculum together know mountains more about programming than I do!) or there’s some kind of implied extra step that’s assumed to be obvious or self-explanatory, and probably is to neurotypical people but for autistic people really isn’t (I can’t say that this is likely either, given that the people that put this curriculum together, you know, are programmers…).
Your code so far
function titleCase(arg){
const b = arg.split(" ");
const c = [];
for (const word of b){
if (word.length == 1){
c.push(word.toUpperCase());
} else {
c.push(word.charAt(0).toUpperCase());
};
};
const d = [];
for (const word of b){
d.push(word.slice(1).toLowerCase());
};
const e = [];
for (let i = 0; i < c.length; i++){
e.push(c[i], d[i]);
};
const f = [];
for (let i = 0; i < e.length; i += 2){
f.push(`${e[i]}${e[(i + 1)]} `);
};
return f.toString().replaceAll(",", "");
};
console.log(titleCase("I like to code"));
console.log(titleCase("javaScript is fun"));
console.log(titleCase("I'm a little tea pot"));
console.log(titleCase("sHoRt AnD sToUt"));
console.log(titleCase("HERE IS MY HANDLE HERE IS MY SPOUT"));
Your browser information:
(If it makes a difference, I actually use Zen browser, which admittedly is basically Firefox under the hood!)
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:158.0) Gecko/20100101 Firefox/158.0
Challenge Information:
Build a Title Case Converter [Lab]
