Last active
September 14, 2017 02:35
-
-
Save easierbycode/0a6b66ca963723f151e7c7fda0d94849 to your computer and use it in GitHub Desktop.
Eloquent JavaScript
This file contains hidden or 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
var divisibleBy3 = function( num ) { return (num % 3) === 0 } | |
var divisibleBy5 = function( num ) { return (num % 5) === 0 } | |
for ( num = 1; num <= 100; num++ ) { | |
if ( divisibleBy3( num ) ) console.log( 'Fizz: ', num ); | |
if ( divisibleBy5( num ) && !divisibleBy3( num ) ) console.log( 'Buzz: ', num ); | |
if ( divisibleBy3( num ) && divisibleBy5( num ) ) console.log( 'FizzBuzz: ', num ); | |
} |
This file contains hidden or 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
var poundSymbols = '#'; | |
for ( i = 1; i < 7; i++ ) { | |
console.log( poundSymbols ); | |
poundSymbols += '#'; | |
} |
This file contains hidden or 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 flipNextChar( char ) { return (char === ' ') ? '#' : ' ' } | |
var chessBoard = ''; | |
var gridSize = 8; | |
var currentChar = ' '; | |
var currLineNbr = 1; | |
for ( i = 1; i <= gridSize; i++ ) { | |
for ( n = 1; n <= gridSize; n++ ) { | |
chessBoard += currentChar; | |
currentChar = flipNextChar( currentChar ); | |
if ( n == gridSize ) chessBoard += '\n'; | |
} | |
currentChar = flipNextChar( currentChar ); | |
} | |
console.log( chessBoard ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment