Skip to content

Instantly share code, notes, and snippets.

Created April 6, 2017 04:35
Show Gist options
  • Save anonymous/2f0ff4ada92a7f1c55d8bf59cf20a214 to your computer and use it in GitHub Desktop.
Save anonymous/2f0ff4ada92a7f1c55d8bf59cf20a214 to your computer and use it in GitHub Desktop.
3.1 Count by M created by smillaraaq - https://repl.it/GxOg/4
function count(n,m,direction){
//n is limit
//m is interval
//direction up or down
if(direction==="up"){
for(var i=m; i<=n; i+=m){
console.log(i);
}
}else{
for(var i=n; i>=0; i-=m){
console.log(i);
}
}
}
//count(11,3,"down");
function countWhile(n,m,direction){
//n is limit
//m is interval
//direction up or down
//debugger;
if(direction==="up"){
var output=0;
while(output < n){
output+=m;
console.log(output);
}
}else{
var output=n;
while(output >= 0){
console.log(output);
output-=m;
}
}
}
countWhile(11,3,"down");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment