/* * jeopardy.js * * Computer Science 50, Fall 2011 * section10 * * Loads the jeopardy board and more! */ // give arrays a lookup property Array.prototype.lookup = function(v) { for (var i = 0; i < this.length; i++) if (this[i] === v) return true; return false; } // initalize an array to keep trak of squares that have been chosen var chosen = new Array(); /* * void * load_board() * * Loads the board. */ function load_board() { var html = ""; var c1 = "I C You Harvard"; var c2 = "WWWinning"; var c3 = "pset9"; var c4 = "FUNctions"; var c5 = "rand()"; html += c1 + c2 + c3 + c4 + c5 + ""; for (var i = 1; i <= 5; i++) { html += ""; for (var j = 1; j <= 5; j++) { html += ""; // if the square has already been chosen, don't print it out as a button if (chosen.lookup(j + (i * 100))) html += i + "00"; else html += ""; html += ""; } html += ""; } document.getElementById("board").innerHTML = html; } /* * void * choose(category, value) * * Opens the chosen square in a new window. */ function choose(category, value) { // add square to chosen array chosen.push(category + value); // open the chosen square in a new window var root = "http://192.168.56.50/~jharvard/section10/jeopardy/"; var page = "square.php?"; window.open(root + page + "category=" + category + "&value=" + value); // reload the board load_board(); }