Writing Functions
Parts of a Function
- Declaration: starts with the function keyword;
- Name: identifies the function (e.g.,
ninjaController,lootZigZag). - Parameters: variables inside parentheses that accept values when the function is called;
- Body: the block of code inside
{}containing the function's actions; - Return value: an optional value returned by the function. If omitted, the result is
undefined.
Example
ninja.js
ninjaController: controls the ninja by callinglootBox(ninja)twice and moving right four times;lootBox: groups a sequence of moves and sushi pickups into a reusable helper function;ninjaparameter: represents theninjaobject that provides methods likegoRight(),goUp(), andpickSushi().
Task
Swipe to start coding
Solution
Explore other courses in Catalog
Everything was clear?
Thanks for your feedback!
SectionΒ 3. ChapterΒ 2
ninja.js
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Awesome!
Completion rate improved to 3.57
Writing Functions
Swipe to show menu
Parts of a Function
- Declaration: starts with the function keyword;
- Name: identifies the function (e.g.,
ninjaController,lootZigZag). - Parameters: variables inside parentheses that accept values when the function is called;
- Body: the block of code inside
{}containing the function's actions; - Return value: an optional value returned by the function. If omitted, the result is
undefined.
Example
ninja.js
ninjaController: controls the ninja by callinglootBox(ninja)twice and moving right four times;lootBox: groups a sequence of moves and sushi pickups into a reusable helper function;ninjaparameter: represents theninjaobject that provides methods likegoRight(),goUp(), andpickSushi().
Task
Swipe to start coding
Solution
Explore other courses in Catalog
Everything was clear?
Thanks for your feedback!
SectionΒ 3. ChapterΒ 2
ninja.js