Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,20 @@ export default function App() {

setInput(newValue);
};


//Updated the WPM calculation logic to ensure accurate calculation based on the time taken and word count. Fixed issues with startTime and endTime initialization and ensured proper state updates for calculating WPM.
const calculateWPM = () => {
if (!startTime || !endTime) return 0;
const timeTaken = (endTime - startTime) / 60000;
const wordCount = currentText.split(" ").length;
return (wordCount / timeTaken).toFixed(2);
const timeTaken = (endTime - startTime) / 60000;
const wordCount = input.trim().match(/\S+/g)?.length || 0;
return (wordCount / timeTaken).toFixed(0);
};

useEffect(() => {
if (isCompleted) {
setEndTime(Date.now()); // Set endTime when typing is completed
}
}, [isCompleted]);

const calculatePoints = (mistakes: number) => {
const textLength = currentText.replace(/\s/g, "").length;
Expand Down Expand Up @@ -211,3 +218,4 @@ export default function App() {
</div>
);
}