-1

for some weird reason, it doesn't work worth a tinker's damn. it appends when i need it to increment. yes, i've read this, and this aaaand this (which doesn't work), but they don't really help (at all) with such a simple case. :poop: what i am trying to do, is this:

  var status = 0;
  console.log('status: '+status);
  status += 1;
  console.log('status: '+status);
  status += 2;
  console.log('status: '+status);
  status += 3;
  console.log('status: '+status);
  ...

but all it outputs is 0,01,012,0123 instead of 0,1,3,6. yes, it's simple, but that's what i need for this particular implementation and the stuff that connects to it. also, the steps matter; otherwise, i'd just status++ and i obviously don't want twenty-six lines of that either. DRY, right?

i've tried to do this, var status = Number(0); and var status = parseInt(0) for fun (no way it would work, but try anyway) and even tried status = status + 1' (pointless variant, but cover the bases...) and none work. what am i missing? i understand this, yet don't know how to make 0 == Number(0), as it were. i thought the increment existed to prevent kind of fumbuckery... its stupid math, for heaven's sake...

so. how do i force the zero to be a Number so the increment can work as needed and output anumber at each step along the way?

WhiteRau
  • 818
  • 14
  • 32
  • 2
    The code you posted will not do what you say it does. *edit* oh. – Pointy Nov 14 '17 at 22:51
  • Seems like `status` is a window variable, you should consider changing name. – kind user Nov 14 '17 at 22:53
  • 2
    The problem is that you're running the code in the global scope, and `status` is some `window` property that really wants to be a string. Change the variable name to "timothy" or "riceNoodle" and it works fine. – Pointy Nov 14 '17 at 22:54
  • works as expected to me! status: 0 status: 1 status: 3 status: 6 – fedeghe Nov 14 '17 at 22:55
  • @fedeghe probably depends on the environment; it'd almost certainly work in Node for example. – Pointy Nov 14 '17 at 22:55
  • @Pointy exactly – fedeghe Nov 14 '17 at 22:56
  • See https://developer.mozilla.org/en-US/docs/Web/API/Window/status – gunn Nov 14 '17 at 22:57
  • e.g. in chrome status is just "" ...so Kind user an Pointy got the clue – fedeghe Nov 14 '17 at 22:57
  • @Pointy hot damn. that's it. brilliant. never thought to check if status was reserved by the DOM. thanks! :) [duplicate, my ass Bergi...] – WhiteRau Nov 14 '17 at 23:34
  • i appreciate you guys answering this question in the comments. i obviously didn't know to even check that my variable name was the issue. StackOverflow is so quick to slap 'DUPLICATE QUESTION' on things, expecting us to magically know where we went wrong, it makes finding answers difficult. so thanks to everyone on this one. – WhiteRau Nov 15 '17 at 00:04

1 Answers1

-1

would be doing status = +status + 1 be to much? Or the hack +status++?