allthewhile's picture
This is supposed to be projected so when the calculation is created, it should look good for projector. There should also be a way to pause and reset the timer.
91de7fb verified
Raw
History Blame Contribute Delete
2.88 kB
// Reading speeds in words per minute by grade level
const readingSpeeds = {
'5': 137,
'6': 141,
'7': 141,
'8': 135
};
let timerInterval;
let secondsRemaining = 0;
let isPaused = false;
let totalSeconds = 0;
function calculateReadingTime() {
const gradeLevel = document.getElementById('gradeLevel').value;
const wordCountInput = document.getElementById('wordCount').value;
if (!gradeLevel) {
alert('Please select a grade level');
return;
}
const wordCount = parseInt(wordCountInput);
if (isNaN(wordCount) || wordCount <= 0) {
alert('Please enter a valid word count');
return;
}
const wpm = readingSpeeds[gradeLevel];
const minutes = Math.ceil(wordCount / wpm);
// Display results
document.getElementById('wpmResult').textContent = wpm;
document.getElementById('timeResult').textContent = minutes;
document.getElementById('resultContainer').classList.remove('hidden');
// Prepare timer
secondsRemaining = minutes * 60;
updateTimerDisplay();
document.getElementById('timerContainer').classList.remove('hidden');
}
function updateTimerDisplay() {
const minutes = Math.floor(secondsRemaining / 60);
const seconds = secondsRemaining % 60;
document.getElementById('timerDisplay').textContent =
`${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
}
function startTimer() {
if (isPaused) {
isPaused = false;
return;
}
if (timerInterval) {
clearInterval(timerInterval);
}
totalSeconds = secondsRemaining;
const timerDisplay = document.getElementById('timerDisplay');
timerDisplay.classList.add('timer-pulse');
timerInterval = setInterval(() => {
if (isPaused) return;
if (secondsRemaining <= 0) {
clearInterval(timerInterval);
timerDisplay.classList.remove('timer-pulse');
timerDisplay.classList.add('text-red-500');
return;
}
secondsRemaining--;
updateTimerDisplay();
// Flash when under 10 seconds
if (secondsRemaining <= 10) {
timerDisplay.classList.toggle('text-red-500');
}
}, 1000);
}
function pauseTimer() {
isPaused = !isPaused;
const timerDisplay = document.getElementById('timerDisplay');
if (isPaused) {
timerDisplay.classList.remove('timer-pulse');
} else {
timerDisplay.classList.add('timer-pulse');
}
}
function resetTimer() {
isPaused = false;
if (timerInterval) {
clearInterval(timerInterval);
}
secondsRemaining = totalSeconds;
const timerDisplay = document.getElementById('timerDisplay');
timerDisplay.classList.remove('timer-pulse', 'text-red-500');
updateTimerDisplay();
}