diff --git a/src/App.js b/src/App.js index 15097913..51a2778a 100644 --- a/src/App.js +++ b/src/App.js @@ -1,3 +1,4 @@ +import { useState } from 'react'; import './index.scss'; const questions = [ @@ -8,7 +9,11 @@ const questions = [ }, { title: 'Компонент - это ... ', - variants: ['приложение', 'часть приложения или страницы', 'то, что я не знаю что такое'], + variants: [ + 'приложение', + 'часть приложения или страницы', + 'то, что я не знаю что такое', + ], correct: 1, }, { @@ -22,37 +27,67 @@ const questions = [ }, ]; -function Result() { +function Result({ correct }) { return (
-

Вы отгадали 3 ответа из 10

- +

+ Вы отгадали {correct} ответа из {questions.length} +

+ + +
); } -function Game() { +function Game({ step, question, onClickAnswer }) { + const percentage = Math.round(step / questions.length); + return ( <>
-
+
-

Что такое useState?

+

{question.title}

); } function App() { + const [step, setStep] = useState(0); + const [correct, setCorrect] = useState(0); + const question = questions[step]; + + const handleClickAnswer = (index) => { + setStep(step + 1); + + if (index === question.correct) { + setCorrect(correct + 1); + } + }; + return (
- - {/* */} + {step !== questions.length ? ( + + ) : ( + + )}
); }