Skip to content

Conversation

aashikofsach
Copy link

@aashikofsach aashikofsach commented Sep 6, 2025

Fixes : #15

Where we are formatting the seconds time, I change the value from 59 to 60.

Summary by CodeRabbit

  • Bug Fixes
    • Corrected the seconds-to-minutes rollover in the countdown timer to align with a true 60-second minute, removing an off-by-one error that could show 60 seconds or miscount at minute transitions.
    • Users now see accurate second decrements and reliable minute increments, improving the precision and predictability of the timer display.

Copy link

coderabbitai bot commented Sep 6, 2025

Walkthrough

Adjusted countdown rollover logic in machine-coding-interview-questions/countdown-timer/src/script.js: when seconds exceed 60, increment minutes and subtract 60 from seconds (previously 59). No other logic or public interfaces changed.

Changes

Cohort / File(s) Summary
Countdown rollover fix
machine-coding-interview-questions/countdown-timer/src/script.js
Corrected off-by-one in seconds-to-minutes rollover: when sec.value > 60, increment min.value and set sec.value = parseInt(sec.value) - 60 (was -59). No other changes.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant Timer as Timer Tick
  participant State as Time State (min, sec)

  Note over Timer,State: Per-second tick
  User->>Timer: Start countdown
  loop Every second
    Timer->>State: Decrement sec
    alt sec < 0
      State->>State: sec += 60<br/>min -= 1
    else sec > 60
      Note over State: Adjusting overflow
      State->>State: min += 1<br/>sec -= 60
    end
    Timer-->>User: Render updated mm:ss
  end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related issues

Poem

A tick, a tock, a tidy tune,
Sixty seconds meet their noon.
Hop! I nudge the minute hand—
No stray second roams the land.
Ears up high, I count with cheer,
Precise as carrots stacked this year. 🥕⏱️

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
machine-coding-interview-questions/countdown-timer/src/script.js (1)

33-37: Minutes normalization can drop time for values ≥ 120; carry hours and remove hard cap

The cap to 60 can lose minutes (e.g., 180m → 1h 60m). Normalize via floor/mod and eliminate the cap.

-    if (min.value > 60) {
-      hour.value++;
-      min.value = parseInt(min.value) - 60;
-    }
-    min.value = min.value > 60 ? 60 : min.value;
+    if (parseInt(min.value, 10) >= 60) {
+      var m = parseInt(min.value, 10);
+      hour.value = (parseInt(hour.value || 0, 10) + Math.floor(m / 60)).toString();
+      min.value = (m % 60).toString();
+    }
🧹 Nitpick comments (3)
machine-coding-interview-questions/countdown-timer/src/script.js (3)

29-33: Normalize seconds with >= 60 and carry multiple minutes

Also handle inputs like 120s (2 minutes) in one pass and specify radix.

-    if (sec.value > 60) {
-      min.value++;
-      sec.value = parseInt(sec.value) - 60;
-    }
+    if (parseInt(sec.value, 10) >= 60) {
+      var s = parseInt(sec.value, 10);
+      min.value = (parseInt(min.value || 0, 10) + Math.floor(s / 60)).toString();
+      sec.value = (s % 60).toString();
+    }

47-54: Simplify zero-padding with padStart and explicit parsing

Reduces coercion surprises and keeps formatting consistent.

-      sec.value = `${sec.value <= 10 ? "0" : ""}${sec.value - 1}`;
+      var sNext = parseInt(sec.value || "0", 10) - 1;
+      sec.value = String(sNext).padStart(2, "0");
@@
-      min.value = `${min.value <= 10 ? "0" : ""}${min.value - 1}`;
+      var mNext = parseInt(min.value || "0", 10) - 1;
+      min.value = String(mNext).padStart(2, "0");
@@
-      min.value = 60;
-      hour.value = `${hour.value <= 10 ? "0" : ""}${hour.value - 1}`;
+      min.value = 60;
+      var hNext = parseInt(hour.value || "0", 10) - 1;
+      hour.value = String(hNext).padStart(2, "0");

73-73: Comment label mismatch

This block ends the Stop button handler, not Start.

-  // Start Timer Button - END
+  // Stop Timer Button - END
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 8d2b593 and aa9ef88.

📒 Files selected for processing (1)
  • machine-coding-interview-questions/countdown-timer/src/script.js (1 hunks)
🔇 Additional comments (1)
machine-coding-interview-questions/countdown-timer/src/script.js (1)

31-31: Fix off-by-one in seconds rollover — LGTM

Changing 59 → 60 correctly normalizes values like 61s → 1m 1s instead of 2s.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] : In CountDown project, there is one second delay when seconds value is greater than 60.
1 participant