Log in or register to post comments

Appending instead of adding

January 10, 2019 - 8:07pm #1

Hi, I'm very new, just started yesterday.

I've worked through the tutorial "Invoke buttons from a function using JavaScript" . 

I used:

$scope.rotateLabel = function() {

  $scope.app.params.rotationParameter += 5;

};

as instructed in the tutorial, but somehow the rotationParameter is being interpreted as a string and appending the 5 instead of adding it, so repeated clicks of the button lead to values of 0, 05, 055, 0555, etc; rather than 0, 5, 10, 15 as expected. However, rotationParameter ++; works, leading to values of 0, 1, 2, 3, 4.

I can force it to increment in steps of five using a for loop with repeated ++  as below:

for (i = 0; i<5; i++) {

         $scope.app.params.rotationParameter ++;

       }

But this seems like a terrible solution. Can someone help me? how can I make it recognise the variable as an int and not a string?

 

Thanks,

Claire

Log in or register to post comments