subject
Engineering, 23.03.2020 22:56 kmarti11owj2q2

Investigate the existing script elementsThe template .js script has three declarations:playerTurn: Boolean variable that is true when the turn belongs to the player and false when the turn belongs to the computer. computerMoveTimeout: ID of an active timeout for the computer's move, or 0 if no such timeout exists. getGameBoard(): Function that returns an array of 9 elements, representing all cells in the game board. The first 3 elements are the top row, the next 3 the middle row, and the last 3 are the bottom row. The getGameBoard() function is implemented for you and requires no alteration. start(): Function that is called when the page loads, in order to start the game. Events for the "New game" button click and game board cell clicks are registered. Then newGame() is called to start the game. The start() function is implemented for you and requires no alteration. Implement the newGame() function (1 point)Implement the newGame() function to do the following:Use clearTimeout to clear the computer's move timeout and then set computerMoveTimeout back to 0Loop through all game board cells and set the inner HTML of each to a non-breaking space: Reset to the player's turn by setting playerTurn to trueSet the text of the turn information div to "Your turn"Implement the cellClicked() function (2 points)Implement the cellClicked() function to do the following:If playerTurn is true and the clicked cell is empty:Set the cell's innerHTML to "X"Set the cell's style color to "red"Call switchTurn()Implement switchTurn() part 1: turn-switching logic (2 points)Implement the switchTurn() function to do the following:If switching from the player's turn to the computer's turn, use setTimeout to call makeComputerMove after 1 second (1000 milliseconds). Assign the return value of setTimeout to computerMoveTimeout. The timeout simulates the computer "thinking", and prevents the nearly-instant response to each player move that would occur from a direct call to makeComputerMove().Toggle playerTurn's value from false to true or from true to false. Set the turn information div's text content to "Your turn" if playerTurn is true, or "Computer's turn" if playerTurn is false. Implement makeComputerMove() (2 points)Implement makeComputerMove() so that the computer puts an "O" in a random, available cell. Set the cell's style color to "blue". Call switchTurn() at the end of the function to switch back to the player's turn. Implement switchTurn() part 2: checking for a winner (3 points)Add logic to the switchTurn() function that checks for a winner before the turn switch. If the board contains 3 X's in a row, display the text "You win!" in the turn info div. If the board contains 3 O's in a row, display the text "Computer wins!" in the turn info div. If the board is full without either the player or computer having won, display the text "Draw game" in the turn info div. In the case of a winner or a draw game, set playerTurn to false and return without switching turns. This prevents the user from being able to place an X after the game is over. var playerTurn = true;var computerMoveTimeout = 0;// Returns an array of 9 elements that make up the game board. The first 3// elements are the top row, the next 3 the middle row, and the last 3 the// bottom row. function getGameBoard() {var gameBoardTable = document. getElementById("gameBoard");var result = [];for (var i = 0; i < 3; i++) {for (var j = 0; j < 3; j++) {result. push(gameBoardTable. rows[i].cells[j]);}}return result;}function start() {// Setup the click event for the "New game" buttonvar newBtn = document. getElementById("newGameButton");new Btn. addEventListener("click", newGame);// Create click-event listeners for each cell in the game boardvar cells = getGameBoard();for (let cell of cells) {cell. addEventListener("click", function() { cellClicked(cell); });}// Call the newGame function to make sure the board is clearnewGame();}function newGame() {// Your code here}function cellClicked(cell) {// Your code here}function switchTurn() {// Your code here}function makeComputerMove() {// Your code here}

ansver
Answers: 1

Another question on Engineering

question
Engineering, 04.07.2019 18:10
Aloaded platform of total mass 500 kg is supported by a dashpot and by a set of springs of effective stiffness 72 kn/m. it is observed that when the platform is depressed through a distance x = 12.5 cm below its equilibrium position and then released without any initial velocity; it reaches its equilibrium position in the shortest possible time without overshoot. find the position and velocity of the loaded platform 0.10 sec. after its release. if a further load of 400 kg is added to the platform, find, i) the frequency of damped vibrations, and i) the amplitude of vibration after 2 complete oscillations, given that the initial amplitude is 15 cm.
Answers: 1
question
Engineering, 04.07.2019 18:10
Different types of steels contain different elements that alter the characteristics of the steel. for each of the following elements, explain what the element does when alloyed with steel.
Answers: 2
question
Engineering, 04.07.2019 18:10
Ajournal bearing has a journal diameter of 3.250 in with a unilateral tolerance of 20.003 in. the bushing bore has a diameter of 3.256 in and a unilateral tolerance of 0.004 in. the bushing is 2.8 in long and supports a 700-lbf load. the journal speed is 900 rev/min. find the minimum oil film thickness and the maximum film pressure for both sae 20 and sae 20w-30 lubricants, for the tightest assembly if the operating film temperature is 160°f. a computer code is appropriate for solving this problem.
Answers: 3
question
Engineering, 04.07.2019 18:10
The thermal expansion or contraction of a given metal is a function of the f a)-density b)-initial temperature c)- temperature difference d)- linear coefficient of thermal expansion e)- final temperature f)- original length
Answers: 2
You know the right answer?
Investigate the existing script elementsThe template .js script has three declarations:playerTurn: B...
Questions
question
History, 17.01.2020 16:31
question
Mathematics, 17.01.2020 16:31
Questions on the website: 13722362