Permalink
Browse files

added skip this question A/B test into assessments

Summary: Added functionality to khan-exercise.js so that it can handle the skip question button. This goes along with review https://khanacademy.kilnhg.com/Review/K117906

Test Plan:
Load an exercise and make sure the new code doens't break anything because of the lack of a skip button
Load an assessment in a phantom window until you are in the right a/b test. Then test out clicking the skip question button multiple times quickly to make sure that only one request is sent.

Reviewers: jace, alpert, chris

Reviewed By: alpert

Differential Revision: http://phabricator.khanacademy.org/D2116
  • Loading branch information...
1 parent fa43cbd commit 736b7f5b80d7069b4b075fef8ebcfa48b2b9d377 @tzjames tzjames committed Apr 4, 2013
Showing with 42 additions and 22 deletions.
  1. +33 −18 interface.js
  2. +9 −4 khan-exercise.js
View
@@ -69,10 +69,11 @@ function problemTemplateRendered() {
// 'Check Answer' or 'Submit Answer'
originalCheckAnswerText = $("#check-answer-button").val();
-
+
// Solution submission
$("#check-answer-button").click(handleCheckAnswer);
$("#answerform").submit(handleCheckAnswer);
+ $("#skip-question-button").click(handleSkippedQuestion);
// Hint button
$("#hint").click(handleHint);
@@ -136,26 +137,28 @@ function newProblem(e, data) {
$("#hint").attr("disabled", numHints === 0);
}
-
function handleCheckAnswer() {
- var framework = Exercises.getCurrentFramework();
+ return handleAttempt({skipped: false});
+}
- // Stop if the form is already disabled and we're waiting for a response
- // (in assessment mode, for instance).
- if ($("#answercontent input").not("#hint, #next-question-button")
- .is(":disabled")) {
- return false;
- }
+function handleSkippedQuestion() {
+ return handleAttempt({skipped: true});
+}
+function handleAttempt(data) {
+ var framework = Exercises.getCurrentFramework();
+ var skipped = data.skipped;
var score;
+
if (framework === "perseus") {
score = PerseusBridge.scoreInput();
} else if (framework === "khan-exercises") {
score = Khan.scoreInput();
}
- // Stop if the user didn't enter a response
- if (score.empty) {
+ // Stop if the user didn't try to skip the question and also didn't yet
+ // enter a response
+ if (score.empty && !skipped) {
return false;
}
@@ -181,7 +184,7 @@ function handleCheckAnswer() {
$("#check-answer-button").hide();
$("#check-answer-results > p").hide();
$("#next-question-button")
- .removeAttr("disabled")
+ .prop("disabled", false)
.removeClass("buttonDisabled")
.show()
.focus();
@@ -236,7 +239,7 @@ function handleCheckAnswer() {
// Save the problem results to the server
var data = buildAttemptData(score.correct, ++attempts,
- JSON.stringify(score.guess), timeTaken);
+ JSON.stringify(score.guess), timeTaken, skipped);
request("problems/" + problemNum + "/attempt", data).fail(function(xhr) {
// Alert any listeners of the error before reload
@@ -298,7 +301,7 @@ function hintUsed() {
if (!localMode && !userExercise.readOnly && !answeredCorrectly) {
// Don't do anything on success or failure; silently failing is ok here
request("problems/" + problemNum + "/hint",
- buildAttemptData(false, attempts, "hint", timeTaken));
+ buildAttemptData(false, attempts, "hint", timeTaken, false));
}
}
@@ -320,7 +323,8 @@ function updateHintButtonText() {
}
// Build the data to pass to the server
-function buildAttemptData(correct, attemptNum, attemptContent, timeTaken) {
+function buildAttemptData(correct, attemptNum, attemptContent, timeTaken,
+ skipped) {
var framework = Exercises.getCurrentFramework();
var data;
@@ -368,7 +372,10 @@ function buildAttemptData(correct, attemptNum, attemptContent, timeTaken) {
cards_left: Exercises.incompleteStack.length - 1,
// The user assessment key if in assessmentMode
- user_assessment_key: Exercises.userAssessmentKey
+ user_assessment_key: Exercises.userAssessmentKey,
+
+ // Whether the user is skipping the question
+ skipped: skipped ? 1 : 0
});
return data;
@@ -493,16 +500,24 @@ function updateUserExercise(e, data) {
function enableCheckAnswer() {
$("#check-answer-button")
- .removeAttr("disabled")
+ .prop("disabled", false)
.removeClass("buttonDisabled")
.val(originalCheckAnswerText);
+
+ $("#skip-question-button")
+ .prop("disabled", false)
+ .removeClass("buttonDisabled");
}
function disableCheckAnswer() {
$("#check-answer-button")
- .attr("disabled", "disabled")
+ .prop("disabled", true)
.addClass("buttonDisabled")
.val("Please wait...");
+
+ $("#skip-question-button")
+ .prop("disabled", true)
+ .addClass("buttonDisabled");
}
function clearExistingProblem() {
View
@@ -1277,7 +1277,7 @@ var Khan = (function() {
// Enable the all answer input elements except the check answer button.
$("#answercontent input").not("#check-answer-button")
- .removeAttr("disabled");
+ .prop("disabled", false);
if (examples !== null && answerData.examples && answerData.examples.length > 0) {
$("#examples-show").show();
@@ -1338,6 +1338,7 @@ var Khan = (function() {
// Note: We don't do this for multiple choice, number line, etc.
if (answerType === "text" || answerType === "number") {
var checkAnswerButton = $("#check-answer-button");
+ var skipQuestionButton = $("#skip-question-button");
checkAnswerButton.attr("disabled", "disabled").attr(
"title", "Type in an answer first.");
// Enables the check answer button - added so that people who type
@@ -1346,19 +1347,23 @@ var Khan = (function() {
$("#solutionarea")
.on("keypress.emptyAnswer", function(e) {
if (e.keyCode !== 13) {
- checkAnswerButton.removeAttr("disabled").removeAttr("title");
+ checkAnswerButton.prop("disabled", false)
+ .removeAttr("title");
}
})
.on("keyup.emptyAnswer", function(e) {
var guess = getAnswer();
if (checkIfAnswerEmpty(guess)) {
- checkAnswerButton.attr("disabled", "disabled");
+ skipQuestionButton.prop("disabled", false);
+ checkAnswerButton.prop("disabled", true);
} else if (e.keyCode !== 13) {
// Enable check answer button again as long as it is
// not the enter key
- checkAnswerButton.removeAttr("disabled");
+ checkAnswerButton.prop("disabled", false);
+ skipQuestionButton.prop("disabled", true);
}
});
+
}
return answerType;

0 comments on commit 736b7f5

Please sign in to comment.