+ 2

Variables Reassigning

In a game, the player's score and their number of lives don't stay the same. The score typically goes up, and the lives typically go down. That means the game needs to be able to change the value of those variables later. So my question is, can someone please explain how a variable is given a new value? And would it look something like this?- var score = 0 ; var lives = 3 ; print1n(score) ; print1n(lives) ; score = 5 ; print1n(score) ;

14th Nov 2019, 11:47 PM
NEVA MELLOW
NEVA MELLOW - avatar
1 Odpowiedź
+ 1
You could reassign using a function or method (if using objects) Function asTimeGoesBy(score, lives){ score = score++ lives = lives-- return [score, lives] };
16th Nov 2019, 2:18 PM
Neil Davis
Neil Davis - avatar