Get some more practice with conditional by helping the early bird catch the worm and return to nest!
- Heading sets the angle of direction to travel in (relative to the grid)
- Use a condition to change the heading at the right moment.
Set your angle on target!
xreturns your current x position on the grid. You can add a condition that checks where
You can also examine
y. An if-block can be changed to an if-else block to do something different when the condition isn't true.
ifblock can have multiple conditions in it known as
else ifchecks another condition if the first condition wasn't true. For example, let's say you encounter a dangerous dragon:
"If" you have a Bazooka, you should shoot the dragon.
"Else if" you have a sword, you should fight the dragon.
"Else", you should run for your life.
If the first condition is true, you won't even check the other conditions. This means you have to set up the order of your If, else if, else statements carefully.
- Setup your conditions carefully to solve this.
- This problem can be solved in a few ways. One way is to use the And condition. An "And" condition is true only if both conditions in it are true. For example:
"If" you have a Bazooka "And" you have ammunition, you should shoot the dragon.
If either condition is false, the overall condition is false, so the code inside the if statement will be skipped.
- Use an And condition and multiple "Else If" statements to solve this problem.
- Get the worm and return to your nest!