Created
November 20, 2018 20:14
-
-
Save tuvo1106/a4c56619f3af528b6bc6984f93dc0b71 to your computer and use it in GitHub Desktop.
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
const addWithLoops = x => { | |
// initializes variable sum to 0 | |
let sum = 0 | |
// loop through all numbers 0 to 100 | |
for (let i = 0; i <= x; i++) { | |
// checks each number if is divisible by 2 | |
if (i % 2 === 0) { | |
// adds number to variable sum if it is | |
sum += i | |
} | |
} | |
// return grand total | |
return sum | |
} | |
console.log(addWithLoops(100)) // 2550 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment