*(&)()Spinal Tap Case$%

Tell us what’s happening:
i don’t understand why my for loop doesn’t work, can anyone explain :frowning:

Your code so far

function spinalCase(str) {
  // "It's such a fine line between stupid, and clever."
  // --David St. Hubbins
  str = str.replace(/\s/g,"-");
  str = str.replace(/_/g,"-");
   for (i=1;i< str.length;i++) // Have no idea why this for loop doesn't work...
    if (90>=str.charCodeAt(i)>=65 && str.charAt(i)===str.charAt(i).toUpperCase() && str.charAt(i-1) !== "-")
        str = [str.slice(0, i), "-",str.slice(i)].join('');
  return str.toLowerCase();

spinalCase('AllThe-small Things');

Your browser information:

Your Browser User Agent is: Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36.

Link to the challenge:

90 >= str.charCodeAt(i) >= 65 evaluates as a single statement, left to right. It’s equivalent to this:

(90 >= str.charCodeAt(i)) >= 65

90 >= str.charCodeAt(i) will evaluate to true or false, which are then coerced to numbers (true becomes 1 and false becomes 0) before being compared with 65. Both 0 and 1 are less than 65, so this comparison will always evaluate to false.


:smile: you are right , thanks man