-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fdaa363
commit d319632
Showing
6 changed files
with
164 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,101 @@ | ||
const NumbersCard = ({ currentCard, flipped, setFlipped }) => ( | ||
<div className="card-container"> | ||
<div | ||
className={`card ${flipped ? "flipped" : ""}`} | ||
onClick={() => setFlipped(!flipped)} | ||
> | ||
<div className="card-front"> | ||
<div className="card-front-content">{currentCard.text}</div> | ||
import React, { useState, useEffect } from "react"; | ||
import { Card, Button, Form } from "react-bootstrap"; | ||
|
||
const NumbersCard = ({ cards, currentCard, flipped, setFlipped }) => { | ||
const [answer, setAnswer] = useState(""); | ||
const [currentScore, setCurrentScore] = useState(0); | ||
const [bestScore, setBestScore] = useState(0); | ||
const [correct, setCorrect] = useState(false); | ||
|
||
useEffect(() => { | ||
setAnswer(""); | ||
}, [currentCard]); | ||
|
||
const handleFlip = () => { | ||
if (flipped) { | ||
setFlipped(!flipped); | ||
} | ||
}; | ||
|
||
const handleFormClick = (event) => { | ||
event.stopPropagation(); // prevent click event from propagating up to card | ||
}; | ||
|
||
const handleAnswerSubmit = (event) => { | ||
event.preventDefault(); | ||
setFlipped(!flipped); | ||
}; | ||
|
||
const handleAnswerChange = (event) => { | ||
const value = event.target.value; | ||
if (value.toLowerCase() == currentCard.number) { | ||
setCorrect(true); | ||
setCurrentScore((prevScore) => prevScore + 1); | ||
setBestScore((prevBestScore) => { | ||
if (currentScore + 1 > prevBestScore) { | ||
return currentScore + 1; | ||
} else { | ||
return prevBestScore; | ||
} | ||
}); | ||
} | ||
setAnswer(value); | ||
}; | ||
|
||
return ( | ||
<> | ||
<div> | ||
<p>{`Current Score: ${currentScore}/${cards.length}`}</p> | ||
<p>Best Score: {bestScore}</p> | ||
</div> | ||
<div className="card-back"> | ||
<div className="card-back-content">{currentCard.number}</div> | ||
<div className="card-container"> | ||
<Card | ||
className={`card ${flipped ? "flipped" : ""}`} | ||
onClick={handleFlip} | ||
> | ||
<div className="card-front"> | ||
<div className="card-front-content"> | ||
{" "} | ||
<Card.Body> | ||
<Card.Title>{currentCard.text}</Card.Title> | ||
<Form onSubmit={handleAnswerSubmit} onClick={handleFormClick}> | ||
<Form.Group controlId="formAnswer"> | ||
<Form.Label>Answer:</Form.Label> | ||
<Form.Control | ||
type="text" | ||
value={answer} | ||
onChange={handleAnswerChange} | ||
required | ||
/> | ||
</Form.Group> | ||
<Button variant="primary" type="submit"> | ||
Check | ||
</Button> | ||
</Form> | ||
</Card.Body> | ||
</div> | ||
</div> | ||
<div className="card-back"> | ||
<div className="card-back-content"> | ||
{" "} | ||
<Card.Body> | ||
<Card.Title> | ||
{correct ? ( | ||
<h4>Correct</h4> | ||
) : ( | ||
<> | ||
<h4>Incorrect</h4> | ||
<h6>{`Correct Answer: ${currentCard.number}`}</h6> | ||
</> | ||
)} | ||
</Card.Title> | ||
</Card.Body> | ||
</div> | ||
</div> | ||
</Card> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
</> | ||
); | ||
}; | ||
|
||
export default NumbersCard; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
.restart-modal-overlay { | ||
position: fixed; | ||
top: 0; | ||
left: 0; | ||
width: 100%; | ||
height: 100%; | ||
background-color: rgba(0, 0, 0, 0.5); | ||
z-index: 9999; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
} | ||
|
||
.restart-modal { | ||
background-color: white; | ||
border-radius: 5px; | ||
padding: 20px; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters