Skip to content

Latest commit

 

History

History
48 lines (37 loc) · 2.46 KB

File metadata and controls

48 lines (37 loc) · 2.46 KB

Module 4: Functions

Activity 1: Introduction to functions

  • Understanding the concept of functions and their importance in programming.
  • Exploring the syntax of function declaration and function expressions.
  • Learning about function names and best practices for naming functions.
  • Understanding the purpose of function documentation and comments.

Activity 2: Declaring and calling functions

  • Declaring functions with parameters and return statements.
  • Calling functions and passing arguments.
  • Understanding function scope and variable visibility.
  • Exploring function hoisting and function expressions.

Activity 3: Parameters and return values

  • Working with function parameters and understanding their role in passing data to functions.
  • Exploring different types of function parameters: required parameters, default parameters, and rest parameters.
  • Using return statements to return values from functions.
  • Understanding the concept of function purity and side effects.

Practice Exercises:

  1. Calculate the area of a circle:

    • Write a function called calculateArea that takes the radius of a circle as a parameter.
    • Inside the function, calculate the area of the circle using the formula: area = Math.PI * radius * radius.
    • Return the calculated area from the function.
    • Call the function with different radius values and log the result to the console.
  2. Reverse a string:

    • Write a function called reverseString that takes a string as a parameter.
    • Inside the function, reverse the order of characters in the string.
    • Return the reversed string from the function.
    • Call the function with different strings and log the result to the console.
  3. Check if a number is prime:

    • Write a function called isPrime that takes a number as a parameter.
    • Inside the function, check if the number is prime (i.e., divisible only by 1 and itself).
    • Return true if the number is prime, and false otherwise.
    • Call the function with different numbers and log the result to the console.

Estimated time to complete this module is approximately 4-6 hours.

To further enhance your learning, here are some additional resources: