# Unit 3 Lesson 17 Questions

**URL:** <https://forum.code.org/t/unit-3-lesson-17-questions/37099>\
**Category:** CS Discoveries\
**Tags:** csd-unit-3\
**Created:** [October 21, 2022, 2:18pm UTC](https://forum.code.org/t/unit-3-lesson-17-questions/37099 "2022-10-21T14:18:18Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![lschlag](https://avatars.discourse-cdn.com/v4/letter/l/ed8c4c/32.png) [@lschlag](https://forum.code.org/u/lschlag)\
**Post date:** [October 21, 2022, 2:18pm UTC](https://forum.code.org/t/unit-3-lesson-17-questions/37099/1 "2022-10-21T14:18:18Z")

</div>

I have a student who is trying to put text on his second part of his card. The page changes and the color and gradient are fine, but we can not get the text to show up? I can not figure out what we are doing wrong? Any help would be great…Here is the code:

var envelope\_1 = createSprite(200, 200);  
envelope\_1.setAnimation(“envelope\_1”);  
function draw() {  
background(“lightblue”);  
if (keyDown(“space”)) {  
var gradient\_01\_1 = createSprite(200, 200);  
gradient\_01\_1.setAnimation(“gradient\_01\_1”);  
textSize(30);  
fill(“pink”);  
text(“Congradulations On Your Birth!”, 45, 200);  
drawSprites();  
} else {  
envelope\_1.x = randomNumber(195, 205);  
envelope\_1.y = randomNumber(195, 205);  
}  
drawSprites();  
}

---

<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:** [October 21, 2022, 3:47pm UTC](https://forum.code.org/t/unit-3-lesson-17-questions/37099/2 "2022-10-21T15:47:41Z")

</div>

HI @lschlag!

Welcome to the forum!! Usually text issues can be solved by moving the drawSprites() block above where the text will be drawn. In most cases, you only need one drawSprites() in the draw loop so it could go after you draw the background. The other thing I notice is that you created a sprite in the draw loop. It’s hard to tell what the sprite is without a link to the project but I am guessing it is a background gradient that you only want to show up in when the space key is pressed. By creating it using the **var** in the draw loop, it is essentially redrawing it over text each time through the draw loop and could be covering up the text. You can solve this issue by creating it at the top of the code and setting visible to false. Then, in the if statement, set the visible to true.

See if those tips help. If not, let us know and send a link to the project so we can take a closer look. You can do this by clicking SHARE and “copy link to project”.

~Michelle

---

<div class="post-metadata">

**Author:** ![lschlag](https://avatars.discourse-cdn.com/v4/letter/l/ed8c4c/32.png) [@lschlag](https://forum.code.org/u/lschlag)\
**Post date:** [October 24, 2022, 1:45pm UTC](https://forum.code.org/t/unit-3-lesson-17-questions/37099/3 "2022-10-24T13:45:59Z")

</div>

It still is not working? How do I send a link to you of the project?

---

<div class="post-metadata">

**Author:** ![lschlag](https://avatars.discourse-cdn.com/v4/letter/l/ed8c4c/32.png) [@lschlag](https://forum.code.org/u/lschlag)\
**Post date:** [October 24, 2022, 1:51pm UTC](https://forum.code.org/t/unit-3-lesson-17-questions/37099/4 "2022-10-24T13:51:32Z")

</div>

> **[Check out what I made](https://studio.code.org/projects/gamelab/F_vQ4YCnXYPZMreTbfshKXf1Rfl_hXeFjb-gZ9Ozy8c)**
>
> I wrote the code myself with Code.org

---

<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:** [October 24, 2022, 4:16pm UTC](https://forum.code.org/t/unit-3-lesson-17-questions/37099/5 "2022-10-24T16:16:37Z")

</div>

I moved all your sprites and animation to the top of the code and set visible to “false” for the gradient. Then, when the space key is pressed, set visible to “true”. I also **moved** the drawSprite to above the if statement and **removed** the second drawSprite in the else statement.  
~Michelle

---

<div class="post-metadata">

**Author:** ![lschlag](https://avatars.discourse-cdn.com/v4/letter/l/ed8c4c/32.png) [@lschlag](https://forum.code.org/u/lschlag)\
**Post date:** [October 24, 2022, 4:40pm UTC](https://forum.code.org/t/unit-3-lesson-17-questions/37099/6 "2022-10-24T16:40:40Z")

</div>

Thank you. Where can I locate the changes that you made to the code?

---

<div class="post-metadata">

**Author:** ![mwood](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/mwood/32/4941_2.png) [@mwood](https://forum.code.org/u/mwood)\
**Post date:** [October 24, 2022, 5:18pm UTC](https://forum.code.org/t/unit-3-lesson-17-questions/37099/7 "2022-10-24T17:18:24Z")

</div>

@lschlag,

The “drawSprites” command on line 15 is the last line of code that is executed each time through the draw loop regardless of whether or not the space key is pressed. Therefore, once you hit the space bar, it draws the gradient, then draws the text and then draws the gradient again. You may want to look at where you put the drawSprites. Normally, there would only be one case of that, but you could include one inside each conditional and that could also work depending on what you are trying to do.

Hope this helps, but check back in if you still aren’t able to get it to work.

Mike
