Skip to content

Instantly share code, notes, and snippets.

@yomotsu
Created December 10, 2013 14:23
Show Gist options
  • Save yomotsu/7891341 to your computer and use it in GitHub Desktop.
Save yomotsu/7891341 to your computer and use it in GitHub Desktop.
fizzbuzz w/o 'if'
var c = document.createElement( 'canvas' );
c.width = 100;
c.height = 1000;
document.body.appendChild( c );
var ctx = c.getContext( '2d' );
ctx.font = '10px';
for ( var i = 0; i < 100; i ++ ) {
ctx.save();
ctx.fillText( ( i + 1 ), 0, i * 10 + 10 );
ctx.fillStyle = 'rgba(0, 0, 0, ' + ( ( ( i + 1 ) % 3 === 0 ) * 1 ) + ')';
ctx.fillText( 'fizz', 20, i * 10 + 10 );
ctx.fillStyle = 'rgba(0, 0, 0, ' + ( ( ( i + 1 ) % 5 === 0 ) * 1 ) + ')';
ctx.fillText( 'buzz', 40, i * 10 + 10 );
ctx.restore();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment