generated from Arquisoft/wiq_0
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Lógica de respuesta correcta implementada
- Loading branch information
Showing
4 changed files
with
64 additions
and
30 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
Paleta de colores--> | ||
fondo: https://www.canva.com/colors/color-palettes/northern-lights-4/ | ||
botones: https://www.canva.com/colors/color-palettes/arts-and-crafts/ | ||
Generador css-->https://front-end-tools.com/en/generateButton/ | ||
Chakra UI-->https://chakra-ui.com/docs/styled-system/style-props | ||
|
||
Para empezar en local: npm start |
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,25 +1,37 @@ | ||
import { Box } from "@chakra-ui/react"; | ||
import React, { useEffect, useState } from 'react'; | ||
import { AnswerButton } from './AnswerButton.jsx'; | ||
|
||
export function AnswersBlock({ respuestas }){ | ||
export function AnswersBlock({ respuestas, correcta }){ | ||
|
||
const correcta = respuestas[0]; | ||
//Ordenar random | ||
//Intercambiar el primer elemento con otro elemento aleatorio del array | ||
const indiceAleatorio = Math.floor(Math.random() * (respuestas.length - 1)); | ||
const save = respuestas[0]; | ||
respuestas[0] = respuestas[indiceAleatorio]; | ||
respuestas[indiceAleatorio] = save; | ||
const [respuestasAleatorizadas, setRespuestasAleatorizadas] = useState([]); | ||
|
||
console.log(correcta); | ||
let respuestasCopy = respuestas; | ||
|
||
return( | ||
<Box display="grid" flex="1" gridTemplateColumns="repeat(2,1fr)" | ||
gridColumnGap="2em" padding="4em" alignItems="center"> | ||
<AnswerButton text={respuestas[0]} colorFondo={"#A06AB4"}/> | ||
<AnswerButton text={respuestas[1]} colorFondo={"#B5EECB"}/> | ||
<AnswerButton text={respuestas[2]} colorFondo={"#FFD743"}/> | ||
<AnswerButton text={respuestas[3]} colorFondo={"#D773A2"}/> | ||
useEffect(() => { | ||
//Baraja con algoritmo de Fisher-Yates | ||
for (let i = respuestasCopy.length - 1; i > 0; i--) { | ||
const j = Math.floor(Math.random() * (i + 1)); | ||
[respuestasCopy[i], respuestasCopy[j]] = [respuestasCopy[j], respuestasCopy[i]]; | ||
} | ||
|
||
setRespuestasAleatorizadas(respuestasCopy); | ||
}, [respuestasCopy]); | ||
|
||
const handleButtonClick = (respuesta) => { | ||
if (respuesta === correcta) { | ||
alert("¡Respuesta correcta!"); | ||
} else { | ||
alert("Respuesta incorrecta."); | ||
} | ||
console.log("owimawe"); | ||
}; | ||
|
||
return ( | ||
<Box display="grid" flex="1" gridTemplateColumns="repeat(2,1fr)" gridColumnGap="2em" padding="4em" alignItems="center"> | ||
{respuestasAleatorizadas.map((respuesta, index) => ( | ||
<AnswerButton key={index} text={respuesta} colorFondo={"#A06AB4"} onClick={() => handleButtonClick(respuesta)} /> | ||
))} | ||
</Box> | ||
) | ||
} | ||
); | ||
} |
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