How to check a sequence? (JS)

How to check a sequence? There are three lights that are lit by the player. He
need to turn them into a sequence. How to check if they were lit in order?

You can do something as easy as:

var lights : bool[] = new bool[3];

function Light (var index : int) {
    for (var i=0;i<index;i++) {
       if (!lights*) {*

Debug.Log ("Can’t turn light "+index+ “on, because light “+i+” is not turned on yet”);
lights[index] = true;
if (index == lights.length-1) {
Debug.Log (“All lights have been lit in sequence”);
Then just call the Light () function when the player tries to light a light. To reset it, just do
lights = new bool[3];
If you don’t want the player to know if he lit the correct light, light the light before you do the sequence check.
Hope it helps!

Ok, another go.

var playerSequence : Array = new Array ();

//Not sure if this is valid js syntax
//This is the correct sequence
var correctSequence : int[] = new int[3] {0,2,1};

//When the player lights a light, call this function with the ID of the light (you choose). For a correct sequence, the player should have lit
//lights 0,1,2.
function Light (var index : int) {
	playerSequence.Add (index);

	//The player has lit three lights, check if they were lit in the correct order
	if (playerSequence.length == 3) {
		//Check if the sequence is correct
		VerifySequence ();

function VerifySequence () {
	if (playerSequence.length != correctSequence.length) {
		Debug.Log ("Not the correct sequence");
	//Loop through the sequence to see if it is correct
	for (var i=0;i<3;i++) {
		if (playerSequence _!= correctSequence*) {*_

* Debug.Log (“Oh no, your sequence is not correct”);*

* //Clear the array so the player can try again*
* playerSequence.Clear ();*
* return;*
* }*
* }*

* //The sequence is correct*
* Debug.Log (“Yey, you have chosen the correct sequence”);*

Here : unitynoobs you can download a small project with this answer!