diff --git a/src/script.js b/src/script.js index bc14519..509ed6b 100644 --- a/src/script.js +++ b/src/script.js @@ -10,7 +10,7 @@ function countUpFromTime(countFrom, id) { const now = new Date(); // Validate date - const isValidDate = !isNaN(countFromDate.getTime()); + const isValidDate = !Number.isNaN(countFromDate.getTime()); // Get DOM element const idEl = document.getElementById(id); diff --git a/src/style.css b/src/style.css index b913d7c..8d4dbbc 100644 --- a/src/style.css +++ b/src/style.css @@ -25,7 +25,7 @@ h2 { font-size: 2.5em; font-weight: 700; padding: 3rem; - color: #3cbaf2; + color: #2196F3; background-color: #0ff; background-color: rgba(0, 0, 0, .5); text-align: center; @@ -74,7 +74,7 @@ h2 { gap: 20px; text-align: center; margin: 0 auto; - color: #3cbaf2; + color: #2196F3; background-color: rgba(0, 0, 0, .5); padding: 20px; max-width: 90%; diff --git a/tests/script.test.js b/tests/script.test.js index 8de1891..a2e327e 100644 --- a/tests/script.test.js +++ b/tests/script.test.js @@ -169,6 +169,20 @@ describe('countUpFromTime', () => { expect(Number(mockEl.hours.innerHTML)).toBeGreaterThanOrEqual(0); }); + test('covers for-loop else branch (break) when remainingDays < daysInYear', () => { + // Freeze time to a known date so the loop runs exactly once and hits the else branch + jest.useFakeTimers(); + jest.setSystemTime(new Date('Nov 01, 2025 12:00:00')); + const mockEl = createMockDOM(); + global.document.getElementById = jest.fn(() => mockEl); + // Choose a date in the previous year but with remaining days less than a full year + script.countUpFromTime('Dec 31, 2024 00:00:00', 'countup1'); + // The function should have written numeric values to the DOM + expect(Number(mockEl.years.innerHTML)).toBeGreaterThanOrEqual(0); + expect(Number(mockEl.days.innerHTML)).toBeGreaterThanOrEqual(0); + jest.useRealTimers(); + }); + test('updates DOM elements with correct values', () => { jest.useFakeTimers(); jest.setSystemTime(new Date('Sep 13, 2025 11:59:00'));