-
Notifications
You must be signed in to change notification settings - Fork 0
Home
This repository is part of a larger project!
Javascript`s array contains the shift method.
The method shift erases the first element in an array and shifts the remaining elements to left, as the following example should show:
var anArray = [1,2,3];
console.log(anArray); //Outputs [1,2,3]
console.log(anArray[0]); //Outputs 1
console.log(anArray[1]); //Outputs 2
console.log(anArray[2]); //Outputs 3
console.log(anArray.length);//Outputs 3
//Shifting to left means that the remaining elements
//are new indicated from left to right
anArray.shift();
//Value 2 has now the index 0!
console.log(anArray); //Outputs [2,3]
console.log(anArray[0]); //Outputs 2
console.log(anArray[1]); //Outputs 3
console.log(anArray.length);//Outputs 2
The user interaction part, after pressing the button "START & RESET", could look like the content as seen below by starting "index.html" in a web browser. The content is a marginal and unimproved tic tac toe game.
-
Between "Bar" and the button "START & RESET" there is a row of circles and stars. They symbolize the players and the systems turn. The order is from left to right.
-
The circles are for the player.
-
The stars are for the system.
-
The player has to click an empty field beneath "Board" to occupy it.
-
The systems AI should only be able to understand that a field is empty and places randomly a star on such.
-
🅱️ utton "START & RESET" resets the current game and/or starts a new game. -
🅱️ utton "SHIFT" uses the shift method to erase the players current turn and thus commences the systems turn.
The colored areas are partly for a better readability in the wiki and are not part of the content. To use the project just download the files and execute "index.html". Note that all files (folder "wiki_images" excluded) should be placed in the same folder so that the functionality of the code is guaranteed.
This knowledge was gained:
Effective JavaScript "68 Specific Ways to Harness the Power of JavaScript" by David Herman