Created
September 3, 2017 17:12
-
-
Save jochri3/bc2865669c6be6149938b0216526cc3f to your computer and use it in GitHub Desktop.
null created by ChrisLis - https://repl.it/HaIs/29
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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