Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprenda Challenge: Create a Sum Function | Functions in JavaScript
Introduction to JavaScript

bookChallenge: 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:

  1. Use 24, 12, and 32 for the first function call and store the result in the variable sum1.
  2. Use 12, 42, and 5 for the second function call and store the result in the variable sum2.

Finally, print the results of both function calls.

123456789
function sum(___, ___, ___) { ___ a + b + c; }; let sum1 = ___(___, ___, ___); let sum2 = ___(___, ___, ___); console.log("sum1 =", ___); console.log("sum2 =", ___);
copy

The output should be:

sum1 = 68
sum2 = 59
  1. Use the return keyword inside the function body.
  2. Use the function name to call this function.
  3. Choose values yourself.
123456789
function 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);
copy

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 6. Capítulo 6

Pergunte à IA

expand

Pergunte à IA

ChatGPT

Pergunte o que quiser ou experimente uma das perguntas sugeridas para iniciar nosso bate-papo

bookChallenge: 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:

  1. Use 24, 12, and 32 for the first function call and store the result in the variable sum1.
  2. Use 12, 42, and 5 for the second function call and store the result in the variable sum2.

Finally, print the results of both function calls.

123456789
function sum(___, ___, ___) { ___ a + b + c; }; let sum1 = ___(___, ___, ___); let sum2 = ___(___, ___, ___); console.log("sum1 =", ___); console.log("sum2 =", ___);
copy

The output should be:

sum1 = 68
sum2 = 59
  1. Use the return keyword inside the function body.
  2. Use the function name to call this function.
  3. Choose values yourself.
123456789
function 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);
copy

Tudo estava claro?

Como podemos melhorá-lo?

Obrigado pelo seu feedback!

Seção 6. Capítulo 6
some-alt