-2

I have some code here:

this.$state.transitionTo('questions.question', { testId: this.$qs.userTestId, cq: this.$qs.cq + 1 });
this.$state.transitionTo('questions.question', { testId: this.$qs.userTestId, cq: this.$qs.cq - 1 });

The value of this.$qs.cq is 1.

When my code runs for the first case instead of changing it to 2 it makes it into "11". How can I make it so it does a numeric addition (and subtraction for the seconds case)?

I did define in typescript:

cq: number;

but it doesn't seem to give an error

Samantha J T Star
  • 30,952
  • 84
  • 245
  • 427
  • If `this.$qs.cq` is supposed to be a number you should use `parseInt()` when you assign a value to it, otherwise it's a string and `+` appends to it. – Ja͢ck Oct 12 '14 at 08:16

1 Answers1

2

Use:

pareseInt(this.$qs.cq,10) + parseInt(this.$qs.cq,10)
Unihedron
  • 10,902
  • 13
  • 62
  • 72
Arindam Nayak
  • 7,346
  • 4
  • 32
  • 48