function drawLine(length = 0) {
// We don't need to do anything in the loop itself. This is honestly a little
// too "clever" but it works to build a string of #s.
for(var line = ''; line.length < length; line += '#') {
}
// Bonus part:
// This checks if the number of #s will be even or not.
// It's called the "modulo operator". Think of it as "the remainder of
// dividing one number by the other".
// Thus:
//
// 0 % 2 is 0
// 1 % 2 is 1
// 2 % 2 is 0
// 3 % 2 is 1
// 4 % 2 is 0
var isEven = length % 2 === 0
return [line, isEven]
}
function main() {
// Draw 8 lines.
for (var i = 0; i < 8; i++) {
console.log(drawLine(i))
}
}
main()
Created
January 17, 2018 17:14
-
-
Save mikew/549476285c3a7c7c0c199b5de287ea3e to your computer and use it in GitHub Desktop.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment