Skip to content

Commit

Permalink
Indicate if user gave up first inside stamp
Browse files Browse the repository at this point in the history
Modify the stamp so that if the user gave up before
solving the lab, the stamp is subtly marked to indicate that.

Signed-off-by: David A. Wheeler <[email protected]>
  • Loading branch information
david-a-wheeler committed Jan 21, 2025
1 parent b3bb08b commit dbebac6
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion docs/labs/checker.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ let info = {}; // General info
let hints = []; // Array of hint objects
let page_definitions = {}; // Definitions used when preprocessing regexes

let user_solved = false; // True if user has *ever* solved it on this load
let user_gave_up = false; // True if user ever gave up before user solved it

// This array contains the default pattern preprocessing commands, in order.
// We process every pattern through these (in order) to create a final regex
// to be used to match a pattern.
Expand Down Expand Up @@ -292,7 +295,12 @@ function makeStamp() {
// when they're in a "secure state". We don't need the hash to be
// cryptographic, since the data is clearly in view. Use a simple one.
let hash = cyrb64Hash(resultBeginning);
return `Completed ${resultBeginning} ${hash}`;
let gave_up_indicator = '';
if (user_gave_up) { // If user gave up first, subtly indicate this.
// The user could reload later this and cause this marking to be omitted.
gave_up_indicator = ' (GA)';
}
return `Completed ${resultBeginning} ${hash}${gave_up_indicator}`;
}

/**
Expand All @@ -317,6 +325,7 @@ function runCheck() {

if (isCorrect && (oldGrade !== newGrade)) {
// Hooray! User has a newly-correct answer!
user_solved = true;

// Set `correctStamp` id (if present) with timestamp and UUID
// This makes it easy to detect someone simply copying a final result.
Expand Down Expand Up @@ -379,6 +388,9 @@ function showHint(e) {
function showAnswer(e) {
let formIndexes = findIndexes(e.target.form); // Indexes in this form
let goodAnswer = formIndexes.map(i => expected[i]).join('\n\n');
if (!user_solved) {
user_gave_up = true;
}
alert(`We were expecting an answer like this:\n${goodAnswer}`);
}

Expand Down

0 comments on commit dbebac6

Please sign in to comment.