# Unit 3 Lesson 16 Level 8

**URL:** <https://forum.code.org/t/unit-3-lesson-16-level-8/33815>\
**Category:** Unit and Lesson Discussion\
**Created:** [December 1, 2020, 10:21pm UTC](https://forum.code.org/t/unit-3-lesson-16-level-8/33815 "2020-12-01T22:21:30Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![ukolacha](https://avatars.discourse-cdn.com/v4/letter/u/df788c/32.png) [@ukolacha](https://forum.code.org/u/ukolacha)\
**Post date:** [December 1, 2020, 10:21pm UTC](https://forum.code.org/t/unit-3-lesson-16-level-8/33815/1 "2020-12-01T22:21:30Z")

</div>

Hello!  
Was wondering if anyone has a solution to Level 8 in this lesson.  
I have written this so far:  
var ghost = createSprite(200,300);  
ghost.setAnimation(“ghost”);

function draw() {  
// Wrap the movement lines in two conditionals  
if (World.mouseX \>= 200) {  
ghost.x = ghost.x + 3;  
[//chick.x](https://chick.x) = 350;  
}  
if ((World.mouseX) \< 200) {  
ghost.x = ghost.x - 3;  
}

drawSprites();

Need help, so the ghost does not move when the mouse is not moving.

Thanks in advance!  
Usha

---

<div class="post-metadata">

**Author:** ![mkmietowicz](https://sea2.discourse-cdn.com/flex016/user_avatar/forum.code.org/mkmietowicz/32/6322_2.png) [@mkmietowicz](https://forum.code.org/u/mkmietowicz)\
**Post date:** [December 2, 2020, 7:31am UTC](https://forum.code.org/t/unit-3-lesson-16-level-8/33815/2 "2020-12-02T07:31:09Z")

</div>

Hi @ukolacha,

Let’s try to break down what the question is asking: it says

> make the ghost move either left or right depending on the position of the mouse pointer.

So we know that we want the ghost to move right if the mouse is to the right of the ghost, and we want the ghost to move left if the mouse is to the left of the ghost.

We’re also told

> - Write at least two if-statements to check for the location of the mouse.
> - Make the ghost move in a different direction for each mouse location.

So, what two values can we compare to determine whether the mouse pointer is to the left or right of the ghost sprite? Then, based on that, how will that determine the way the ghost moves?

Reply here if you need further assistance with this!

–Michael K.

---

<div class="post-metadata">

**Author:** ![ukolacha](https://avatars.discourse-cdn.com/v4/letter/u/df788c/32.png) [@ukolacha](https://forum.code.org/u/ukolacha)\
**Post date:** [December 2, 2020, 4:58pm UTC](https://forum.code.org/t/unit-3-lesson-16-level-8/33815/4 "2020-12-02T16:58:22Z")

</div>

Thanks for your prompt response. I was able to debug this last night.  
Usha

---

<div class="post-metadata">

**Author:** ![gchristianson](https://avatars.discourse-cdn.com/v4/letter/g/ce73a5/32.png) [@gchristianson](https://forum.code.org/u/gchristianson)\
**Post date:** [June 21, 2021, 2:01pm UTC](https://forum.code.org/t/unit-3-lesson-16-level-8/33815/5 "2021-06-21T14:01:30Z")

</div>

@mkmietowicz  
In the animation above the workspace on Unit 3 lesson 16 level 8B, it appears the ghost does not move when the mouse is directly over the sprite. Is the lesson asking us to use the sprite’s current location to determine whether to move? I checked the help section and it discusses variables. Is there a way to use variables in this example?  
Thanks in advance for your help-

---

<div class="post-metadata">

**Author:** ![gchristianson](https://avatars.discourse-cdn.com/v4/letter/g/ce73a5/32.png) [@gchristianson](https://forum.code.org/u/gchristianson)\
**Post date:** [June 21, 2021, 2:05pm UTC](https://forum.code.org/t/unit-3-lesson-16-level-8/33815/6 "2021-06-21T14:05:16Z")

</div>

@mkmietowicz

Disregard. I figured it out:

if (World.mouseX \> ghost.x) {  
ghost.x = ghost.x + 5;  
}  
if (World.mouseX \< ghost.x) {  
ghost.x = ghost.x - 5;
