# Conditionals help

**URL:** https://forum.code.org/t/conditionals-help/34637
**Category:** Coding and Debugging Help
**Created:** [April 26, 2021, 4:15pm UTC](https://forum.code.org/t/conditionals-help/34637 "2021-04-26T16:15:33Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![gretchenreeves](https://avatars.discourse-cdn.com/v4/letter/g/7cd45c/32.png) [@gretchenreeves](https://forum.code.org/u/gretchenreeves)
#### Post date: [April 26, 2021, 4:15pm UTC](https://forum.code.org/t/conditionals-help/34637/1 "2021-04-26T16:15:33Z")

</div>

I have a student who is creating a game in Unit 3, Lesson 27. He’s trying to add a conditional so that when his character reaches the finish line, the words, “you win” appear on the screen. We have the conditional set up but it isn’t working. Any ideas?

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

---

<div class="post-metadata">

### Author: ![jdonwells](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/jdonwells/32/7900_2.png) [@jdonwells](https://forum.code.org/u/jdonwells)
#### Post date: [April 26, 2021, 4:33pm UTC](https://forum.code.org/t/conditionals-help/34637/2 "2021-04-26T16:33:13Z")

</div>

It isn’t shared properly.

---

<div class="post-metadata">

### Author: ![gretchenreeves](https://avatars.discourse-cdn.com/v4/letter/g/7cd45c/32.png) [@gretchenreeves](https://forum.code.org/u/gretchenreeves)
#### Post date: [April 26, 2021, 4:59pm UTC](https://forum.code.org/t/conditionals-help/34637/3 "2021-04-26T16:59:05Z")

</div>

That’s the only link I can copy. Here’s the copy of the code…

var sprite = createSprite(200, 200);  
sprite.setAnimation(“sports\_track\_1”);  
// Create your variables here  
var person1 = createSprite(70, 350);  
person1.scale = 0.3;  
person1.setAnimation(“red\_hoodie\_hands\_in\_hoodie\_1”);  
var person3 = createSprite(270, 350);  
person3.scale = 0.3;  
person3.setAnimation(“blue\_hoodie\_hands\_in\_hoodie\_1”);  
var person4 = createSprite(200, 350);  
person4.scale = 0.3;  
person4.setAnimation(“blue\_shirt2\_1”);  
var person5 = createSprite(135, 350);  
person5.scale = 0.3;  
person5.setAnimation(“brown\_sweater\_hands\_in\_pockets\_1”);  
var person6 = createSprite(330, 350);  
person6.scale = 0.3;  
person6.setAnimation(“yellow\_shirt\_hands\_in\_pockets2\_1”);  
var finishline = createSprite(200, 5);  
finishline.scale = 0.6;  
finishline.setAnimation(“finish line.jpg\_1”);

// Create your sprites here

function draw() {  
if (keyWentDown(“space”)) {  
person1.setAnimation(“red\_hoodie\_hands\_in\_hoodie\_1”);  
person1.y = person1.y - 13;  
}  
if (keyDown(“space”)) {  
person3.setAnimation(“blue\_hoodie\_hands\_in\_hoodie\_1”);  
person3.velocityY = -1;  
person4.setAnimation(“blue\_shirt2\_1”);  
person4.velocityY = -2;  
person5.setAnimation(“brown\_sweater\_hands\_in\_pockets\_1”);  
person5.velocityY = -2.5;  
person6.setAnimation(“yellow\_shirt\_hands\_in\_pockets2\_1”);  
person6.velocityY = -1.5;  
}  
if (person1.isTouching(finishline)) {  
fill(“black”);  
textSize(10);  
text(“you win”, 200, 200);  
}  
drawSprites();  
}  
indent preformatted text by 4 spaces

---

<div class="post-metadata">

### Author: ![jdonwells](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/jdonwells/32/7900_2.png) [@jdonwells](https://forum.code.org/u/jdonwells)
#### Post date: [April 26, 2021, 6:11pm UTC](https://forum.code.org/t/conditionals-help/34637/4 "2021-04-26T18:11:15Z")

</div>

You could remix the project and then publish and post a link.

It is possible in games like these for one sprite to jump over another sprite without ever touching it. Sprites don’t move to every location in between. They jump.

---

<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: [April 27, 2021, 4:07am UTC](https://forum.code.org/t/conditionals-help/34637/5 "2021-04-27T04:07:10Z")

</div>

@gretchenreeves,

It appears you don’t have sharing enabled for your students. If you have the ability to enable the sharing and/or remix the project yourself and then send us the shared link, we are happy to take a look.

Because we can’t see the sprites and can’t visualize what is happening in a situation like this, the code itself won’t help us to troubleshoot as it isn’t likely a typo, but rather as @jdonwells says, a potential collision issue due to the velocity of the sprite that may be skipping over the finish line without making a direct hit.

If you can’t share, you may try “slowing down” the velocity which could cause a more direct collision.

Best wishes! If you can find a way to share it, we’d be happy to take a look at it.

Mike

---

<div class="post-metadata">

### Author: ![gretchenreeves](https://avatars.discourse-cdn.com/v4/letter/g/7cd45c/32.png) [@gretchenreeves](https://forum.code.org/u/gretchenreeves)
#### Post date: [April 27, 2021, 1:19pm UTC](https://forum.code.org/t/conditionals-help/34637/6 "2021-04-27T13:19:18Z")

</div>

I remixed and then shared the link below. I hope this one works.

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

---

<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: [April 27, 2021, 1:35pm UTC](https://forum.code.org/t/conditionals-help/34637/7 "2021-04-27T13:35:35Z")

</div>

@gretchenreeves,

I’ve played around with this and was able to get it to work. There’s nothing wrong with the code, but the “finish\_line” sprite is somehow corrupted. I’ve seen this happen before and I can’t figure out why or how it gets that way, but here’s what I did to get it to work.

1. Duplicate the finish line
2. Delete the original finish line
3. rename the copy to be the same as the original

Alternately, you could delete it and try uploading it again.

Good luck!

Mike
