Sphero JavaScript Notes

Read about programming Sphero robots in javaScript

Part 1: Get Started

  1. When was JavaScript invented? __________
  2. How did adding JavaScript to web pages improve the world wide web? ___________________________________
  3. Describe what these lines of code do
    async function startProgram() {          //______________________________________
           await speak("Hello World", true); //______________________________________
           setMainLed({ r: 0, g: 0, b: 255}); //______________________________________
           setSpeed(60.0);                    //______________________________________
           await delay (2.0);                //______________________________________
           setSpeed(0.0);                   //______________________________________
           }
        
  4. How fast does the code stream between your device and the robot? _______
  5. What are 2 reasons why they stream the instructions instead of loading them onto the robot? ____________________________
  6. What is syntax? ____________________________________
  7. Is JavaScript case sensitive? _______
  8. What are the 3 commands needed to start a program? ____________________________________
  9. What punctuation contains all program code except global functions and variables? _____
  10. What indicates a comment? ______
  11. What ends a statement? ____
  12. When do you use a tab? ____________________________________________________
  13. What must be done to fix this program? _________________________________________
      async function startProgram(){
        setSpee(188.0)
    //!ReferenceError: Can't find variable: setSpee!
        setMainLed({ r: 0, g: 255, b: 0 });
        delay(2);
    }
  14. For the 3 data types used in Javascript, give an exampe of each
    1. number
    2. string
    3. boolean
  15. What is the special type for each of these cases:
    1. when something is defined as nothing _______
    2. when a variable has never been defined ____________________
    3. a new data type for advanced users _______________________

Part 2: Movement

  1. Sphero robots move with 3 basic instructions: _____________, ______________ and ____________
  2. Write the code to make the robot roll 180 degrees at a speed of 150 for 3 seconds ______________________________________
  3. Why do they use the values of 0 to 255? _____________________________
  4. What command is the same as setSpeed(0) ________________________________
  5. What is the command to move to the right? _____________________________________
  6. What is the code to make the robot spin 2 times in 2 seconds? ______________________________
  7. how do you turn the stabilization on and off? ____________________________________

Look at the SDK documentation to answer more questions