
var squares = document.querySelectorAll(".square");

var colors = [];
for (var i = squares.length - 1; i >= 0; i--) {
  colors.push(getRandomRGB());
}

var pickedColor = colors[getRandomInt(0, colors.length + 1)];
var h1 = document.querySelector('h1');
var t = document.createTextNode(' ' + pickedColor);
h1.appendChild(t);


function getRandomInt(min, max) {
  min = Math.ceil(min);
  max = Math.floor(max);
  return Math.floor(Math.random() * (max - min)) + min;
}

function getRandomRGB() {
  var red = getRandomInt(0, 256);
  var green = getRandomInt(0, 256);
  var blue = getRandomInt(0, 256);
  var rgb = "rgb(" + red + ", " +
                     green + ", " +
                     blue + ")";
  return rgb;
}

var colorCounter = 0;
squares.forEach(function(square) {
  square.style.backgroundColor = colors[colorCounter];
  colorCounter++;
  square.addEventListener('click', function() {
    if (square.style.backgroundColor === pickedColor) {
      alert("You're right!!")
    } else {
      alert("WRONG!")
      square.style.backgroundColor = '#232323';
    }
  })
});


var squares = document.querySelectorAll(".square");

var colors = [];
for (var i = squares.length - 1; i >= 0; i--) {
  colors.push(getRandomRGB());
}

var pickedColor = colors[getRandomInt(0, colors.length)];
var h1 = document.querySelector('h1');
var t = document.createTextNode(' ' + pickedColor);
h1.appendChild(t);


function getRandomInt(min, max) {
  min = Math.ceil(min);
  max = Math.floor(max);
  return Math.floor(Math.random() * (max - min)) + min;
}

function getRandomRGB() {
  var red = getRandomInt(0, 256);
  var green = getRandomInt(0, 256);
  var blue = getRandomInt(0, 256);
  var rgb = "rgb(" + red + ", " +
                     green + ", " +
                     blue + ")";
  return rgb;
}

var colorCounter = 0;
squares.forEach(function(square) {
  square.style.backgroundColor = colors[colorCounter];
  colorCounter++;
  square.addEventListener('click', function() {
    if (square.style.backgroundColor === pickedColor) {
      alert("You're right!!")
    } else {
      square.style.backgroundColor = '#232323';
    }
  })
});

Fix picked color sometimes undefined
Fix picked color sometimes undefined
