# CSD Lesson 13 Bubble 2 Predict not working as I'd expect?

**URL:** <https://forum.code.org/t/csd-lesson-13-bubble-2-predict-not-working-as-id-expect/31530>\
**Category:** CS Discoveries\
**Tags:** csd-unit-3-lesson-13\
**Created:** [October 24, 2019, 12:34am UTC](https://forum.code.org/t/csd-lesson-13-bubble-2-predict-not-working-as-id-expect/31530 "2019-10-24T00:34:33Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![andrea.burgess](https://avatars.discourse-cdn.com/v4/letter/a/fbc32d/32.png) [@andrea.burgess](https://forum.code.org/u/andrea.burgess)\
**Post date:** [October 24, 2019, 12:34am UTC](https://forum.code.org/t/csd-lesson-13-bubble-2-predict-not-working-as-id-expect/31530/1 "2019-10-24T00:34:33Z")

</div>

Am I mis-reading the code?  
Seems to me that the balloon should only grow if I press the space bar.  
If I just let it run and press nothing, it still grows.  
If I press the space bar, it seems to shrink and then grow

---

<div class="post-metadata">

**Author:** ![karenma](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/karenma/32/4924_2.png) [@karenma](https://forum.code.org/u/karenma)\
**Post date:** [October 25, 2019, 12:40am UTC](https://forum.code.org/t/csd-lesson-13-bubble-2-predict-not-working-as-id-expect/31530/2 "2019-10-25T00:40:41Z")

</div>

Hi Andrea,

When the program starts, the balloon will be flipped and scale up with a negative scale value. Once you press and hold the spacebar the balloon will decrease in size, flip upright and begin to increase in size. This happens when the condition is true. When you release the spacebar, the balloon decreases in size because the condition is false.

I hope this makes since,  
Karen

---

<div class="post-metadata">

**Author:** ![andrea.burgess](https://avatars.discourse-cdn.com/v4/letter/a/fbc32d/32.png) [@andrea.burgess](https://forum.code.org/u/andrea.burgess)\
**Post date:** [November 15, 2019, 7:37pm UTC](https://forum.code.org/t/csd-lesson-13-bubble-2-predict-not-working-as-id-expect/31530/3 "2019-11-15T19:37:53Z")

</div>

I’m afraid I’m still not following.  
What part of the code is making it flip?  
To me, the IF statement  
if (keyDown(“space”)) {  
balloon.scale = balloon.scale + 0.02;

would make the balloon grow - the else would make it shrink.

But if I do nothing it still grows.

---

<div class="post-metadata">

**Author:** ![infinitestasis](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/infinitestasis/32/5047_2.png) [@infinitestasis](https://forum.code.org/u/infinitestasis)\
**Post date:** [November 15, 2019, 11:30pm UTC](https://forum.code.org/t/csd-lesson-13-bubble-2-predict-not-working-as-id-expect/31530/4 "2019-11-15T23:30:04Z")

</div>

You may need to provide more context.

function draw() {  
if (keyDown(“space”)) {  
balloon.scale+=0.02;  
} else {  
balloon.scale=min(1, balloon.scale-0.02);  
}  
}

---

<div class="post-metadata">

**Author:** ![dmaletta](https://avatars.discourse-cdn.com/v4/letter/d/3d9bf3/32.png) [@dmaletta](https://forum.code.org/u/dmaletta)\
**Post date:** [November 16, 2019, 12:28am UTC](https://forum.code.org/t/csd-lesson-13-bubble-2-predict-not-working-as-id-expect/31530/5 "2019-11-16T00:28:27Z")

</div>

I too am not following this…

---

<div class="post-metadata">

**Author:** ![dmaletta](https://avatars.discourse-cdn.com/v4/letter/d/3d9bf3/32.png) [@dmaletta](https://forum.code.org/u/dmaletta)\
**Post date:** [November 16, 2019, 12:40am UTC](https://forum.code.org/t/csd-lesson-13-bubble-2-predict-not-working-as-id-expect/31530/6 "2019-11-16T00:40:00Z")

</div>

I just figured it out… when the space isn’t pressed, the scale is decreasing… so as soon as it starts running the scale is going down… when the scale goes negative, the balloon turns upside down… then it gets MORE negative when you’re not pressing the space bar which actually makes it just larger and upside down… this is a TERRIBLE example for students and I’m going to skip it!!! An additional condition inside of the negative block for scale greater than 0 would make more sense!

---

<div class="post-metadata">

**Author:** ![achan](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/achan/32/7354_2.png) [@achan](https://forum.code.org/u/achan)\
**Post date:** [March 28, 2022, 8:19pm UTC](https://forum.code.org/t/csd-lesson-13-bubble-2-predict-not-working-as-id-expect/31530/7 "2022-03-28T20:19:15Z")

</div>

Yes, why does a negative scale value cause the balloon to flip & start growing?  
At first, I thought it was “subtracting a negative which is adding a positive” but it actually reads as “negative” subtract “positive 0.01” so that’s not it. I forward the code to my CS engineer friend. He couldn’t give me an answer either ☹

---

<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:** [March 29, 2022, 3:23am UTC](https://forum.code.org/t/csd-lesson-13-bubble-2-predict-not-working-as-id-expect/31530/8 "2022-03-29T03:23:25Z")

</div>

This happens due to how the javascript library (p5.js) was programmed to handle negative scales. From [Digital Harbor](https://learn.digitalharbor.org/courses/creative-programming/lessons/p5-js-transformations-scale-2/#:~:text=Negative%20Scale&text=This%20essentially%20inverts%20the%20axis,left%20instead%20of%20the%20right.)

> The scale() command can receive negative parameters, such as `scale(-1, -2)` . This essentially _inverts the axis_ , meaning that the x and/or y values would be drawn in the opposite direction. For example, if you were to use a negative value parameter for the x value, the shape would be drawn with the x value pointing to the left instead of the right. Likewise if you use a negative value parameter for the y value, the shape would be drawn as if the y axis points up instead of down.

As a result, once the scale reaches zero, it has no dimension, but a negative scale inverts both the x and y axis and it starts growing again. It can be used to mirror an object if you want to create a reflection of an object, but I usually add a conditional to “handle” negative scales when I just want an object to shrink to a scale of zero and disappear.

Hope this helps a little…

Mike

---

<div class="post-metadata">

**Author:** ![achan](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/achan/32/7354_2.png) [@achan](https://forum.code.org/u/achan)\
**Post date:** [March 29, 2022, 10:36pm UTC](https://forum.code.org/t/csd-lesson-13-bubble-2-predict-not-working-as-id-expect/31530/9 "2022-03-29T22:36:07Z")

</div>

Thanks Mike, it does help. I also got better clarification from my friend.
