Connect 4

This is a JavaScript version of 2 player Connect 4. Players take turns dropping pieces into the columns of the board. The computer tracks wins and draws automatically individually a game or match set. Awesome.

Over 2000+ free Javascript
at Website
Sampled by

This script has been rewritten from an older version due to a bug which was discovered by David Angell. Actually, he told me about this a long time ago, I just forgot about it until I was going through some old files. Oh well.

The 4-in-a-row testing algorithm has been mostly rewritten, the scoreboard area was removed in favor of a smaller, more code (and footprint) efficient design. The option to be able to specify the width and height of the board was removed; now it is the size of the real game: 6 rows x 7 columns. Sound capability was added when the player "drops" their chip. This feature only works in IE, but does not generate errors in other browsers.

This script does use the window.onload and window.onresize event handlers. Therefore, if you are running other scripts that also use these events, you must combine like events or one of the script will cease to function. There are instructions in the Tutorials section of this site to explain how to do this.


  1. Copy and paste the following script in the BODY section of your page where you want the game to appear:

    <script language="javascript" src="connect4.js"></script>

  2. This game features a clicking sound when the players drop their pieces. This works in IE only, but doesn't generate errors in other browsers. Copy and paste the following HTML tag into the HEAD section of your page:

    <bgsound id="c4sound">