# Lesson 13 Extra \*extra extra\* Challenge

**URL:** <https://forum.code.org/t/lesson-13-extra-extra-extra-challenge/26139>\
**Category:** CS Discoveries\
**Tags:** csd-unit-3-lesson-13\
**Created:** [April 5, 2019, 3:13pm UTC](https://forum.code.org/t/lesson-13-extra-extra-extra-challenge/26139 "2019-04-05T15:13:38Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![ben\_kuehl](https://avatars.discourse-cdn.com/v4/letter/b/779978/32.png) [@ben\_kuehl](https://forum.code.org/u/ben_kuehl)\
**Post date:** [April 5, 2019, 3:13pm UTC](https://forum.code.org/t/lesson-13-extra-extra-extra-challenge/26139/1 "2019-04-05T15:13:38Z")

</div>

Anyone ever give the students an extra challenge of trying to figure out how to keep the rectangle from never leaving the screen. I feel this would be a good key learning as if you were designing a game and say the rectangle was a character I feel you would never want any part of it at all to leave the screen.

Anyways hope this makes sense and here is a solution to this…

// Create a sprite  
var sprite = createSprite(200, 100, 50, 50);  
sprite.shapeColor = “red”;

function draw() {  
background(“white”);

// Move the sprite in the direction of the arrow keys  
// But make sure it doesn’t go off the screen  
if (keyDown(“up”) && sprite.y \> 25) {  
sprite.y = sprite.y - 5;  
}  
if (keyDown(“down”) && sprite.y \< 375) {  
sprite.y = sprite.y + 5;  
}  
if (keyDown(“left”) && sprite.x \> 25) {  
sprite.x = sprite.x - 5;  
}  
if (keyDown(“right”) && sprite.x \< 375) {  
sprite.x = sprite.x + 5;  
}  
drawSprites();

}

---

<div class="post-metadata">

**Author:** ![ben\_kuehl](https://avatars.discourse-cdn.com/v4/letter/b/779978/32.png) [@ben\_kuehl](https://forum.code.org/u/ben_kuehl)\
**Post date:** [April 5, 2019, 3:22pm UTC](https://forum.code.org/t/lesson-13-extra-extra-extra-challenge/26139/2 "2019-04-05T15:22:07Z")

</div>

One thing I just realized though you have to consider is how much you are increasing the sprite by. As you can see I sped up the sprite by doing +5 as I was getting sick of how slow it was going. However, if I do more then +5 it will actually still fall off the screen in my scenario.

Lot of different things you have to think about and consider when your making these.

---

<div class="post-metadata">

**Author:** ![bradleywellsashley](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/bradleywellsashley/32/522_2.png) [@bradleywellsashley](https://forum.code.org/u/bradleywellsashley)\
**Post date:** [April 6, 2019, 3:16pm UTC](https://forum.code.org/t/lesson-13-extra-extra-extra-challenge/26139/3 "2019-04-06T15:16:36Z")

</div>

Ben,

Yep! As I started making challenges for my students I realized those little things too. Glad to see you are working through it!

Brad

PS also responded to your other post here: [Lesson 13 Extra \*extra\* Challenge](https://forum.code.org/t/lesson-13-extra-extra-challenge/26137/3?u=bradleywellsashley)
