File size: 2,876 Bytes
17f2fbc
 
 
 
 
 
 
 
 
91de7fb
 
17f2fbc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91de7fb
 
 
 
 
17f2fbc
 
 
 
91de7fb
17f2fbc
 
 
 
91de7fb
 
17f2fbc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91de7fb
 
 
 
 
 
 
 
 
 
17f2fbc
91de7fb
17f2fbc
 
 
91de7fb
17f2fbc
 
 
91de7fb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
// 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();
}