0

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"));

4
  • 8
    Did you mean i < s.length? Did you mean .toUpperCase() and .toLowerCase()? Commented Oct 10, 2016 at 6:28
  • yes.. awesome thanks. Getting my head around switching syntax, the tool I'm using didn't even bring these up as errors Commented Oct 10, 2016 at 6:30
  • 1
    Are you using notepad? :D Commented Oct 10, 2016 at 6:42
  • might as well be!, no I run it through pythontutor.com/javascript.html#mode=edit, which is really good. But doesn't advise of any syntax errors etc Commented Oct 10, 2016 at 8:29

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.