Unit 1 Lesson 11 Debugging

The task is to have the console log show the painter’s status as it moves.
All of my students code runs 4 times and stops.
Once we noticed we started to play with the code to get it to update continuously till the painter reaches the end.
Any thoughts as to why the console log only updates 4 times?

May you show me the code?
It could be that it needs to run more than 4 times, but I can’t help you if you can’t send me the code.

@fayecd - Thank you for reaching out to the forum. I don’t want to assume, but are you referring to Unit 1 Lesson 11 Level 3? If so, the painter in my teacher example shows the updates for each state in which the painter changes direction.

Please refer to the For Teacher Section where the example solution may be found.

Please let us know if this helps answer your question. You also contact support@code.org if you believe their is a coding error.

Yes that is the lesson I am referring to
here is the link to the code

The code works even with the teacher’s example of the code. This was more splitting of hairs on the way the question is worded. It states that the “status of the myPainterPlus object as it moves” yet it only gives the status 4 times not continuously

My students were trying to get it to work showing the status as it moves.
Not sure if I am explaining the wording and how they took it vs the way the program actually works (showing status only 4 times)

Task : 1. Use the printStatus() method while navigating the maze to print the current status of the myPainterPlus object as it moves.

@fayecd Thanks for sharing a link to your code!

I think this is a perfect example to model tracing your code with students. Here is what I see:

  1. On line 12 you call printStatus(). If that is printing 4 times, that must mean the while loop is running 4 times.
  2. I also see that the PainterPlus object is moving much more than 4 times. So that must mean that each iteration through the while loop is doing more than moving the painter once.
  3. On line 13 you have moveOrTakePaint(). I wasn’t 100% sure what that method did so I went to look in the PainterPlusclass to understand that method.
  4. moveOrTakePaint()method also has a while loop inside it. This method moves the painter as far as they can move OR takes the paint. So, if I wanted to see where the painter was during this method, I would need to call the printStatus() method inside the moveOrTakePaint() method. Then I would be able to see the location of the painter every time it moved.

I hope that helps!

1 Like

Thank you Kaitie!
We looked at it today and they saw why it was doing that and how to change it if they wanted to see more♥

1 Like