// Generated by CoffeeScript 1.6.3
var MainCtrl, app;

app = angular.module('app', ['ngSanitize']);

app.factory('questions', function($http) {
  return {
    newQuestion: function(cb) {
      var doRequest;
      doRequest = function() {
        return $http.get('/new-question/').success(function(data) {
          return cb(data);
        }).error(function() {
          return doRequest();
        });
      };
      return doRequest();
    }
  };
});

MainCtrl = function($scope, questions) {
  $scope.numQuestions = 2;
  $scope.currentQuestionNum = 0;
  $scope.numCorrect = 0;
  $scope.percentCorrect = 0;
  $scope.getNextQuestion = function() {
    if ($scope.currentQuestionNum === $scope.numQuestions) {
      $scope.gameOver = true;
      $scope.calculateGrade();
      return;
    }
    $scope.busy = true;
    return questions.newQuestion(function(data) {
      $scope.currentQuestion = data;
      $scope.currentQuestionNum++;
      return $scope.busy = false;
    });
  };
  $scope.getNextQuestion();
  $scope.setChoice = function(i) {
    return $scope.choice = i;
  };
  $scope.submitChoice = function() {
    $scope.currentQuestion.graded = true;
    $scope.currentQuestion.correct = $scope.choice === $scope.currentQuestion.answer;
    if ($scope.currentQuestion.correct) {
      $scope.numCorrect++;
      return $scope.percentCorrect = 100 * $scope.numCorrect / $scope.numQuestions;
    }
  };
  $scope.getProgressBarStyle = function() {
    var color;
    color = "green";
    if ($scope.percentCorrect < 50) {
      color = "red";
    } else if ($scope.percentCorrect < 70) {
      color = "yellow";
    } else if ($scope.percentCorrect < 90) {
      color = "orange";
    }
    return {
      width: "" + $scope.percentCorrect + "%",
      'background-color': color
    };
  };
  return $scope.calculateGrade = function() {
    var pc;
    pc = $scope.percentCorrect;
    if (pc < 60) {
      $scope.letterGrade = "F";
      return $scope.doctorLevel = "Bro, do you even healthcare?";
    } else if (pc < 70) {
      $scope.letterGrade = "D";
      return $scope.doctorLevel = "Nurse Assistant";
    } else if (pc < 80) {
      $scope.letterGrade = "C";
      return $scope.doctorLevel = "Nurse";
    } else if (pc < 90) {
      $scope.letterGrade = "B";
      return $scope.doctorLevel = "Physician";
    } else {
      $scope.letterGrade = "A";
      return $scope.doctorLevel = "Dr. House";
    }
  };
};

// Generated by CoffeeScript 1.6.3
var MainCtrl, app;

app = angular.module('app', ['ngSanitize']);

app.factory('questions', function($http) {
  return {
    newQuestion: function(cb) {
      var doRequest;
      doRequest = function() {
        return $http.get('/new-question/').success(function(data) {
          return cb(data);
        }).error(function() {
          return doRequest();
        });
      };
      return doRequest();
    }
  };
});

MainCtrl = function($scope, questions) {
  $scope.numQuestions = 10;
  $scope.currentQuestionNum = 0;
  $scope.numCorrect = 0;
  $scope.percentCorrect = 0;
  $scope.getNextQuestion = function() {
    if ($scope.currentQuestionNum === $scope.numQuestions) {
      $scope.gameOver = true;
      $scope.calculateGrade();
      return;
    }
    $scope.busy = true;
    return questions.newQuestion(function(data) {
      $scope.currentQuestion = data;
      $scope.currentQuestionNum++;
      return $scope.busy = false;
    });
  };
  $scope.getNextQuestion();
  $scope.setChoice = function(i) {
    return $scope.choice = i;
  };
  $scope.submitChoice = function() {
    $scope.currentQuestion.graded = true;
    $scope.currentQuestion.correct = $scope.choice === $scope.currentQuestion.answer;
    if ($scope.currentQuestion.correct) {
      $scope.numCorrect++;
      return $scope.percentCorrect = 100 * $scope.numCorrect / $scope.numQuestions;
    }
  };
  $scope.getProgressBarStyle = function() {
    var color;
    color = "green";
    if ($scope.percentCorrect < 50) {
      color = "red";
    } else if ($scope.percentCorrect < 70) {
      color = "yellow";
    } else if ($scope.percentCorrect < 90) {
      color = "orange";
    }
    return {
      width: "" + $scope.percentCorrect + "%",
      'background-color': color
    };
  };
  return $scope.calculateGrade = function() {
    var pc;
    pc = $scope.percentCorrect;
    if (pc < 60) {
      $scope.letterGrade = "F";
      return $scope.doctorLevel = "Bro, do you even healthcare?";
    } else if (pc < 70) {
      $scope.letterGrade = "D";
      return $scope.doctorLevel = "Nurse Assistant";
    } else if (pc < 80) {
      $scope.letterGrade = "C";
      return $scope.doctorLevel = "Nurse";
    } else if (pc < 90) {
      $scope.letterGrade = "B";
      return $scope.doctorLevel = "Physician";
    } else {
      $scope.letterGrade = "A";
      return $scope.doctorLevel = "Dr. House";
    }
  };
};

Recompile main.js