0
0
Javascriptprogramming~15 mins

Function parameters in Javascript - Mini Project: Build & Apply

Choose your learning style9 modes available
Function parameters
πŸ“– Scenario: You are creating a simple calculator that adds two numbers. You will write a function that takes two numbers as inputs and returns their sum.
🎯 Goal: Build a function called addNumbers that takes two parameters and returns their sum. Then call the function with specific numbers and display the result.
πŸ“‹ What You'll Learn
Create a function named addNumbers with two parameters: num1 and num2
Inside the function, return the sum of num1 and num2
Call the function with the numbers 5 and 7
Print the result using console.log
πŸ’‘ Why This Matters
🌍 Real World
Functions with parameters are used everywhere in programming to reuse code and perform tasks with different inputs.
πŸ’Ό Career
Understanding how to write and use functions with parameters is essential for any programming job, as it helps build clean and efficient code.
Progress0 / 4 steps
1
Create the function skeleton
Write a function named addNumbers that takes two parameters called num1 and num2. For now, leave the function body empty.
Javascript
Need a hint?

Use the function keyword followed by the function name and parentheses with parameters.

2
Add the return statement
Inside the addNumbers function, write a return statement that returns the sum of num1 and num2.
Javascript
Need a hint?

Use return num1 + num2; to send back the sum.

3
Call the function with numbers
Create a variable called result and assign it the value returned by calling addNumbers with the numbers 5 and 7.
Javascript
Need a hint?

Use const result = addNumbers(5, 7); to call the function and save the answer.

4
Display the result
Use console.log to print the value of the variable result.
Javascript
Need a hint?

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