Skip to content

Instantly share code, notes, and snippets.

View Bviveksingh's full-sized avatar
🙂
Focusing

Vivek Singh Bisht Bviveksingh

🙂
Focusing
View GitHub Profile
@Bviveksingh
Bviveksingh / index.tsx
Created September 16, 2022 06:28
understanding setDifficulty function
const setDifficulty = (value: number) => {
setDifficultyLevel(value);
setDisplayVal(paragraphs[value]); /*----THIS LINE SETS THE DISPLAY VALUE (STRING) ----*/
}
@Bviveksingh
Bviveksingh / index.tsx
Created September 16, 2022 06:26
definition of displayVal
const [displayVal, setDisplayVal] = useState<string>('');
@Bviveksingh
Bviveksingh / index.tsx
Created September 16, 2022 06:09
computeResult function definition
const computeResult = () => {
const result = (inputVal.length / 5) / minutes;
const percentage = (((inputVal.length - incorrectEntry) / inputVal.length) * 100).toFixed(2);
setWordsPerMin(result);
setAccuracy(parseFloat(percentage));
}
@Bviveksingh
Bviveksingh / index.tsx
Created September 15, 2022 19:44
definition of displayResult
const displayResult = () => {
return(
<div>
<p>The words per minute written: {wordsPerMin}</p>
<p>Percentage Accuracy: {accuracy}%</p>
</div>
)
};
@Bviveksingh
Bviveksingh / index.tsx
Created September 15, 2022 19:41
supplying props to displayResult
{endTimer && displayResult()}
@Bviveksingh
Bviveksingh / index.tsx
Created September 15, 2022 19:39
definition of resetTest
const resetTest = () => {
setEndTimer(false);
setInputVal('');
setInpBoxSplit([]);
setWordsPerMin(undefined);
setAccuracy(0);
setDifficultyLevel(undefined);
setIncorrectEntry(0);
setTimeInSeconds(0);
setElegibleToStart(false);
@Bviveksingh
Bviveksingh / index.tsx
Created September 15, 2022 19:37
providing props to reset button
{inputVal.length > 0 && <button onClick={() => resetTest()}>Reset</button>}
@Bviveksingh
Bviveksingh / index.tsx
Created September 15, 2022 19:36
providing props to inputBox
{!endTimer && eligibleToStart && <InputBox value={inputVal} onChange={(e) => setInputVal(e.target.value)}/>}
@Bviveksingh
Bviveksingh / index.tsx
Created September 15, 2022 19:14
providing props to Paragraph
{paragraphArr.length > 0 && <Paragraph value={paragraphArr.length > 0 ? paragraphArr : [] }/>}
@Bviveksingh
Bviveksingh / index.tsx
Created September 15, 2022 19:11
define setDifficulty
const setDifficulty = (value: number) => {
setDifficultyLevel(value);
setDisplayVal(paragraphs[value]);
}