My Code Is

function wave(str){
  var str2 = [];
  var j = 0;
  for (var i = 0; i < str.length; i++, j++)
    {
      if (/S/.test(str.charAt(i)))
        {
          str2[j] =  str.slice(0, i) + str.charAt(i).toUpperCase() + str.slice(i + 1)
        }
      else if (i + 1 < str.length)
        {
          i++;
          str2[j] =  str.slice(0, i) + str.charAt(i).toUpperCase() + str.slice(i + 1)
        }
    }
  console.log(str2)
  console.log(str.length)
  return str2;
  
}


this is an image of my console log

enter image description here

so basically its not supposed to do that because in the code the else if checks it and because its true it should run and skip to the next one but that’s not what happen the first if gets triggered some how idk because the if statement clearly says no white space so it should return all of that but without those extra lines that have no capitalized letter!
1

New contributor

Imagination is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

2