ga-wdi-exercises / project1

[project] GA- Project 1
3 stars 75 forks source link

issue with toggling selection in concentration #165

Closed ghost closed 9 years ago

ghost commented 9 years ago

Working on populating the colors for cards in concentration.

I am trying laying colors out manually behind the white squares so each square will toggle to its color when clicked.

Trying:

function flipCard(evt){
  console.log('card clicked')
  //add toggle from white to color for indiv cards
  $(this).toggleClass(cardColor)
}
function cardColor(squareValues){
  //assign colors to cards
    //rowOne
  $('div.rowOne .card:eq(0)').addClass('blue')
  $('div.rowOne .card:eq(1)').addClass('red')
  $('div.rowOne .card:eq(2)').addClass('green')
  $('div.rowOne .card:eq(3)').addClass('orange')
    //rowTwo
  $('div.rowTwo .card:eq(0)').addClass('blue')
  $('div.rowTwo .card:eq(1)').addClass('lime')
  $('div.rowTwo .card:eq(2)').addClass('olive')
  $('div.rowTwo .card:eq(3)').addClass('brown')
    //rowThree
  $('div.rowThree .card:eq(0)').addClass('tan')
  $('div.rowThree .card:eq(1)').addClass('orange')
  $('div.rowThree .card:eq(2)').addClass('tan')
  $('div.rowThree .card:eq(3)').addClass('red')
    //rowFour
  $('div.rowFour .card:eq(0)').addClass('lime')
  $('div.rowFour .card:eq(1)').addClass('green')
  $('div.rowFour .card:eq(2)').addClass('brown')
  $('div.rowFour .card:eq(3)').addClass('olive')
}

I expected the colors to populate into all sixteen squares; I'll work on starting out white as a next step.

Instead, the colors do populate, but the clicked square disappears; my toggle method is removing classes instead of toggling between two of them..

RobertAKARobin commented 9 years ago

toggleClass expects a string. For example:

$("#whatever").toggleClass("myClassName");

cardColor is a function that doesn't return anything. As a result, I'm not entirely sure what toggleClass is trying to do with it!

ghost commented 9 years ago

okay, that's where i'm hung up. going to try to come up with a meaningful cardColor function.