Skip to content

Instantly share code, notes, and snippets.

@kamens
Created August 21, 2013 05:15
Show Gist options
  • Save kamens/6290546 to your computer and use it in GitHub Desktop.
Save kamens/6290546 to your computer and use it in GitHub Desktop.
Pokin' around code I shouldn't be pokin' around
diff --git a/interface.js b/interface.js
index 89a7c2c..aef728b 100644
--- a/interface.js
+++ b/interface.js
@@ -41,6 +41,7 @@ var PerseusBridge = Exercises.PerseusBridge,
numHints,
hintsUsed,
lastAttemptOrHint,
+ lastAttemptContent,
firstProblem = true;
$(Exercises)
@@ -128,6 +129,7 @@ function newProblem(e, data) {
numHints = data.numHints;
hintsUsed = data.userExercise ? data.userExercise.lastCountHints : 0;
lastAttemptOrHint = new Date().getTime();
+ lastAttemptContent = null;
var framework = Exercises.getCurrentFramework();
$("#problem-and-answer")
@@ -192,11 +194,21 @@ function handleAttempt(data) {
canAttempt = false;
}
- var curTime = new Date().getTime();
- var timeTaken = Math.round((curTime - lastAttemptOrHint) / 1000);
- var stringifiedGuess = JSON.stringify(score.guess);
+ var curTime = new Date().getTime(),
+ millisTaken = curTime - lastAttemptOrHint,
+ timeTaken = Math.round(millisTaken / 1000),
+ stringifiedGuess = JSON.stringify(score.guess);
+
lastAttemptOrHint = curTime;
+ // If user hasn't changed their answer and is resubmitting w/in one second
+ // of last attempt, don't allow this attempt. They're probably just
+ // smashing Enter.
+ if (stringifiedGuess === lastAttemptContent && millisTaken < 1000) {
+ return false;
+ }
+ lastAttemptContent = stringifiedGuess;
+
Exercises.guessLog.push(score.guess);
Exercises.userActivityLog.push([
score.correct ? "correct-activity" : "incorrect-activity",
@@ -362,6 +374,7 @@ function onHintShown(e, data) {
var curTime = new Date().getTime();
var timeTaken = Math.round((curTime - lastAttemptOrHint) / 1000);
lastAttemptOrHint = curTime;
+ lastAttemptContent = null;
Exercises.userActivityLog.push(["hint-activity", "0", timeTaken]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment