Chat with us, powered by LiveChat Javascript/HTML TicTacToe | WriteDemy

<html>

<head>

<style>

.tictac

{

background:purple;

border:#999 10px groove;

width:180px;

height:180px;

font-size:150px;

}

</style>

<script>

// create a variable for if the game is over, initialize it to false

// create a variable for the current player, initialize it to ‘O’ or ‘X’

// based on who will go first

// create an array for the squares using the regular methodology

// create a 2-d array of the win combinations, the data is as follows:

/*

0, 1, 2

3, 4, 5

6, 7, 8

0, 3, 6

1, 4, 7

2, 5, 8

0, 4, 8

2, 4, 6

*/

// declare function named reset with no parameters

{

// write a for loop starting at index 1 instead of the 

// usual 0, that loops through all 9 positions

{

// create a variable to relate to each HTML button,

// set it equal to explicit text “sqr” concatenated

// with the looping variable of the for loop

// update the associated HTML element with the id

// equal to the variable created above, set it equal

// to and explicit empty string

}

// reset the global variable for the squares to an 

// empty array using the literal methodology

// reset the global variable for the game being over

// setting it equal to false

}

// declare function named squareClick with one parameter called square

{

// create a variable that is set equal to the HTML element

// with the id of square (i.e. the parameter) and retrieve its value

//

// this will be used down below as the id to update the HTML element

// create a variable that is set equal to the JavaScript method call

// parseInt() passing as an argument square.substring(3, 4), 

// subtract one from the result of the parseInt method call

// 

// this will represent the index of the array of squares where

// the user clicked

// write an if statement that evaluates if the variable

// value is equal to explicit string “”

{

// update the HTML element using the parameter square as

// the id, setting its value equal to the global variable

// player

// in array of the squares update element stored at

// the index retrieved above to the global variable

// player

}

// call the function checkForWinner passing as an argument

// the explicit value ‘X’

// call the function checkForWinner passing as an argument

// the explicit value ‘O’

// change the player

// write an if statement that checks if the player variable

// is equal to O, if true, set player to X

// write the else leg that switches player from X to O

}

// declare function playAgain with no parameters

{

// create a variable that stores the response to a

// confirm dialog box with text “Play again?”

// write an if statement that evaluates the user’s response

// from above compared to true

{

// call function reset

}

// write the else leg

{

// display an alert dialog box that thanks the user

// for playing

}

}

// declare function checkForWinner with one parameter called value

{   

// write for loop, start at index 0, loop while

// the index less than the length of the array

// winCombinations

{

// write an if statement that evaluates

// the squares array [] where the index is

// array winCombinations[][], with the first index

// being the looping variable and the second index 

// being value 0, 1, or 2, checking if it is 

// equal to the value parameter;

// this if statement should be 

// three statements using the logical and &&

// e.g. squares[windCombinations[][]]  == value &&

{

// display an alert dialog box stating which

// player won

// set the variable gameOver equal to true

}

}

// write an if statement checking if gameOver is true

{

// call function playAgain

}

// write the else leg

{

// use the return statement for program control

}

}

</script>

</head>

<body>

<table>

<tr>

<td><input type=”button” id=”sqr1″ name=”sqr1″ class=”tictac” onClick=”squareClick(‘sqr1’)” /></td>

<!– TODO add the other two squares using sqr2 and sqr3 for id –>

</tr>

<!– TODO add another row–>

<!– TODO add sqr4 for id –>

<!– TODO add sqr5 for id –>

<!– TODO add sqr6 for id –>

<!– TODO add another row–>

<!– TODO add sqr7 for id –>

<!– TODO add sqr8 for id –>

<!– TODO add sqr9 for id –>

</table>

</body>

</html>

Our website has a team of professional writers who can help you write any of your homework. They will write your papers from scratch. We also have a team of editors just to make sure all papers are of HIGH QUALITY & PLAGIARISM FREE. To make an Order you only need to click Ask A Question and we will direct you to our Order Page at WriteDemy. Then fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.

Fill in all the assignment paper details that are required in the order form with the standard information being the page count, deadline, academic level and type of paper. It is advisable to have this information at hand so that you can quickly fill in the necessary information needed in the form for the essay writer to be immediately assigned to your writing project. Make payment for the custom essay order to enable us to assign a suitable writer to your order. Payments are made through Paypal on a secured billing page. Finally, sit back and relax.

Do you need an answer to this or any other questions?

About Writedemy

We are a professional paper writing website. If you have searched a question and bumped into our website just know you are in the right place to get help in your coursework. We offer HIGH QUALITY & PLAGIARISM FREE Papers.

How It Works

To make an Order you only need to click on “Place Order” and we will direct you to our Order Page. Fill Our Order Form with all your assignment instructions. Select your deadline and pay for your paper. You will get it few hours before your set deadline.

Are there Discounts?

All new clients are eligible for 20% off in their first Order. Our payment method is safe and secure.

Hire a tutor today CLICK HERE to make your first order