# GameLab Scoring Capability

**URL:** https://forum.code.org/t/gamelab-scoring-capability/14034
**Category:** Uncategorized
**Created:** [January 31, 2018, 3:11pm UTC](https://forum.code.org/t/gamelab-scoring-capability/14034 "2018-01-31T15:11:52Z")
**Posts on this page:** 1
**Showing post:** 2

<div class="post-metadata">

### Author: ![frank\_w\_lee](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/frank_w_lee/32/4895_2.png) [@frank\_w\_lee](https://forum.code.org/u/frank_w_lee)
#### Post date: [February 1, 2018, 6:01am UTC](https://forum.code.org/t/gamelab-scoring-capability/14034/2 "2018-02-01T06:01:06Z")

</div>

In the Computer Science Discoveries curriculum, several lessons in Unit 3 build up and eventually have the student use a variable to keep score in this side-scroller game: [https://studio.code.org/s/csd3/stage/16/puzzle/9](https://studio.code.org/s/csd3/stage/16/puzzle/9)

Here’s the gist:

1. Create a variable to keep track of the score (var score = 0;)
2. Use an “if” statement in your draw loop to constantly check if your scoring criteria is met (if x is touching y…)
3. If that condition is met, increase your score variable by 1 (score = score + 1;)

Remember the score is tracked internally, so it’s invisible to the user. You may need to remind students to add blocks to **display** the score whenever the score is updated (use the “text” block).

For the bunny/carrot example linked above, here’s my code that would go near the bottom…  
// when bunny touches carrot  
// add 1 to score and put carrot back off screen  
if (carrot.isTouching(bunny)) {  
carrot.x = 400;  
score = score+1;  
carrot.y = randomNumber(200, 400);  
}

---

_[View the full topic](https://forum.code.org/t/gamelab-scoring-capability/14034)._
