# How to increase and decrease score using the same variable

**URL:** https://forum.code.org/t/how-to-increase-and-decrease-score-using-the-same-variable/38750
**Category:** CS Discoveries
**Tags:** csd-unit-3
**Created:** [December 1, 2023, 8:02pm UTC](https://forum.code.org/t/how-to-increase-and-decrease-score-using-the-same-variable/38750 "2023-12-01T20:02:22Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![dajanim](https://avatars.discourse-cdn.com/v4/letter/d/cc9497/32.png) [@dajanim](https://forum.code.org/u/dajanim)
#### Post date: [December 1, 2023, 8:02pm UTC](https://forum.code.org/t/how-to-increase-and-decrease-score-using-the-same-variable/38750/1 "2023-12-01T20:02:22Z")

</div>

[https://studio.code.org/projects/gamelab/gEP6nQqnMV01v7Xm8vTkRtHh3WvSJzF7r8PJVYbqPmU/edit](https://studio.code.org/projects/gamelab/gEP6nQqnMV01v7Xm8vTkRtHh3WvSJzF7r8PJVYbqPmU/edit)

I have scenario where I need the **health number** to go down when the **SPACE BAR IS PRESSED** , but when **I press the up Arrow** , I need the **health number to go up,** but instead **when the Up arrow is pressed** it will immediately **go down because of the variable.**

Any ideas how I can do that using the same number as a variable?

---

<div class="post-metadata">

### Author: ![melynn](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/melynn/32/4925_2.png) [@melynn](https://forum.code.org/u/melynn)
#### Post date: [December 1, 2023, 9:13pm UTC](https://forum.code.org/t/how-to-increase-and-decrease-score-using-the-same-variable/38750/2 "2023-12-01T21:13:30Z")

</div>

Hi @dajanim,

Welcome to the forum! The link does not go to your project but perhaps I can help without it.  
Based on your description it sounds like you have two different if statements with two different actions to take if the if statement is true. So in pseudocode(ish):  
set a global var health;  
if space bar is pressed → health = health - 1  
if up arrow is pressed → health = health +1

Hope that helps but if not, try sending another link by clicking share and copy link to project.  
~Michelle
