Javascript code:
newOutput(); print("Warmup"); // Middle pane, where tasks are displayed var taskPane = document.getElementById("interaction-pane"); // Number of tasks to display. var numTasks = 10; // State of the current task. var correctAnswer; // either "A" or "B" for now var startTime; // time when task started // Some CSS styles as helpful constants. var BOLD = "font-weight: bold;"; var PLAIN = "font-weight: plain;"; var SERIF = "font-family: serif;"; var SANS_SERIF = "font-family: sans-serif;"; var BIG = "font-size: 20pt;"; var SMALL = "font-size: 8pt;"; // Display the next task to the user and // start timing the user's response. function nextTask() { correctAnswer = random(2) ? "A" : "B"; var style = BIG + BOLD + SERIF; taskPane.innerHTML = "<div style='" + style + "'>" + correctAnswer + "</div>"; startTime = new Date().getTime(); } // Return a random integer in [0,n-1] function random(n) { return Math.floor(Math.random() * n); } // Handle the user's answer (a string with // the character that the user pressed). function handleAnswer(answer) { var time = new Date().getTime() - startTime; var message = time + " " + answer; if (answer.toLowerCase() != (""+correctAnswer).toLowerCase()) { message += "(wrong: should be " + correctAnswer + ")"; } print(message); if (--numTasks <= 0) { taskPane.innerHTML = ""; alert("Done! Thank you."); } else { nextTask(); } } // Pause until the user is ready to start, // then show the first task. taskPane.innerHTML = ""; alert("Press Enter when ready"); nextTask();
Run