Skip to content

Instantly share code, notes, and snippets.

@jalehman
Created January 11, 2016 22:13
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 jalehman/217e8309be1eff2a219d to your computer and use it in GitHub Desktop.
Save jalehman/217e8309be1eff2a219d to your computer and use it in GitHub Desktop.
// 1. Compute the sum of squares up to `n`, where n is 10.
var n = 10;
var i = 0;
var result = 0;
while (i < n) {
result = result + (i * i);
i++;
}
console.log(result);
// 2. How about the sum of cubes of even numbers up to 10?
n = 10;
i = 0;
result = 0;
while (i < n) {
result = result + (i * i * i);
i = i + 2;
}
console.log(result);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment