Sussion 10 Control Structures Functions
Sussion 10 Control Structures Functions
Functions
Web Development Essentials - Session 10
Session Overview
Learning Goals for Today:
● Conditional statements allow you to execute code based on whether a condition is true or false.
Example
Multiple Conditions (else-if)
What if there are more than two conditions?
● You can chain multiple conditions using else if for more complex decision-making.
Example
Logical Operators in Conditions
Logical Operators:
● Loops allow you to run the same block of code multiple times.
Types of Loops:
1. for loop
2. while loop
The for Loop
What is a for Loop?
Example:
The while Loop
Example:
Functions in JavaScript
What are Functions?
● A function is a block of code designed to perform a specific task. It can be reused multiple times by "invoking" it.
Declaring a Function:
● Parameters are variables that are passed into a function when it's called, allowing the function to work with different inputs.
Example:
Returning Values from Functions
What is a Return Statement?
● A return statement allows a function to return a value back to the calling code.
Example:
Hands-On Activity: Creating Functions
Goal: Write a function that accepts two numbers, adds them, and returns the result.
Instructions:
Infinite Loops: Make sure loop conditions eventually become false, or the loop will run indefinitely.
Forget to Call Functions: Remember to "invoke" the function to execute the code inside it.
Summary
What We Learned Today: