var coloursArray = [ "blue", "green", "yellow", "red" ];

var numCorrect = 0;
var numIncorrect = 0;
var answersArray = [];
var _dep = new Deps.Dependency();

// -------------------------------------------- Create Colour Game Question
var createColourQuestion = function(colours) {

    var nextRandomColour = colours[Math.floor(Math.random()*colours.length)];
    
// -------------------------------------------- Update Random Colour in current Session

    Session.set('randomColour', nextRandomColour);
    
};

// -------------------------------------------------------- Set initial Session variable values
Session.set('randomColour', coloursArray[Math.floor(Math.random()*coloursArray.length)]);

// -------------------------------------------------------- Handlebar helper function returns Session randomColour value
Handlebars.registerHelper('getRandomColour',function(){
  
  return Session.get("randomColour");
  
});

Template.colours.helpers({
  
	child: function () {
		var child = Session.get("child");
		return child;
		console.log(child.name);
	},
  
// -------------------------------------------------------- update Correct Answers in Session
  updateCorrectAnswers: function() {
    
     _dep.depend();
    return numCorrect;
    
  }
  
});

Template.colours.events({

// -------------------------------------------------------- Listen for click event on any colour circle
  "click .circle": function(event) {
    
    var answer = Session.get("randomColour");

// -------------------------------------------------------- Save the id of the clicked circle (contains colour)
    var clickedColour = event.target.id;
    
    if (clickedColour === answer) {
      
      var newCorrectAnswer = {
        
        answer: answer,
        child_answer: clickedColour,
        correct: true
        
      };

// -------------------------------------------------------- If it's the right answer update the right answers in Session
      answersArray.push(newCorrectAnswer);
      console.log(answersArray);


      numCorrect++;
      _dep.changed();
// -------------------------------------------------------- update the Session random colour and display a new question     
      createColourQuestion(coloursArray);
      
    }
    else {
// -------------------------------------------------------- If it's wrong, update the wrong answers in Session    
      var newIncorrectAnswer = {
        
        answer: answer,
        child_answer: clickedColour,
        correct: false
        
      };
      
      answersArray.push(newIncorrectAnswer);
      console.log(answersArray);
      
      
      numIncorrect++;
      
    }

  },
// -------------------------------------------------------- Listen for the click to Finish Game
  "click .finish-game": function(event) {
    
// -------------------------------------------------------- Take the child object on finish and pass it to the storing score function
    var child = Session.get("child");
    
    Meteor.call('addColoursScore', child.id, numCorrect, numIncorrect, answersArray);
    
    numCorrect = 0;
    numIncorrect = 0;
    
    Router.go('/');
    
  }

});

@@ -1,12 +1,103 @@
+Session.set('randomColour', coloursArray%5BMath.floor(Math.random()*coloursArray.length)%5D);%0A%0A
 var coloursA
@@ -141,17 +141,16 @@
 red%22 %5D;%0A
-%0A
 var numC
@@ -288,16 +288,28 @@
 --------
+------------
  Create 
@@ -328,16 +328,50 @@
 Question
+. Update Random Colour in Session%0A
 %0Avar cre
@@ -492,101 +492,8 @@
 h)%5D;
-%0A    %0A// -------------------------------------------- Update Random Colour in current Session
 %0A%0A  
@@ -554,195 +554,8 @@
 %7D;%0A%0A
-// -------------------------------------------------------- Set initial Session variable values%0ASession.set('randomColour', coloursArray%5BMath.floor(Math.random()*coloursArray.length)%5D);%0A%0A
 // -
@@ -671,16 +671,17 @@
 r value%0A
+%0A
 Handleba
@@ -769,32 +769,130 @@
 lour%22);%0A  %0A%7D);%0A%0A
+// -------------------------------------------------------- Return the Current Child Name and Id%0A%0A
 Template.colours
@@ -1073,22 +1073,30 @@
 ------- 
-u
+Render U
 pdate
+d
  Correct
@@ -1103,27 +1103,19 @@
  Answers
- in Session
+%0A  
 %0A  updat
@@ -1311,41 +1311,31 @@
 for 
-c
+C
 lick 
-event 
 on any 
-colour c
+C
 ircle%0A
+  %0A
   %22c
@@ -1423,120 +1423,8 @@
 );%0A%0A
-// -------------------------------------------------------- Save the id of the clicked circle (contains colour)%0A
     
@@ -1654,129 +1654,8 @@
 %7D;%0A%0A
-// -------------------------------------------------------- If it's the right answer update the right answers in Session%0A
     
@@ -1697,42 +1697,8 @@
 r);%0A
-      console.log(answersArray);%0A%0A
 %0A   
@@ -1740,309 +1740,76 @@
 ();%0A
-// -------------------------------------------------------- update the Session random colour and display a new question     %0A      createColourQuestion(coloursArray);%0A      %0A    %7D%0A    else %7B%0A// -------------------------------------------------------- If it's wrong, update the wrong answers in Session
+      createColourQuestion(coloursArray);%0A      %0A    %7D%0A    else %7B%0A  
     
@@ -2009,48 +2009,8 @@
 r);%0A
-      console.log(answersArray);%0A      %0A
     
@@ -2053,16 +2053,19 @@
 %7D%0A%0A  %7D,%0A
+  %0A
 // -----
@@ -2131,21 +2131,8 @@
 for 
-the click to 
 Fini
@@ -2139,16 +2139,19 @@
 sh Game%0A
+  %0A
   %22click
@@ -2193,142 +2193,8 @@
    %0A
-// -------------------------------------------------------- Take the child object on finish and pass it to the storing score function%0A
     

clean up comments