One of my students was working on this activity (draw two aliens in space), although she used just one bee. Her code wouldn’t work at all (see attachment), so she copied the Example Solution code exactly, and even refreshed the page and restarted the browser. Still didn’t work. Any thoughts on why her code is wrong and why the solution code didn’t work?
Hi @gellis1,
In order to better help you, we’ll need you to share the code to this student’s work. You’ll want to use the Share option in order to provide a direct link to the student code. It also helps if you could let us know what the student expected to happen verses what is actually happening when the code is run. If you could provide this information then we can hopefully help you debug the problem. Thanks!
You can’t put a period in a variable name. The variable name does NOT have to be the same thing as the name of the animation. In this case, the animation is “bee.png_1”. Just name your variable “bee”
In line 3, you are setting the animation, but you are not specifiying which sprite to set the animation for.
You are also missing a semi-colon at the end of line 3
this is what the code should look like:
background(“pink”); var bee = createSprite(175, 175); bee.setAnimation(“bee.png_1”); drawSprites();
There is nothing at this time that I see in the screenshot of your code. It would be best if you find the SHARE button, copy the link, and paste it here to help with this specific puzzle.
I recreated an example. Hope this helps. If you want to share your link, we can take a look at that. HERE is my example.
Michelle
Thank you for your reply. Unfortunately, it didn’t work…and the funny thing is that it didn’t work even if we copied the suggested solution word for word.
Here is my student’s code:
She was hoping for one bee to appear instead of two aliens.
One thing that did work, however, was to eliminate the period in the name of the sprite (i.e. call it bee, not bee.png).
When I open the project, I see:
background(“pink”);
var bee.png_1 = createSprite(175, 175);
setAnimation(“bee.png_1”);
drawSprites();
So the fixes that @kammie.dill suggested are correct. #1: Your variable name can’t have a period so should just be “bee”. (Here are the rules for creating variable names). #2: bee.setAnimation(“bee.png_1”); (not setAnimation(“bee.png_1”)
The correct code is
background(“pink”);
var bee = createSprite(175, 175);
bee.setAnimation(“bee.png_1”);
drawSprites();
@melynn your code and mine look exactly the same… and it works for me.
My code came directly from my code.org project and it worked with no errors. @gellis1 - Carefully check all the lines of code…even if you copy and paste, a simple missing “;” can cause errors.