Skip to content

Commit

Permalink
Merge pull request #74 from sl707/updates
Browse files Browse the repository at this point in the history
feat: show score button
  • Loading branch information
sl707 authored Feb 3, 2025
2 parents 2cf383a + 547c2d5 commit 76e76cf
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/pages/bowling-score-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ import s from 'styled-components'

const BowlingScoreGenerator = () => {
const [score, setScore] = useState([])

const [frame, setFrame] = useState(-1)
const [cumScore, setCumScore] = useState([])

const generateNewScore = () => {
setFrame(-1)
const strikeProb = 0.4
const spareProb = 0.75
const spareNumProbs = [
Expand Down Expand Up @@ -59,6 +60,12 @@ const BowlingScoreGenerator = () => {
setScore(newScore)
}

const showFrame = () => {
if (frame < 9) {
setFrame(frame + 1)
}
}

const calculateScore = () => {
let cumScore = 0
let rolls = []
Expand Down Expand Up @@ -107,10 +114,11 @@ const BowlingScoreGenerator = () => {
<div>
<div>
{score.map((elem, i) => (
<p key={i}>{elem}</p>
i <= frame && <p key={i}>{elem}</p>
))}
</div>
<button onClick={() => generateNewScore()}>Regenerate Score</button>
<button onClick={() => showFrame()}>Show Frame</button>
<button onClick={() => calculateScore()}>Calculate Score</button>
<div>{cumScore}</div>
</div>
Expand Down

0 comments on commit 76e76cf

Please sign in to comment.