Student 1
Ready to race! Press Start Race to begin.
Ready to race! Press Start Race to begin.
Ready to race! Press Start Race to begin.
Ready to race! Press Start Race to begin.
Log in with your Google Sheets credentials to load your saved quiz & check access days.
Stores usernames, passwords, auto-subtracting access days, and custom questions.
Open sheets.new, click Extensions → Apps Script, paste the code from Code.gs, and click Run → setupDatabase.
Running setupDatabase automatically creates the Accounts tab, headers, starter logins (teacher1 / 12345 with 90 days), and the daily midnight countdown trigger!
const SHEET_NAME = 'Accounts';
function setupDatabase() {
const ss = SpreadsheetApp.getActiveSpreadsheet();
let sheet = ss.getSheetByName(SHEET_NAME);
if (!sheet) {
const firstSheet = ss.getSheets()[0];
if (firstSheet && firstSheet.getLastRow() === 0) {
firstSheet.setName(SHEET_NAME);
sheet = firstSheet;
} else {
sheet = ss.insertSheet(SHEET_NAME);
}
}
if (sheet.getLastRow() === 0) {
const headers = ['Username', 'Password', 'DaysLeft', 'LastChecked', 'QuestionsJSON'];
sheet.getRange(1, 1, 1, headers.length).setValues([headers]);
sheet.getRange(1, 1, 1, headers.length).setBackground('#1e3a8a').setFontColor('#ffffff').setFontWeight('bold');
sheet.setFrozenRows(1);
const todayStr = Utilities.formatDate(new Date(), Session.getScriptTimeZone(), 'yyyy-MM-dd');
sheet.getRange(2, 1, 2, 5).setValues([
['teacher1', '12345', 90, todayStr, '[]'],
['teacher2', 'quiz2026', 30, todayStr, '[]']
]);
}
const hasTrigger = ScriptApp.getProjectTriggers().some(t => t.getHandlerFunction() === 'dailySubtractDays');
if (!hasTrigger) {
ScriptApp.newTrigger('dailySubtractDays').timeBased().everyDays(1).atHour(0).create();
}
}
function doPost(e) {
const lock = LockService.getScriptLock();
lock.waitLock(10000);
try {
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(SHEET_NAME);
const payload = JSON.parse(e.postData.contents || '{}');
const username = String(payload.username || '').trim();
const password = String(payload.password || '').trim();
const data = sheet.getDataRange().getValues();
const todayStr = Utilities.formatDate(new Date(), Session.getScriptTimeZone(), 'yyyy-MM-dd');
const todayMs = new Date(todayStr + 'T00:00:00Z').getTime();
for (let i = 1; i < data.length; i++) {
const rowUser = String(data[i][0] || '').trim();
const rowPass = String(data[i][1] || '').trim();
if (rowUser.toLowerCase() === username.toLowerCase() && rowPass === password) {
let daysLeft = Number(data[i][2]) || 0;
const rawLast = data[i][3];
const lastStr = rawLast instanceof Date ? Utilities.formatDate(rawLast, Session.getScriptTimeZone(), 'yyyy-MM-dd') : String(rawLast || '').trim();
const elapsed = lastStr ? Math.max(0, Math.floor((todayMs - new Date(lastStr + 'T00:00:00Z').getTime()) / 86400000)) : 0;
if (elapsed > 0) {
daysLeft = Math.max(0, daysLeft - elapsed);
sheet.getRange(i + 1, 3).setValue(daysLeft);
}
sheet.getRange(i + 1, 4).setValue(todayStr);
if (daysLeft <= 0) {
return ContentService.createTextOutput(JSON.stringify({ success: false, expired: true, message: 'Account expired (0 days left).' })).setMimeType(ContentService.MimeType.JSON);
}
if (payload.action === 'login') {
let questions = [];
try { if (data[i][4]) questions = JSON.parse(data[i][4]); } catch (err) {}
return ContentService.createTextOutput(JSON.stringify({ success: true, username: rowUser, daysLeft: daysLeft, questions: questions })).setMimeType(ContentService.MimeType.JSON);
}
if (payload.action === 'saveQuestions') {
sheet.getRange(i + 1, 5).setValue(JSON.stringify(payload.questions || []));
return ContentService.createTextOutput(JSON.stringify({ success: true, daysLeft: daysLeft })).setMimeType(ContentService.MimeType.JSON);
}
}
}
return ContentService.createTextOutput(JSON.stringify({ success: false, message: 'Invalid username or password.' })).setMimeType(ContentService.MimeType.JSON);
} finally {
lock.releaseLock();
}
}
function dailySubtractDays() {
const sheet = SpreadsheetApp.getActiveSpreadsheet().getSheetByName(SHEET_NAME);
if (!sheet) return;
const data = sheet.getDataRange().getValues();
const todayStr = Utilities.formatDate(new Date(), Session.getScriptTimeZone(), 'yyyy-MM-dd');
for (let i = 1; i < data.length; i++) {
const daysLeft = Number(data[i][2]) || 0;
const rawLast = data[i][3];
const lastStr = rawLast instanceof Date ? Utilities.formatDate(rawLast, Session.getScriptTimeZone(), 'yyyy-MM-dd') : String(rawLast || '').trim();
if (daysLeft > 0 && lastStr !== todayStr) {
sheet.getRange(i + 1, 3).setValue(daysLeft - 1);
sheet.getRange(i + 1, 4).setValue(todayStr);
}
}
}
Click Deploy → New deployment, choose Web app, set Execute as: Me and Who has access: Anyone, click Deploy, and paste the generated https://script.google.com/macros/s/.../exec link into the login box!
All 3 students see the exact same question simultaneously. Lock in your answer first—ties in points are broken by your cumulative reaction speed!
| # | Question | Student 1 | Student 2 | Student 3 |
|---|
Create your own questions, paste a list, or customize student names & keys.
Paste one question per line using the pipe | separator:
Question Text | Choice 1 | Choice 2 | Choice 3 | CorrectChoiceNumber (1, 2, or 3)
Each student uses 3 dedicated keys (one for Choice 1, Choice 2, and Choice 3).