175k views
3 votes
The lettuce is scattered all over the garden.

Travel down each path until you reach a head of lettuce, then continue to pick it while
there is still some left.
This is vety hard this is level 4 number 10 on code.org plsss help me

User JjNford
by
4.2k points

1 Answer

4 votes

Answer:

Step-by-step explanation:

Coding is all about logic, since I do not have the actual problem from the website I will guide you on how to solve this.

Since you need to go a certain direction you will need to indicate to the character which direction to go. Next, we need to prevent the player from travelling through a wall, we can accomplish this using an IF/ELSE statement. IF the next block in that direction is a wall then do not move forward, ELSE move forward. We would call this statement every time the player tries to move in any direction. Finally, once we reach the lettuce we need to continue picking it until there is no more. To do this we use a While loop, that checks to see if there is any more lettuce, if there is it will run the code to pick up lettuce, if there is NO more then the While loop will exit. That would be the entire code.

User Gstroup
by
3.6k points