Skip to content

Instantly share code, notes, and snippets.

@McLarenCollege
Last active March 9, 2022 03:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save McLarenCollege/a7734c7e5def2faf1d68fe098d183e42 to your computer and use it in GitHub Desktop.
Save McLarenCollege/a7734c7e5def2faf1d68fe098d183e42 to your computer and use it in GitHub Desktop.
Exercise : Sum from a to b

Part1

Create a function with two parameters a and b that calculates the sum of all the numbers between a and b and returns it. Both a and b are included in the sum.You can assue that a will be smaller than b.

CODE TEMPLATE


// write your code here
console.log(sumBetween(5, 8));//
console.log(sumBetween(6, 12));//63

Part2

Modify the function in Part1 to include the possibility when a is greater than b

console.log(sumBetween(10, 8));//27

Part3

Modify the function to include the possibility that a can be equal to b. In that case the function should just return either of the two numbers.

console.log(sumBetween(6, 6));//6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment