0
0
Javascriptprogramming~15 mins

Return values in Javascript - Mini Project: Build & Apply

Choose your learning style9 modes available
Return values
πŸ“– Scenario: You are creating a simple calculator function that adds two numbers and returns the result.
🎯 Goal: Build a function that takes two numbers, adds them, and returns the sum. Then display the result.
πŸ“‹ 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.
Call the function with the numbers 5 and 7 and store the result in a variable named result.
Print the value of result to the console.
πŸ’‘ Why This Matters
🌍 Real World
Functions that return values are used everywhere in programming to calculate results, process data, and send back answers.
πŸ’Ό Career
Understanding return values is essential for writing reusable code and building software that works correctly and efficiently.
Progress0 / 4 steps
1
Create the function addNumbers
Write a function named addNumbers that takes two parameters: a and b. Do not write the function body yet.
Javascript
Need a hint?

Use the function keyword followed by the name addNumbers and parameters a, b.

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

Use return a + b; to send back the sum.

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

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

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.