Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix:Updated the WPM calculation logic #2

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
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>
);
}