ajeshrkurup
2/24/2017 - 5:08 PM

JS Bin // source https://jsbin.com/cocome

JS Bin

// source https://jsbin.com/cocome

var c = 0;
var d = 1;
//var count = 0;


var addSetI = setInterval(function () {
   
//     if(count == 3) {
//         clearI();
//     }
    
  timer();
  
        
}, 1000);

function timer() {
       
        c =c +d;
        console.log(c);
        if(c == 10) {
            //count++
            d=-1;
            
        }
        else if(c<=1) {
            d=1;
        }
    }

var clearI = function() {
  clearInterval(addSetI);    
};
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>

<script id="jsbin-javascript">
var c = 0;
var d = 1;
//var count = 0;


var addSetI = setInterval(function () {
   
//     if(count == 3) {
//         clearI();
//     }
    
  timer();
  
        
}, 1000);

function timer() {
       
        c =c +d;
        console.log(c);
        if(c == 10) {
            //count++
            d=-1;
            
        }
        else if(c<=1) {
            d=1;
        }
    }

var clearI = function() {
  clearInterval(addSetI);    
};
</script>



<script id="jsbin-source-javascript" type="text/javascript">var c = 0;
var d = 1;
//var count = 0;


var addSetI = setInterval(function () {
   
//     if(count == 3) {
//         clearI();
//     }
    
  timer();
  
        
}, 1000);

function timer() {
       
        c =c +d;
        console.log(c);
        if(c == 10) {
            //count++
            d=-1;
            
        }
        else if(c<=1) {
            d=1;
        }
    }

var clearI = function() {
  clearInterval(addSetI);    
};</script></body>
</html>