Trouble with TicTacToe

I’m trying to make a TicTacToe game using JavaScript to make it all GUI based. My trouble is that I’m not a strong programmer. I can get the 3x3 layout and texture. But when it comes to actually getting it coded to work I’m lost. I can’t get it centered or the GUI Text to be above and centered the grid. Any help would be appreciated.

    //declaring all states of buttons
    var emptyState : Texture;
    var xplayer : Texture;
    var oplayer : Texture;
    var cell : Array = new Array[9];
    var cellEst : Array = new Array[9];
    var turn : boolean; // false = X; true = O
     
    function Start () {
    for (var i = 0; i <= 8; i = i + 1){
    cellEst *= ""; //Gives an empty string that can later be changed to X or O*

}
}

function OnGUI () {
for (var i = 0; i <= 8; i = i + 1){

//Arranges the buttons into an tic tac toe board
var posX : int = 0;
var posY : int = 0;
var size : float = 100;

if (i == 1 || i == 4 || i == 7) {
posX = size;
}

if (i == 2 || i == 5 || i == 8) {
posX = size * 2;
}

if (i == 3 || i == 4 || i == 5) {
posY = size;
}

if (i == 6 || i == 7 || i == 8) {
posY = size * 2;
}

if (GUI.Button (Rect (posX, posY, size, size), cellEst_) && cellEst == “”) {
if (turn == false) {
}_

else {
}

turn = !turn; //Changes player
}
}
}

Ok so i was browsing and saw your question, and copied your code to see if i could make it work. I dont do javascript btw, the syntax bothers my eyes. This is what I came up with in C#. You just need to assign an empty texture, a texture for a square with O and a texture for a square with X. i used 3 64x64 plain white textures i made in paint, and just painted x and o on two of them. assign textures in the inspector. There are probably alot better ways to handle some parts, but hey it works, and this is only off the top of my head after reading your question. Hopefully the code i came up with can help you understand ONE POSSIBLE SOLUTION, there are probably countless ways to make a tictactoe game.
Also, what do you mean by centering the grid? you mean like the whole grid in the center of the screen? I would put all the buttons into a GUI.Window and then position that using screen.width and screen.height in some fashion. (I hate doing guis, i can never make them look nice)
anyways, here the code i wrote based off yours. hope this might help

using UnityEngine;
using System.Collections;

