23.0k views
4 votes
KittyBot is a programmable robot that obeys the following commands:

NameDescriptionwalkForward()Walks forward one space in the grid.turnLeft()Rotates left 90 degrees (without moving forward).turnRight()Rotates right 90 degrees (without moving forward).
KittyBot is currently positioned in the second row and second column of the grid, and is facing the right side of the grid.
We want to program KittyBot to reach the ball of yarn, located in the fifth row and fifth column.
Which of these code segments accomplishes that goal?

User Jhasse
by
6.5k points

1 Answer

3 votes

Final answer:

To program KittyBot to reach the ball of yarn, located in the fifth row and fifth column, you would need to use a loop that turns right and walks forward three times.

Step-by-step explanation:

To program KittyBot to reach the ball of yarn, located in the fifth row and fifth column, you would need to use the code segment:

for (let i = 0; i < 3; i++) {
turnRight();
walkForward();
}

This code segment consists of a loop that repeats three times. In each iteration of the loop, KittyBot turns right and then walks forward, effectively moving the robot to the next square in the grid. By repeating this process three times, KittyBot will reach the fifth row and fifth column, facing the ball of yarn.

User Dimoniy
by
6.4k points