/Stopwatch

Stopwatch

Primary LanguageJavaScript

Project Description: ๐Ÿš€

HTML:

  1. Element separation for improved DOM manipulation. ๐Ÿงฉ

CSS:

  1. Utilizing box-sizing to include padding, margin, and border in height and width calculations. ๐Ÿ“
  2. Using overflow: hidden to prevent scrolling and overflow to clip container content. ๐Ÿšซ
  3. Responsive design with em, rem, vh, vw units. ๐Ÿ“ฑ
  4. flex-wrap for responsive layout, flex-column for vertical alignment. ๐ŸŒ
  5. Media queries for max-width responsiveness. ๐Ÿ–ฅ๏ธ
  6. Animations for dynamic content transitions. ๐Ÿ”„
  7. Additional Details:
    • box-sizing: border-box; ensures that padding and border are included in the element's total width and height. ๐Ÿ“ฆ
    • overflow: hidden; disables scrolling, and strategic use of overflow is employed to clip content. ๐Ÿ”’
    • Units like em, rem, vh, and vw are used for automatic responsiveness with width adjustments. ๐Ÿ“
    • flex-wrap is applied for elements to stack vertically instead of overlapping. ๐Ÿ“
    • Animations are used for smooth transitions, like animating the displayed time. ๐ŸŽ‰
    • Media queries with max-width are used for responsiveness, setting maximum widths for layout adjustments. ๐Ÿ“

JavaScript:

  1. QuerySelector for accessing HTML elements using class and ID. ๐Ÿ”
  2. EventListener for constructing events, passing functions without parentheses. ๐ŸŽค
  3. Functions:
    • Toggle Start:
      • Determines whether to start or stop the stopwatch based on the current state (isRunning). โฏ๏ธ
      • Calls the appropriate function accordingly. ๐Ÿ“ž
    • Start Stopwatch:
      • Sets the starttime value. โฑ๏ธ
      • Adjusts the start time if the stopwatch was paused (pausetime is not zero). โธ๏ธ
      • Calls the updateStopWatchFunction to display and animate the stopwatch. ๐Ÿ”„
    • Pause Stopwatch:
      • Sets isRunning to false. โธ๏ธ
      • Records the pause time (pausetime) as the current time minus the start time. โฑ๏ธ
    • Update Stopwatch:
      • Calculates the elapsed time by subtracting the start time from the current time. โณ
      • Calls the formatTime function to convert the elapsed time into hours, minutes, and seconds. ๐Ÿ•ฐ๏ธ
      • Calls the displayTime function to update the displayed time. ๐Ÿ”„
      • Initiates an animation for the displayed time. ๐ŸŽ‰
    • Format Time:
      • Performs mathematical calculations to obtain hours, minutes, and seconds from the given time. ๐Ÿงฎ
      • Ensures the formatted time values are limited to two digits. ๐Ÿ”ข
      • Returns an object containing the formatted time values. ๐Ÿ“Š
    • Display Time:
      • Updates the HTML content for hours, minutes, and seconds with the values received in the object parameter. ๐Ÿ“ˆ
    • Resume Watch:
      • Sets isRunning to true. โ–ถ๏ธ
      • Adjusts starttime based on the original start time and any pause time. ๐Ÿ”„
      • Resets pausetime to zero. ๐Ÿ”„
      • Calls the updateStopWatchFunction to display and animate the resumed stopwatch. ๐Ÿ”„
    • Reset Stopwatch:
      • Resets the stopwatch to its initial state. ๐Ÿ”„
      • Sets isRunning to false, pausetime to zero. โŒ
      • Calls clearLaps to clear lap records. ๐Ÿ”„
      • Resets lap number to 1. 1๏ธโƒฃ
      • Updates the displayed time to zero. โฐ
    • Clear Laps:
      • Clears lap records by setting the innerHTML of the lap container to an empty string. ๐Ÿงน
      • Resets the lap number to 1. 1๏ธโƒฃ
    • Record Laps:
      • Checks if the stopwatch is running before creating a lap record. ๐Ÿƒ
      • Calculates lap time using the formatTime function. โฑ๏ธ
      • Creates a new div element using createElement. ๐Ÿ†•
      • Applies CSS styling to the div using classList. ๐ŸŽจ
      • Updates the innerHTML of the div with lap details using template literals. ๐Ÿ“
      • Appends the div to the lap container using appendChild. โž•

General:

  1. Dynamic use of backticks and ${} for string interpolation. ๐Ÿ”„
  2. Consistent use of camelCase for function and variable names. ๐Ÿซ
  3. Careful handling of conditional operations based on isRunning state. โš–๏ธ
  4. Strategic use of createElement, classList, and appendChild for dynamic content manipulation. ๐Ÿ› ๏ธ