Skip to content

Commit

Permalink
Arreglado error en la comprobación de la respuesta correcta
Browse files Browse the repository at this point in the history
  • Loading branch information
uo289792 committed Mar 9, 2024
1 parent 394cc29 commit 2b048e9
Showing 1 changed file with 8 additions and 18 deletions.
26 changes: 8 additions & 18 deletions webapp/src/components/Game.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ const Game = () => {
const [selectedOption, setSelectedOption] = useState('');
const [openSnackbar, setOpenSnackbar] = useState(false);
const [elapsedTime,setElapsedTime] = useState(30);
const [answerCorrect, setAnswerCorrect] = useState(false);
const MAX_TIME = 30;

const [answerCorrect, setAnswerCorrect] = useState(false);

useEffect(() => {
getQuestion();
}, []);
Expand Down Expand Up @@ -56,14 +55,10 @@ const Game = () => {
const handleOptionClick = (option) => {
setSelectedOption(option);
setOpenSnackbar(true);
if (correctOption === option) {
setAnswerCorrect(true);
} else {
setAnswerCorrect(false);
}
setAnswerCorrect(correctOption === option);
setTimeout(() => {
getQuestion();
}, 3000);
}, 1500);
};

const handleCloseSnackbar = () => {
Expand All @@ -84,17 +79,12 @@ const Game = () => {
{question}
</Typography>
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(2, 1fr)', gap: '10px', alignItems: 'center', marginTop: '20px' }}>
{options.map((option, index) => {
const isSelected = option === selectedOption;
var buttonColor = isSelected ? (answerCorrect ? 'green' : 'red') : 'primary';
return (
<Button key={index} variant="contained" color={buttonColor} disabled={waitingAnswer} onClick={() => handleOptionClick(option)} style={{ width: '100%', height: '100%' }}>
{option}
</Button>
);
})}
{options.map((option, index) => (
<Button key={index} variant="contained" color={selectedOption === option ? (answerCorrect ? 'success' : 'error') : 'primary'} onClick={() => handleOptionClick(option)} style={{ width: '100%', height: '100%' }}>
{option}
</Button>
))}
</div>
<Snackbar open={openSnackbar} autoHideDuration={6000} onClose={handleCloseSnackbar} />
{error && (
<Snackbar open={!!error} autoHideDuration={6000} onClose={() => setError('')} message={`Error: ${error}`} />
)}
Expand Down

0 comments on commit 2b048e9

Please sign in to comment.