← Back to Upcase

Flashcard Web App - Shuffling the Deck


(Kevin Murphy) #1

I just wrapped up the intro course and am completing the exercise. I have a guess controller with a backing model that I’m persisting to the database (the idea being that it might be useful for tracking stats/progress).

Right now I only have the ability for a user to make a guess for a particular card. However, I’d like to have the functionality to allow the user to go through the entire deck, guess one card at a time, and then progress to the next card to guess again.

In video lesson 2 we used the array shuffle method to go through the entire deck; however that won’t work here because the state won’t transfer from web request to web request. So far, the options I’m considering are as follows:

  1. Store the IDs of the cards in the deck in an array as a session variable or cookie, shuffle it, and then pop off items as you progress through.
  2. Query the database for each new card to guess from based on some statistic, such as the card in the deck that has been guessed the least number of times, has been guessed incorrectly the most, was guessed further in the past, etc. With this method though, you may never know when you’ve gone through the entire deck.

Does anyone have suggestions on the best way to accomplish this?


(Michael Tener) #2

This sounds like you could store the values in params if you don’t want to hit the db. To me it really sounds like you would want to use javascript/backbone. Here’s an example of what sounds like you’re trying to achieve: http://www.thepetedesign.com/demos/tip_cards_demo.html - jquery with ajax might be a good way to go.