public class TicTacToe : MonoBehaviour
{
	public Texture EmptyTex;
	public Texture XTex;
	public Texture OTex;
	public bool Turn = false;
	bool GameOver = false;
	CellDataClass CellData;
	CellDataClass[] CellDataArray;
	string winner = "";
	void Start () 
	{

		SetCells();
	}
	void SetCells()
	{
		CellDataArray = new CellDataClass[9];
		int CellID = 0;
		foreach(CellDataClass Cell in CellDataArray)
		{
			CellData = new CellDataClass();
			CellData.ID = CellID;
			CellID = CellID + 1;
			CellData.Tex = EmptyTex;

			CellData.isEmpty = true;
			CellData.height = 100;
			CellData.width = 100;
			if (CellData.ID == 0)
			{
				CellData.posX = 0;
				CellData.posY = 0;
				
			}
			if (CellData.ID == 1)
			{
				CellData.posX = 100;
				CellData.posY = 0;
			}
			if (CellData.ID == 2)
			{
				CellData.posX = 200;
				CellData.posY = 0;
			}
			if (CellData.ID == 3)
			{
				CellData.posX = 0;
				CellData.posY = 100;
			}
			if (CellData.ID == 4)
			{
				CellData.posX = 100;
				CellData.posY = 100;
			}
			if (CellData.ID == 5)
			{
				CellData.posX = 200;
				CellData.posY = 100;
			}
			if (CellData.ID == 6)
			{
				CellData.posX = 0;
				CellData.posY = 200;
			}
			if (CellData.ID == 7)
			{
				CellData.posX = 100;
				CellData.posY = 200;
			}
			if (CellData.ID == 8)
			{
				CellData.posX = 200;
				CellData.posY = 200;
			}
			CellDataArray[CellData.ID] = CellData;
		}
	}
	void OnGUI ()
	{
		if(!GameOver)
		{
			foreach(CellDataClass Cell in CellDataArray)
			{
				if (GUI.Button(new Rect (Cell.posX, Cell.posY, Cell.height, Cell.width),Cell.Tex) && Cell.isEmpty)
				{
					if (Turn)
					{
						Cell.Tex = XTex;
						Cell.Owner = false;
						Cell.isEmpty = false;
					}
					else if (!Turn)
					{
						Cell.Tex = OTex;
						Cell.Owner = true;
						Cell.isEmpty = false;
					}
					if(!CellDataArray[0].isEmpty && !CellDataArray[1].isEmpty && !CellDataArray[2].isEmpty && !CellDataArray[3].isEmpty &&
					   !CellDataArray[4].isEmpty && !CellDataArray[5].isEmpty && !CellDataArray[6].isEmpty && !CellDataArray[7].isEmpty && !CellDataArray[8].isEmpty)
					{
						GameOver = true;
					}
					DetermineWinner();
					Turn = !Turn;
				}
			}
		}
		else if(GameOver)
		{
			GUILayout.Label(winner + " wins.");
			if (GUILayout.Button("Restart"))
			{
				SetCells();
				GameOver = false;
				Turn = false;
			}
		}
	}
	void DetermineWinner()
	{
		winner = "Nobody";
		//First horizontal Row
		if(CellDataArray[0].Owner == CellDataArray[1].Owner && CellDataArray[1].Owner == CellDataArray[2].Owner)
		{
			if(!CellDataArray[0].isEmpty && !CellDataArray[1].isEmpty && !CellDataArray[2].isEmpty)
			{
				if(CellDataArray[0].Owner)
					winner = "O";
				else if(!CellDataArray[0].Owner)
					winner = "X";
				GameOver = true;
			}
		}
		//Second Horiztontal Row
		if(CellDataArray[3].Owner == CellDataArray[4].Owner && CellDataArray[4].Owner == CellDataArray[5].Owner)
		{
			if(!CellDataArray[3].isEmpty && !CellDataArray[4].isEmpty && !CellDataArray[5].isEmpty)
			{
				if(CellDataArray[3].Owner)
					winner = "O";
				else if(!CellDataArray[3].Owner)
					winner = "X";
				GameOver = true;
			}
		}
		//Third Horizontal Row
		if(CellDataArray[6].Owner == CellDataArray[7].Owner && CellDataArray[7].Owner == CellDataArray[8].Owner)
		{
			if(!CellDataArray[6].isEmpty && !CellDataArray[7].isEmpty && !CellDataArray[8].isEmpty)
			{
				if(CellDataArray[6].Owner)
					winner = "O";
				else if(!CellDataArray[6].Owner)
					winner = "X";
				GameOver = true;
			}
		}
		//First Vertical Column
		if(CellDataArray[0].Owner == CellDataArray[3].Owner && CellDataArray[3].Owner == CellDataArray[6].Owner)
		{
			if(!CellDataArray[0].isEmpty && !CellDataArray[3].isEmpty && !CellDataArray[6].isEmpty)
			{
				if(CellDataArray[0].Owner)
					winner = "O";
				else if(!CellDataArray[0].Owner)
					winner = "X";
				GameOver = true;
			}
		}
		//Second Vertical Column
		if(CellDataArray[1].Owner == CellDataArray[4].Owner && CellDataArray[4].Owner == CellDataArray[7].Owner)
		{
			if(!CellDataArray[1].isEmpty && !CellDataArray[4].isEmpty && !CellDataArray[7].isEmpty)
			{
				if(CellDataArray[1].Owner)
					winner = "O";
				else if(!CellDataArray[1].Owner)
					winner = "X";
				GameOver = true;
			}
		}
		//Third Vertical Column
		if(CellDataArray[2].Owner == CellDataArray[5].Owner && CellDataArray[5].Owner == CellDataArray[8].Owner)
		{
			if(!CellDataArray[2].isEmpty && !CellDataArray[5].isEmpty && !CellDataArray[8].isEmpty)
			{
				if(CellDataArray[2].Owner)
					winner = "O";
				else if(!CellDataArray[2].Owner)
					winner = "X";
				GameOver = true;
			}
		}
		//BackSlash Diagonal
		if(CellDataArray[0].Owner == CellDataArray[4].Owner && CellDataArray[4].Owner == CellDataArray[8].Owner)
		{
			if(!CellDataArray[0].isEmpty && !CellDataArray[4].isEmpty && !CellDataArray[8].isEmpty)
			{
				if(CellDataArray[0].Owner)
					winner = "O";
				else if(!CellDataArray[0].Owner)
					winner = "X";
				GameOver = true;
			}
		}
		//ForwardSlash Diagonal
		if(CellDataArray[2].Owner == CellDataArray[4].Owner && CellDataArray[4].Owner == CellDataArray[6].Owner)
		{
			if(!CellDataArray[2].isEmpty && !CellDataArray[4].isEmpty && !CellDataArray[6].isEmpty)
			{
				if(CellDataArray[2].Owner)
					winner = "O";
				else if(!CellDataArray[2].Owner)
					winner = "X";
				GameOver = true;
			}
		}


			

	}
}
public class CellDataClass
{
	public int ID;
	public bool Owner; //if false, is X. if true, is O.
	public int posX;
	public int posY;
	public int height;
	public int width;
	public Texture Tex;
	public bool isEmpty;
}