0
0
Javascriptprogramming~15 mins

Function execution flow in Javascript - Mini Project: Build & Apply

Choose your learning style9 modes available
Function Execution Flow
πŸ“– Scenario: Imagine you are building a simple calculator that adds two numbers. You want to understand how functions work step-by-step in JavaScript.
🎯 Goal: You will create a function that adds two numbers, call it with specific values, and print the result. This will help you see how the function runs from start to finish.
πŸ“‹ What You'll Learn
Create a function named addNumbers that takes two parameters: a and b
Inside the function, return the sum of a and b
Create two variables named num1 and num2 with values 5 and 7 respectively
Call the function addNumbers with num1 and num2 as arguments and store the result in a variable named result
Print the value of result to the console
πŸ’‘ Why This Matters
🌍 Real World
Functions help organize code into reusable blocks. This is useful in calculators, games, websites, and many programs.
πŸ’Ό Career
Understanding function execution flow is essential for any programming job. It helps you write clear, reusable, and testable code.
Progress0 / 4 steps
1
Create the function addNumbers
Write a function named addNumbers that takes two parameters called a and b. Inside the function, return the sum of a and b.
Javascript
Need a hint?

Use the function keyword to create a function. Return the sum using return a + b;.

2
Create variables num1 and num2
Create two variables named num1 and num2 and set them to 5 and 7 respectively.
Javascript
Need a hint?

Use const to create variables and assign the numbers 5 and 7.

3
Call addNumbers and store the result
Call the function addNumbers with num1 and num2 as arguments. Store the returned value in a variable named result.
Javascript
Need a hint?

Call the function by writing addNumbers(num1, num2) and save it in result.

4
Print the result
Print the value of the variable result to the console using console.log.
Javascript
Need a hint?

Use console.log(result); to show the sum in the console.