Garmaine Staff asked 1 year ago

So in the code below everything worked fine, until I got down to my first if statement. I kept getting the wrong results in test because I had (crazyString = char + crazyString) instead of what I have below. I now understand I could have used +=, but i was just wondering how come addition order is so strict in javascript.

const crazyCaps = (origString) => {
   let crazyString = '';
   for (let i = 0; i < origString.length; i++) {
      let char = origString[i];
      if (i % 2 === 1) { 
         char = char.toUpperCase();
         crazyString = crazyString + char;
      } else {
         crazyString = crazyString + origString[i];
      }    
   }
   return crazyString;
};