freeCodeCamp's editor is saying this is incorrect

Tell us what’s happening:
I’ve written this code for the challenge. Everything’s outputing correctly, but freeCodeCamp’s editor is saying it’s wrong. Please tell me why the editor is saying this.
I may also be incorrect, so please don’t go harsh on me, and explain what went wrong.

/*
function titleCase(str) {
var str1 = str.split(' ');
var regex = /\w/;
var firstchar = '';
var output = '';

for (var i = 0; str1.length > i; i++) {
var str2 = str1[i].replace(regex, ' ');
firstchar = str1[i].slice(0, 1);
firstchar = firstchar.toUpperCase();
var tempstr = firstchar + str1[i].slice(1).toLowerCase();
output += tempstr + ' ';
}
str = output;
//console.log (str);
return str;
}
*/
function titleCase(str) {
var temp = str.toLowerCase().replace(/(^|\s)\S/g, ' ');
console.log(temp)
return str.toLowerCase().replace(/(^|\s)\S/g, L => L.toUpperCase());
}
titleCase("sHorT aNd stOuT")

Your browser information:

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

Challenge: Title Case a Sentence

Link to the challenge:

Thanks

what error are you getting? what part is giving you issues?

I just copied the part out of the comments, and that pass.

Do you mean the commented out one? Please explain more.

The editor is saying my code is wrong. Only the requirement where it says we have to return a string comes correct, even though the whole code does what it should.

Hey @gammarays :wave:,

Your code works totally fine for me. Did you have any extensions that have access to FCC. This can cause it to alter the tests causing it to fail. You might want to disable some of those extensions.

Hope this helps,
Remember to Stay Safe and Happy Coding!! :slight_smile:

Catalactics