easierbycode
9/14/2017 - 1:43 AM

Eloquent JavaScript

Eloquent JavaScript

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 );
var poundSymbols	= '#';

for ( i = 1; i < 7; i++ ) {
  console.log( poundSymbols );
  poundSymbols += '#';
}
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 );
}