JavaScript: Compute the sum of three elements of a given array of integers of length 3
JavaScript Basic: Exercise-69 with Solution
Sum of 3 Elements in Array (Length 3)
Write a JavaScript program to compute the sum of three elements of a given array of integers of length 3.
The program takes an array of three integers as input and calculates the sum of these three elements. It then returns or displays the resulting sum.
Visual Presentation:

Sample Solution:
JavaScript Code:
Output:
62 21 -3
Live Demo:
Flowchart:

ES6 Version:
For more Practice: Solve these Related Problems:
- Write a JavaScript program that sums the three elements of an array only if the array length is exactly 3, otherwise returns an error.
- Write a JavaScript function that accepts an array of three integers and computes their sum using a loop or reduce method.
- Write a JavaScript program that validates the length of an array before calculating the sum of its three elements.
Improve this sample solution and post your code through Disqus.
Previous: JavaScript program to create a new string taking the first and last n characters from a given string.
Next: JavaScript program to rotate the elements left of a given array of integers of length 3.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.