2018-08-06 10:20:19
JavaScript
, 2018-08-06 10:20:19

A function that changes the value of a variable?

Here I have a money variable and its value is 0. How to make the function increase it by 1 when it is executed

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vladimir Proskurin, 2018-08-06
detain

var a = 0;
function func(newA) {
   return newA+1;
}
a = func(a);

or shove it into an object
var a = { a: 1 };
function func(newA) {
    newA.a += 1;
}
func(a);

K
kr_ilya, 2018-08-06
@kr_ilya

function(){
var money = 0;
money += 1;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question