theHussle
theHussle

Reputation: 321

JavaScript Variable returning null when entering for loop

I'm working on some code that should output the accumulation of a string eg.

abc would = A Bb Ccc

But when I test it the input and output get assigned abc and "" respectively, but once the for loop happens the code just stops and returns null.

Anyone can explain why? I tried SubString instead of charAt to no avail.

function accum(s) {

  //storage
  var input = s;
  var output = "";

  // capitalize first letter
  for (var i = 0; i < s; i++) {
    output = input.charAt(i);
    output.toUpper();

    for (var j = i; j < i; j++) {
      output += output.toLower();
    };

    return output;
  };

}
console.log(accum("abc"));

Upvotes: 0

Views: 107

Answers (1)

cs01
cs01

Reputation: 5773

I believe the first for loop should have the condition i < s.length, as opposed to i < s.

Upvotes: 1

Related Questions