2016-03-26 00:47:20 +01:00
|
|
|
# compass challenges
|
|
|
|
|
2016-11-02 01:44:37 +01:00
|
|
|
Display the direction that the @boardname@ is facing using the compass
|
2016-03-26 00:47:20 +01:00
|
|
|
|
|
|
|
## Before we get started
|
|
|
|
|
2016-04-13 17:27:45 +02:00
|
|
|
Complete the following [guided tutorial](/lessons/compass/activity), your code should look like this:
|
2016-03-26 00:47:20 +01:00
|
|
|
|
|
|
|
```blocks
|
|
|
|
basic.forever(() => {
|
2017-03-29 15:47:52 +02:00
|
|
|
let degrees = input.compassHeading();
|
|
|
|
if (degrees < 45 || degrees > 315) {
|
2016-03-26 00:47:20 +01:00
|
|
|
basic.showString("N");
|
|
|
|
}
|
|
|
|
else if (degrees < 135) {
|
|
|
|
basic.showString("E");
|
|
|
|
}
|
|
|
|
else if (degrees < 225) {
|
|
|
|
basic.showString("S");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
basic.showString("W");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
2017-09-07 22:42:08 +02:00
|
|
|
## Challenge 1
|
2016-03-26 00:47:20 +01:00
|
|
|
|
2016-11-01 18:42:42 +01:00
|
|
|
Instead of displaying `N` when the @boardname@ is pointing North, display a star to indicate the north star.
|
2016-03-26 00:47:20 +01:00
|
|
|
|
|
|
|
```blocks
|
|
|
|
basic.forever(() => {
|
2017-03-29 15:47:52 +02:00
|
|
|
let degrees = input.compassHeading();
|
|
|
|
if (degrees < 45 || degrees > 315) {
|
2016-03-26 00:47:20 +01:00
|
|
|
basic.showLeds(`
|
|
|
|
# . # . #
|
|
|
|
. # # # .
|
|
|
|
# # # # #
|
|
|
|
. # # # .
|
|
|
|
# . # . #`);
|
|
|
|
}
|
|
|
|
else if (degrees < 135) {
|
|
|
|
basic.showString("E");
|
|
|
|
}
|
|
|
|
else if (degrees < 225) {
|
|
|
|
basic.showString("S");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
basic.showString("W");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
* Run your code to see if it works as expected
|
|
|
|
|
2017-09-07 22:42:08 +02:00
|
|
|
## Challenge 2
|
2016-03-26 00:47:20 +01:00
|
|
|
|
|
|
|
Instead of displaying just `N`, `W`, `S`, or `E`, display the full word.
|
|
|
|
|
|
|
|
```blocks
|
|
|
|
basic.forever(() => {
|
2017-03-29 15:47:52 +02:00
|
|
|
let degrees = input.compassHeading();
|
|
|
|
if (degrees < 45 || degrees > 315) {
|
2016-03-26 00:47:20 +01:00
|
|
|
basic.showString("NORTH");
|
|
|
|
}
|
|
|
|
else if (degrees < 135) {
|
|
|
|
basic.showString("EAST");
|
|
|
|
}
|
|
|
|
else if (degrees < 225) {
|
|
|
|
basic.showString("SOUTH");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
basic.showString("WEST");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
* Run your code to see if it works as expected
|
|
|
|
|
2017-09-07 22:42:08 +02:00
|
|
|
## Challenge 3
|
2016-03-26 00:47:20 +01:00
|
|
|
|
|
|
|
Display your own unique message for each direction.
|
|
|
|
|