Skip to content

Instantly share code, notes, and snippets.

@seanwiseman
Created February 27, 2023 13:53
Show Gist options
  • Select an option

  • Save seanwiseman/33b8599421e12ec627cc63c837b0c6db to your computer and use it in GitHub Desktop.

Select an option

Save seanwiseman/33b8599421e12ec627cc63c837b0c6db to your computer and use it in GitHub Desktop.
/*
We need a function called `calculateTotal` that will accept an array of numbers, then add them all up and return the total.
`hint` - maybe take a look at https://www.w3schools.com/js/js_loop_forin.asp .
Here are some examples that sound work:
Example 1:
const items = [
10,
25,
35,
]
> calculateTotal(items)
70
--------------
Example 2:
const items = [
5.5,
100,
34,
]
> calculateTotal(items)
139.5
--------------
Example 3:
const items = [
25,
100,
-10, // this could be a discount
]
> calculateTotal(items)
115
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment