// Generated by CoffeeScript 1.9.3
(function() {
  $(function() {
    var pressedEnter, random_question, startUp, update_question, words;
    this.current = "";
    this.context = this;
    $("#question, #answer").hide();
    words = $.getJSON("spellings.json");
    $.when(words).done((function(d) {
      return startUp(d);
    }));
    $.when(words).fail(function(data, status, error) {
      console.log(status + error);
    });
    startUp = function(data) {
      $("#question, #answer").show();
      update_question(data);
      return this.data = data;
    };
    random_question = function(data) {
      var choice;
      choice = Math.floor(Math.random() * data['words'].length);
      this.current = choice;
      return data['words'][choice];
    };
    update_question = function(data) {
      var word;
      word = random_question(data);
      return $("p#hint").empty().append(word['hint']);
    };
    return pressedEnter = function(e) {
      var attempt;
      if (e.which === 13) {
        attempt = $("#input_answer").val();
        if (attempt.toLowerCase() === this.choice.toLowerCase()) {
          return alert("SUCCESS!");
        } else {
          return alert("FAIL!");
        }
      }
    };
  });

}).call(this);

// Generated by CoffeeScript 1.9.3
(function() {
  $(function() {
    var random_question, startUp, update_keyHandler, update_question, words;
    this.current = "";
    $("#question, #answer").hide();
    words = $.getJSON("spellings.json");
    $.when(words).done((function(d) {
      return startUp(d);
    }));
    $.when(words).fail(function(data, status, error) {
      console.log(status + error);
    });
    startUp = function(data) {
      $("#question, #answer").show();
      update_question(data);
      return this.data = data;
    };
    random_question = function(data) {
      var choice;
      choice = Math.floor(Math.random() * data['words'].length);
      this.current = data['words'][choice]['name'];
      return data['words'][choice];
    };
    update_question = function(data) {
      var word;
      word = random_question(data);
      update_keyHandler();
      return $("p#hint").empty().append(word['hint']);
    };
    return update_keyHandler = function() {
      return $("#input_answer").keydown((function(_this) {
        return function(e) {
          var attempt;
          if (e.which === 13) {
            attempt = $("#input_answer").val();
            if (attempt.toLowerCase() === _this.current.toLowerCase()) {
              return alert("SUCCESS!");
            } else {
              return alert("FAIL!");
            }
          }
        };
      })(this));
    };
  });

}).call(this);

update output