It works but I can pass the challenge

It works but I can pass the challenge
0

#1

Maybe it is not the best code but I get all the right results. In addition I can not pass the challenge. Does anyone know why?
My code is this one for the “Title Case a Sentence"
function titleCase(str) {
var array = [];
array = str.split(” “);
var something=” ";
var printed = " ";
for (var i=0; i<array.length; i++){
var newArray = array[i].toLowerCase() + " ";
something = newArray.charAt(0).toUpperCase() + newArray.slice(1);
printed += something;
}

return printed;
}

titleCase(“HERE IS MY HANDLE HERE IS MY SPOUT”);


#2

Hi,

I just launched your code in the browser console and I get the correct result.

Could you tell me what error you get on the right panel that prevents you from passing the challenge ?


#3

firstly, thank you for your time. I take the correct result for all the examples, I don’t have error but it looks like I did right only the first one from the
titleCase(“I’m a little tea pot”) should return a string.
titleCase(“I’m a little tea pot”) should return “I’m A Little Tea Pot”.
titleCase(“sHoRt AnD sToUt”) should return “Short And Stout”.
titleCase(“HERE IS MY HANDLE HERE IS MY SPOUT”) should return “Here Is My Handle Here Is My Spout”.


#4

Because the algorithm is correct and you don’t pass the challenge, could you try to press ctrl + enter while in the left panel ?


#5

I did that but still nothing


#6

Ok, maybe it’s an issue with the browser. Did you close and open the browser ? Or clear your cookies.

I have also tried and I can get the errors and pass the challenge.


#7

I tried it. Anyway, I changes my code and now it’s okay but I don’t know why!


#8

Hahaha, the mystery of computers. Glad it works. Good luck for your next challenges.