# Need code for bug grab

**URL:** https://forum.code.org/t/need-code-for-bug-grab/15766
**Category:** Unit and Lesson Discussion
**Tags:** csd-unit-6
**Created:** [April 24, 2018, 1:14pm UTC](https://forum.code.org/t/need-code-for-bug-grab/15766 "2018-04-24T13:14:32Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![sjreagin](https://avatars.discourse-cdn.com/v4/letter/s/dc4da7/32.png) [@sjreagin](https://forum.code.org/u/sjreagin)
#### Post date: [April 24, 2018, 1:14pm UTC](https://forum.code.org/t/need-code-for-bug-grab/15766/1 "2018-04-24T13:14:32Z")

</div>

Does anyone have the code for the bug grab game? I am having some students having a very difficult time coming up with their own game to write. So my thought is to have them change up the bug grab game or the emoji game. I would like to show them the code for bug grab as a starting point.

---

<div class="post-metadata">

### Author: ![elizabeth\_admin](https://avatars.discourse-cdn.com/v4/letter/e/bb73d2/32.png) [@elizabeth\_admin](https://forum.code.org/u/elizabeth_admin)
#### Post date: [April 26, 2018, 9:27pm UTC](https://forum.code.org/t/need-code-for-bug-grab/15766/2 "2018-04-26T21:27:39Z")

</div>

Do you need the entire project, or just the Javascript code? I can copy and paste the code here, but you’ll still need to do the Design Mode part of the project.

---

<div class="post-metadata">

### Author: ![elizabeth\_admin](https://avatars.discourse-cdn.com/v4/letter/e/bb73d2/32.png) [@elizabeth\_admin](https://forum.code.org/u/elizabeth_admin)
#### Post date: [April 26, 2018, 9:28pm UTC](https://forum.code.org/t/need-code-for-bug-grab/15766/3 "2018-04-26T21:28:52Z")

</div>

```
var score = 0;
var starting_position = getProperty("bug", "x");

onBoardEvent(buttonL, "press", function(event) {
  score = score - 10;
  setProperty("bug", "x", starting_position + score);
  if (score < -100) {
    setProperty("winner", "text", "Player 1");
    setScreen("win_screen");
    buzzer.frequency(900, 1000);
  }
});

onBoardEvent(buttonR, "press", function(event) {
  score = score + 10;
  setProperty("bug", "x", starting_position + score);
  if (score > 100) {
    setProperty("winner", "text", "Player 2");
    setScreen("win_screen");
    buzzer.frequency(200, 1000);
  }
});
```

---

<div class="post-metadata">

### Author: ![alainaw](https://avatars.discourse-cdn.com/v4/letter/a/13edae/32.png) [@alainaw](https://forum.code.org/u/alainaw)
#### Post date: [May 18, 2018, 6:44pm UTC](https://forum.code.org/t/need-code-for-bug-grab/15766/4 "2018-05-18T18:44:48Z")

</div>

Im so glad I found this post!  
Will you be putting up example solutions for this in the unit 6 teacher interface soon?
