02-01-spin-a-star.js 4.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /**
  2. Ninjas code their first function by using the built in GDP spin function. They reference an object by name and
  3. investigate how changing parameters affect the targeted object.
  4. New Vocabulary and Concepts
  5. * GDP spin() function
  6. * Javascript semicolons
  7. * parameters
  8. Reinforced Vocabulary and Concepts
  9. * Functions
  10. * GDP Objects and Properties
  11. * Object Names
  12. Sensei Notes
  13. * This activity is the Ninja's first introduction into coding.
  14. * The Ninjas need to add and customize a star.
  15. * They may decorate the scene, but they must have one object named "star" to complete the coding portion
  16. of the activity.
  17. * All the coding in White Belt takes place in the scene's update every frame event. If you see a Ninja coding on
  18. an object or in a different event, help them move their code to the right place.
  19. * Reference the Coded Messages and Ninja Says activities when explaining functions. Functions, as well as
  20. objects, have unique case sensitive names. The GDP only understands spin(object, rate), so stress that the
  21. Ninja needs to make sure they have the exact name and the correct parameters. You can reference the
  22. Debug tab if you feel the Ninja will understand it.
  23. * Semicolons are not required for JavaScript code to run and execute but using them is a good practice to help
  24. communicate the concept of statements.
  25. * This activity has a lot of new vocabulary, so consider writing definitions on the board and having the Ninja
  26. come up with examples or their own ways to explain the concepts.
  27. Solution Steps
  28. 1 Make sure the Ninja can navigate to the correct scene on their own.
  29. 2 Make sure the Ninja adds only one star to the scene. If they want to add more shapes, then tell them they
  30. can do that after they complete the lesson content. It is best if the scene is not cluttered with other objects.
  31. 3 Let the Ninja customize their star. Make sure that it you will be able to see it being rotated . The rotation of a
  32. star with a very large number of points or a similar inner and outer radius will be difficult to see. The object
  33. name is important from this activity on. Make sure that the Ninja keeps this object's default name of star.
  34. 4 Make sure the Ninja is in the scene's update every frame event. All coding in the White Belt will take place
  35. here, so it is essential that the Ninjas develop a habit of checking where they are before they start coding.
  36. S Instruct the Ninjas to copy the code exactly. Make sure they know the location of each character on the
  37. keyboard. Explain the purpose of a semicolon.
  38. spin(star, 10)
  39. 6 Ask the Ninja if they predicted correctly. If not, have them explain what happened. Ask the Ninja to connect
  40. the result in the scene to the code.
  41. 7 Explain the three pieces of the spin function. Explain the three rules of functions. If the Ninja doesn't seem to
  42. understand, work with them to come up with real world actions that could have parameters that alter the
  43. outcome. For example, riding a bike could have a parameter of speed.
  44. 8 Make sure the ninja changes only the second parameter. The star should spin the same direction, just
  45. significantly faster.
  46. spin(star, 10);
  47. spin(star, 200);
  48. 9 Make sure the ninja changes only the second parameter. The star should spin the same direction, just
  49. significantly slower.
  50. Code Diff:
  51. spin(star, 200);
  52. spin(star, l);
  53. 10 Ask the Ninja how they feel about writing their first line of code. Ask them to explain what each part of the
  54. code does.
  55. */
  56. spin(star, 1);
  57. /**
  58. Sensei Stops
  59. 5 Tell a Sensei what you think is going to happen when you start your game. Will the star move? How?
  60. Make sure that the Ninja has the correct line of code. Before the Ninja plays the game, they should predict
  61. what will happen to their star. No matter what their answer is, ask them why they thought that. If they have
  62. a fundamental misunderstanding, reference the Ninja Says activity to get them back on the right path. If the
  63. Ninja pressed play too early and has already seen what happens to the star, get them to explain how the line
  64. of code caused the star to spin.
  65. 10 Tell a Sensei what happens when you change the second parameter of the spin function. What happens
  66. when your number is big? What about o smo// number?
  67. It is important for the Ninja to make the connection that we are spinning the star at a rate. If we change the
  68. rate, then the speed of the spin changes. They should be able to explain that a bigger number makes it spin
  69. faster and a lower number makes it spin slower. Encourage them to experiment with different numbers.
  70. */