How do I do it I have pos=0 and each time I fire a function Pos+=10 and how to store how many times I fire it in another var
Asked
Active
Viewed 47 times
0
-
use some global variable to store count.. – Jyothi Babu Araja Sep 07 '16 at 11:39
-
`var counter = 0` followed by `counter += 1;` – Gerardo Furtado Sep 07 '16 at 11:39
-
This is a really basic question - maybe consider solving it by yourself to improve your JS skills. If you don't wan't that share your code and possibly someone will do it for you. – Mx. Sep 07 '16 at 11:39
3 Answers
0
let pos = 0
function count (){
pos = pos + 10;
console.log('fired count-' , pos/10 , ', value- ', pos )
}
for(var i= 0 ;i<5 ; i++){
count();
}

ajaykumar
- 646
- 7
- 17
0
var count;
if (count == undefined || count == "" || count == 0)
{
var count = 0;
}
function add()
{
count+=10;
alert(count);
}
<button onclick="add();">click</button>

Sidharth Gusain
- 1,473
- 1
- 13
- 20