Q:

JavaScript setInterval increase and decrease variable

I have a problem with creating a variable that first will increase value (for example) form 0 to 10, and after that it wil go back from 10 to 0. 
So 0,1,2,3...10,10,9,8,7...0 (and so on)
The main idea looks like this:
var count = 10;

var counter = setInterval(timer, 500); 

function timer() {
  count = count-1;

  if (count == 0) {
        count = 10;
    }

}
console.log(counter);

But it will only go from 0 to 10 all the time.  How to make that 'comeback' thing?  Thank you for help. 

A:

Try to change the increment value
var count = 10;
var counterIncrement=-1;
var counter = setInterval(timer, 500); 

function timer() {
  count = count+counterIncrement;
  if (count == 0 || count == 10 ) {
        counterIncrement = -counterIncrement;
    }
  console.log(count);
}

