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