Challenge: Create a Sum Function
Task
Implement a function sum that takes three arguments (a, b, and c) and returns their sum.
Next, call this function twice, using the following sets of arguments:
- Use
24,12, and32for the first function call and store the result in the variablesum1. - Use
12,42, and5for the second function call and store the result in the variablesum2.
Finally, print the results of both function calls.
123456789function sum(___, ___, ___) { ___ a + b + c; }; let sum1 = ___(___, ___, ___); let sum2 = ___(___, ___, ___); console.log("sum1 =", ___); console.log("sum2 =", ___);
The output should be:
sum1 = 68
sum2 = 59
- Use theΒ
returnΒ keyword inside the function body. - Use the function name to call this function.
- Choose values yourself.
123456789function sum(a, b, c) { return a + b + c; } let sum1 = sum(24, 12, 32); let sum2 = sum(12, 42, 5); console.log("sum1 =", sum1); console.log("sum2 =", sum2);
Everything was clear?
Thanks for your feedback!
SectionΒ 6. ChapterΒ 6
Ask AI
Ask AI
Ask anything or try one of the suggested questions to begin our chat
Suggested prompts:
Can you explain how the function works?
What would happen if I passed different numbers to the function?
Can I use this function for more than three numbers?
Awesome!
Completion rate improved to 2.33
Challenge: Create a Sum Function
Swipe to show menu
Task
Implement a function sum that takes three arguments (a, b, and c) and returns their sum.
Next, call this function twice, using the following sets of arguments:
- Use
24,12, and32for the first function call and store the result in the variablesum1. - Use
12,42, and5for the second function call and store the result in the variablesum2.
Finally, print the results of both function calls.
123456789function sum(___, ___, ___) { ___ a + b + c; }; let sum1 = ___(___, ___, ___); let sum2 = ___(___, ___, ___); console.log("sum1 =", ___); console.log("sum2 =", ___);
The output should be:
sum1 = 68
sum2 = 59
- Use theΒ
returnΒ keyword inside the function body. - Use the function name to call this function.
- Choose values yourself.
123456789function sum(a, b, c) { return a + b + c; } let sum1 = sum(24, 12, 32); let sum2 = sum(12, 42, 5); console.log("sum1 =", sum1); console.log("sum2 =", sum2);
Everything was clear?
Thanks for your feedback!
SectionΒ 6. ChapterΒ 6