
//Javascript for Jeopardy Style ALgebra Game
//===========================================//

//Variable Identification
//cellNumber = the number of the box in the grid
//attempt = the number of times the user responded with an answer
//cellDone[] = the questions already answered correctly (Boolean)
//answer[] = the correct answers
//question[]= the questions subscripted by their location in the grid
//PointValue[]= the point value of each question
//index = subscripted index value
//response = response from user

var cellNumber = 0;
var attempt = 0;
var cellDone = new Array(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0);
var answer = new Array(1,3,1,1,3, 3,1,2,3,3, 1,2,3,2,3, 2,2,2,2,1, 2,2,3,1,1);
var PointValue = new Array(100,100,100,100,100,200,200,200,200,200,300,300,300,300,300,400,400,400,400,400,500,500,500,500,500);

//questions for Operations, Equations, Coordinate Geometry, Data, Probability 
var question = new Array();

//First column - Operations
question[1] = "A hockey team played 26 games and won 18.  What is the ratio of wins to loses? \n 1. 9:4 \n 2. 9:13 \n 3. 4:13";
question[6] = "Two numbers are in the ratio 3:5.  Their sum is 80.  What is the larger number? \n 1. 10 \n 2. 30 \n 3. 50";
question[11] = "(-2x)³ = \n 1. -8x³ \n 2. -2x³ \n 3. 8x³";
question[16] = "The length and width of a rectangle measure 4xy and 3xy.  What is its area? \n 1. 12xy \n 2. 12x²y² \n 3. (12xy)²";
question[21] = "For what values of x, is |x-3| = 5 true? \n 1. x = 8 \n 2. x = -2, x = 8 \n 3. x = -2";

//Second column - Equations
question[2] = "Solve:  5x - 4 - 2x + 1 = 8x + 2 \n 1. x = 1 \n 2. x = 3 \n 3. x = -1";
question[7] = "A number decreased by 20 equals 46.  Find the number. \n 1. 66 \n 2. 26 \n 3. -26";
question[12] = "Solve for y:  xy - d = m \n 1. y = (m-d)/x  \n 2. y = (m+d)/x \n 3. y = (m+d)-x";
question[17] = "Solve for a:  a² = 36 \n 1. a = 6 \n 2. a = {-6,6} \n 3. a = {-6,0,6}";
question[22] = "The equation  y = 0.5x represents: \n 1. exponential growth \n 2. a straight line \n 3. exponential decay";

//Third column - Coordinate Geometry
question[3] = "The slope of the segment connecting (1,2) and (3,4) is: \n 1. 1 \n 2. 2 \n 3. -1";
question[8] = "In the formula y = mx+b, the b stands for: \n 1. slope \n 2. y-intercept \n 3. x-intercept";
question[13] = "The lines y = 3x+1 and y = 3x-4 are: \n 1. the same line \n 2. perpendicular \n 3. parallel";
question[18] = "A line perpendicular to 2y = 4x-6 will have a slope of: \n 1. 2 \n 2. -1/2 \n 3. -3x";
question[23] = "What is the axis of symmetry for the parabola y = 3x²+12x-2? \n 1. y = 2 \n 2. x = 2 \n 3. x = -2";

//Fourth column – Data
question[4] = "Data dealing with color, descriptions and smell is referred to as: \n 1. qualitative \n 2. quantitative \n 3. biased";
question[9] = "The sum of a set of data divided by the number of data is the: \n 1. median \n 2. mode \n 3. mean";
question[14] = "Another name for the median of a set of data is the: \n 1. outlier \n 2. second quartile \n 3. third quartile";
question[19] = "If a set of data is described as having a negative correlation, the slope of the line is: \n 1. positive \n 2. negative \n 3. zero";
question[24] = "If Mike graduated 25th out of a class of 150 students, his percentile rank would be: \n 1. 83rd percentile \n 2. 75th percentile \n 3. 25th percentile";

//Fifth column - Probability
question[5] = "5! is: \n 1. 20 \n 2. 60 \n 3. 120";
question[10] = "6P2 is: \n 1. 12 \n 2. 15 \n 3. 30";
question[15] = "7C2 is: \n 1. 49 \n 2. 42 \n 3. 21";
question[20] = "In a deck of 52 cards, the probability of drawing the 5 of diamonds is: \n 1. 1/52 \n 2. 1/16 \n 3. 1/4";
question[25] = "A coin is tossed 5 times.  The number of possible arrangements of heads and tails is: \n 1. 32 \n 2. 25 \n 3. 10";

//Function to set and reset the graphic buttons, clear the score,
//and set text to starting statements 
function set_reset()
{
	var index = 0;
	attempt = 0;
	cellNumber = 0;
	
	while (index < cellDone.length)
	{
		cellDone[index] = 0;
		if (index < 5)
	 	{ 
			window.document.images[index].src="100pic.gif";
		}
		if (index > 4 && index < 10)
		{
			window.document.images[index].src="200pic.gif";
		}
		if (index > 9 && index < 15) 
		{
			window.document.images[index].src="300pic.gif";
		}
		if (index > 14 && index < 20)
		{
			window.document.images[index].src="400pic.gif";
		}
		if (index > 19 && index < 25)
		{
			window.document.images[index].src="500pic.gif";
		}

		index++;
	}

	score.innerText = 0;
	message.innerText = "Begin";
	questiontxt.innerText = "Click red button to start";
	window.document.jeopardy.answertxt.value = " ";
}
//Function to get the number of the chosen box, check to see if that box
//has already been answered, and display the question.
function on_click(num)
{

	cellNumber = num;

	message.innerText = " ";
	questiontxt.innerText = " ";
	window.document.jeopardy.answertxt.value = " ";


	if (cellDone[cellNumber] == 1)   
	{
		return;
	}

	questiontxt.innerText = question[cellNumber];

	window.document.jeopardy.answertxt.focus();
}

//Function to get the user’s answer to the question, check if answer is 
//correct, award or deduct points, increment the number of questions
//attempted, and check to see if the game is over.
function get_answertxt()
{
	var PointAmount = 0;

	if (cellDone[cellNumber] == 1 || cellNumber == 0)
	{
		return;
	}

	var response = window.document.jeopardy.answertxt.value;

	PointAmount = PointValue[cellNumber -1];
	
	attempt++;
	
	if (response!=answer[cellNumber-1])
	{
		score.innerText = parseInt(score.innerText) - PointAmount;
		PointAmount = parseInt(score.innerText);
		message.innerText = attempt +". Incorrect. Pick another button.";
	}
	else
	{

		cellDone[cellNumber] = 1; 
		window.document.images[cellNumber -1].src="blankpic.gif";

		score.innerText = parseInt(score.innerText) + PointAmount;
		PointAmount = parseInt(score.innerText);
		message.innerText = attempt +". Very good! Pick another button.";
		
		
	}

	window.document.jeopardy.answertxt.value = " ";

	cellNumber = 0;
	

	if (attempt > 24) 
	{
		PointAmount = parseInt(score.innerText);
		message.innerText = "Game over with " + PointAmount + " pts";
	}
} 

