Four Corners Javascript Challenge

four-corners-compassFour corners is a children’s game, often played in primary/elementary schools. The game can be played in a classroom. One player stand in the middle of the room with a blindfold. All the other participants choose one of the four corners of the room. For the purpose of this game we will call the four corners of the room North, East, South and West. The central player, “it”, designates one corner of the room. All the participants standing in this corner are out of the game. The remaining participants then move to a different corner of their choice and the game carries on until all participants have been caught.

The aim of this challenge is to recreate the game of four corners using HTML, CSS and JavaScript. The names of all participants will be stored in a JavaScript array called names as follows:

You can then access a value within an array using the appropriate index. i.e.

You can find out the number of items in an array using the length property:

You can sort the values of an array using the sort() method:

You can use the push() method to append a new value in the array.

You can use the pop() method to remove the last value in the array.

You can reset/empty an array:

You can join two or more arrays together using the concat() method:
For instance you can join two arrays together:

You can join three arrays together (an so on):

Four Corners Game


Using some of the techniques mentioned above, review the code for the four corners game. The JavaScript code is incomplete. Add some code in the clickCorner() to complete the game.

Press the “Edit on Codepen” button to access the code in full screen mode.

See the Pen
Four Corners
by 101 Computing (@101Computing)
on CodePen.

Share Button