Published on January 26, 2024By DeveloperBreeze
// Stopwatch functions
let startTime;
// Function to start the stopwatch
function startStopwatch() {
startTime = new Date();
}
// Function to stop the stopwatch and calculate elapsed time
function stopStopwatch() {
const endTime = new Date();
const elapsedTime = endTime - startTime;
console.log('Elapsed Time (ms):', elapsedTime);
}
// Starting the stopwatch
startStopwatch();
// Performing some tasks...
// Stopping the stopwatch after performing tasks
stopStopwatch();
Comments
Please log in to leave a comment.