+ 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) ;
1 Antwort
+ 1
You could reassign using a function or method (if using objects)
Function asTimeGoesBy(score, lives){
score = score++
lives = lives--
return [score, lives]
};