-
-
Save AliceWonderland/46500f1cfb034deb39bc81509b5b14c4 to your computer and use it in GitHub Desktop.
3.1 Count by M created by smillaraaq - https://repl.it/GxOg/4
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
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