scrimba
Speed Typing Game Part 4
Go Pro!Bootcamp

Bootcamp

Study group

Collaborate with peers in your dedicated #study-group channel.

Code reviews

Submit projects for review using the /review command in your #code-reviews channel

Speed Typing Game Part 4
AboutCommentsNotes
Speed Typing Game Part 4
Expand for more info
App.js
run
preview
console
import React, {useState} from "react"

/**
* Challenge:
*
* 1. Create state to hold the current value of the countdown timer.
* Display this time in the "Time Remaining" header
*/

function App() {
const [text, setText] = useState("")

function handleChange(e) {
const {value} = e.target
setText(value)
}

function calculateWordCount(text) {
const wordsArr = text.trim().split(" ")
return wordsArr.filter(word => word !== "").length
}

return (
<div>
<h1>How fast do you type?</h1>
<textarea
onChange={handleChange}
value={text}
/>
<h4>Time remaining: ???</h4>
<button onClick={() => console.log(calculateWordCount(text))}>Start</button>
<h1>Word count: ???</h1>
</div>
)
}

export default App
Console
/index.html
-6:01