Skip to content

Instantly share code, notes, and snippets.

@jochri3
Created September 3, 2017 17:12
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 jochri3/bc2865669c6be6149938b0216526cc3f to your computer and use it in GitHub Desktop.
Save jochri3/bc2865669c6be6149938b0216526cc3f to your computer and use it in GitHub Desktop.
null created by ChrisLis - https://repl.it/HaIs/29
// Write a function that takes in an integer `num` and returns the sum of
// all integers between zero and num, up to and including `num`.
//
// Difficulty: easy.
function sum_nums(num) {
var sum=0;
for(var i=1;i<=num;i++)
{
sum +=i
}
return sum
}
// These are tests to check that your code is working. After writing
// your solution, they should all print true.
console.log("\nTests for //sum_nums")
console.log("===============================================")
console.log('sum_nums(1) == 1: ' + (sum_nums(1) == 1))
console.log('sum_nums(2) == 3: ' + (sum_nums(2) == 3))
console.log('sum_nums(3) == 6: ' + (sum_nums(3) == 6))
console.log('sum_nums(4) == 10: ' + (sum_nums(4) == 10))
console.log('sum_nums(5) == 15: ' + (sum_nums(5) == 15))
console.log("===============================================")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment