ghost613 commited on
Commit
74378ac
·
verified ·
1 Parent(s): 640cab0

improved slightly mroe

Browse files
Files changed (1) hide show
  1. components/MathQuizApp.tsx +11 -5
components/MathQuizApp.tsx CHANGED
@@ -39,6 +39,7 @@ const MathQuizApp = () => {
39
  const [userAnswer, setUserAnswer] = useState('');
40
  const [result, setResult] = useState('');
41
  const [score, setScore] = useState(0);
 
42
  const [difficulty, setDifficulty] = useState('easy');
43
 
44
  const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
@@ -48,6 +49,7 @@ const MathQuizApp = () => {
48
  setScore(score + 1);
49
  } else {
50
  setResult(`Incorrect. The correct answer is ${question.answer}.`);
 
51
  }
52
  setUserAnswer('');
53
  setQuestion(generateQuestion(difficulty));
@@ -57,17 +59,22 @@ const MathQuizApp = () => {
57
  setDifficulty(e.target.value);
58
  setQuestion(generateQuestion(e.target.value));
59
  setScore(0);
 
60
  };
61
 
62
  return (
63
- <div className="max-w-3xl mx-auto p-8 mt-10 bg-white rounded-lg shadow-md">
64
  <h1 className="text-4xl font-bold mb-8 text-center">Math Quiz App</h1>
65
  <form onSubmit={handleSubmit} className="space-y-6">
66
- <div className="flex justify-between items-center">
 
 
 
 
67
  <select
68
  value={difficulty}
69
  onChange={handleDifficultyChange}
70
- className="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 p-2.5 w-48"
71
  >
72
  {difficulties.map((difficulty) => (
73
  <option key={difficulty} value={difficulty}>
@@ -75,9 +82,8 @@ const MathQuizApp = () => {
75
  </option>
76
  ))}
77
  </select>
78
- <p className="text-xl font-bold">Score: {score}</p>
79
  </div>
80
- <div className="text-center">
81
  <p className="text-3xl font-bold mb-6">
82
  What is {question.num1} {question.operation} {question.num2}?
83
  </p>
 
39
  const [userAnswer, setUserAnswer] = useState('');
40
  const [result, setResult] = useState('');
41
  const [score, setScore] = useState(0);
42
+ const [wrongAnswers, setWrongAnswers] = useState(0);
43
  const [difficulty, setDifficulty] = useState('easy');
44
 
45
  const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
 
49
  setScore(score + 1);
50
  } else {
51
  setResult(`Incorrect. The correct answer is ${question.answer}.`);
52
+ setWrongAnswers(wrongAnswers + 1);
53
  }
54
  setUserAnswer('');
55
  setQuestion(generateQuestion(difficulty));
 
59
  setDifficulty(e.target.value);
60
  setQuestion(generateQuestion(e.target.value));
61
  setScore(0);
62
+ setWrongAnswers(0);
63
  };
64
 
65
  return (
66
+ <div className="max-w-3xl mx-auto p-8 mt-20 bg-white rounded-lg shadow-md">
67
  <h1 className="text-4xl font-bold mb-8 text-center">Math Quiz App</h1>
68
  <form onSubmit={handleSubmit} className="space-y-6">
69
+ <div className="flex flex-col items-center gap-6">
70
+ <div className="flex gap-8 items-center justify-center">
71
+ <div className="text-xl font-bold">Correct: {score}</div>
72
+ <div className="text-xl font-bold text-red-500">Wrong: {wrongAnswers}</div>
73
+ </div>
74
  <select
75
  value={difficulty}
76
  onChange={handleDifficultyChange}
77
+ className="bg-gray-50 border border-gray-300 text-gray-900 text-lg rounded-lg focus:ring-blue-500 focus:border-blue-500 p-2.5 w-48 text-center"
78
  >
79
  {difficulties.map((difficulty) => (
80
  <option key={difficulty} value={difficulty}>
 
82
  </option>
83
  ))}
84
  </select>
 
85
  </div>
86
+ <div className="text-center mt-8">
87
  <p className="text-3xl font-bold mb-6">
88
  What is {question.num1} {question.operation} {question.num2}?
89
  </p>