Skip to content

Instantly share code, notes, and snippets.

@easierbycode
Last active September 14, 2017 02:35
Show Gist options
  • Save easierbycode/0a6b66ca963723f151e7c7fda0d94849 to your computer and use it in GitHub Desktop.
Save easierbycode/0a6b66ca963723f151e7c7fda0d94849 to your computer and use it in GitHub Desktop.
Eloquent JavaScript
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 );
}
var poundSymbols = '#';
for ( i = 1; i < 7; i++ ) {
console.log( poundSymbols );
poundSymbols += '#';
}
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