-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
  • 28,982
  • 82
  • 233
  • 406
  • 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,601
  • 13
  • 59
  • 69
Arindam Nayak
  • 7,298
  • 4
  • 31
  • 47