Skip to content

Commit 30ded90

Browse files
committed
feat: green buttons when correct answer
1 parent 85b3c32 commit 30ded90

File tree

3 files changed

+35
-17
lines changed

3 files changed

+35
-17
lines changed

components/mdx/Question.tsx

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,13 @@ interface Question {
1515
]
1616
}
1717

18-
interface Answers {
19-
[index: string]: number
20-
}
21-
2218
const Question: FC<QuestionProps> = (props: QuestionProps) => {
2319
const question: Question = require(`../../utils/questions/${props.question}.json`)
2420
const [optionSelected, setOptionSelected]: [
2521
number,
2622
React.Dispatch<React.SetStateAction<number>>,
2723
] = useState(-1)
24+
const [answersSubmitted, setAnswersSubmitted] = useState(false)
2825
const toast = useToast()
2926

3027
const selectAnswer = (optionIndex: number) => {

components/mdx/Quiz.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ const Quiz: FC<QuizProps> = (props: QuizProps) => {
4242
const [showQuiz, setShowQuiz] = useState(false)
4343
const [currentQuestionIndex, setCurrentQuestionIndex] = useState(0)
4444
const [answers, setAnswers] = useState<Answers>({})
45+
const [correctAnswers, setCorrectAnswers] = useState<number[] | null>(null)
4546
const toast = useToast()
4647

4748
const nextQuestion = () => {
@@ -69,6 +70,15 @@ const Quiz: FC<QuizProps> = (props: QuizProps) => {
6970
}
7071

7172
const getQuestionBackground = (optionIndex: number) => {
73+
if (
74+
correctAnswers &&
75+
correctAnswers.indexOf(currentQuestionIndex) !== -1 &&
76+
quiz.questions[currentQuestionIndex].options[optionIndex].correct &&
77+
answers[currentQuestionIndex] === optionIndex
78+
) {
79+
return 'green.500'
80+
}
81+
7282
if (answers[currentQuestionIndex] == optionIndex) {
7383
return 'yellow.600'
7484
}
@@ -113,13 +123,19 @@ const Quiz: FC<QuizProps> = (props: QuizProps) => {
113123
let hasWrongAnswers = false
114124
let wrongAnswersCounter = 0
115125

126+
const newCorrectAnswers: number[] = []
127+
116128
quiz.questions.forEach((q, index) => {
117129
if (!q.options[answers[index]].correct) {
118130
hasWrongAnswers = true
119131
wrongAnswersCounter++
132+
} else {
133+
newCorrectAnswers.push(index)
120134
}
121135
})
122136

137+
setCorrectAnswers(newCorrectAnswers)
138+
123139
if (hasWrongAnswers) {
124140
return quizFailedToast(wrongAnswersCounter)
125141
}

pages/lessons/projects/1.mdx

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,6 @@ benefits to this decentralised model as we’ll continue to see.
122122

123123
</SideDrawer>
124124

125-
<Question question="question-1" />
126-
127125
## Let’s get this party started!
128126

129127
We’re going to write a smart contract, which is going to be a “Web3
@@ -299,15 +297,13 @@ contract WAGMI {
299297
<Callout emoji='💡' size='md' variant='info'>
300298
While private and internal are not readable or modifiable from other contracts, its values are set on a public blockchain, making its values visible from the outside world.
301299
</Callout>
302-
300+
303301
#### Which visibility should I use ?
304302

305303
A simple answer to this is , start with giving every variable a `private` visibility then as you move further in contract developement modify variables to `internal` visibility as a next step of modification. Try to use `public` visibility as little as possible in order to be gas efficient and making less vulnerabilities in the smart contract.
306304

307305
</SideDrawer>
308306

309-
<Question question="question-2" />
310-
311307
## Creating Functions
312308

313309
Our contract needs a way to store new information on the blockchain! But both
@@ -399,8 +395,6 @@ some more about them in **Variables** and **Functions**.
399395

400396
</SideDrawer>
401397

402-
<Question question="question-3" />
403-
404398
Ok, now we have to figure out a way to store some info on our contract!
405399

406400
We want to _set_ a new message in our contract, so now we define a new function
@@ -711,14 +705,25 @@ you see the magical spell that is being cast here?
711705
![Wizard Wooshing on Successful Lesson](/assets/lessons/1/img_10.png)
712706

713707
Before you go ahead and tell us: **what your future in web3 is,** have a check
714-
on what you didn’t know a little while ago, and what you know now! Take the quiz
715-
and prove your knowledge :)
708+
on what you didn’t know a little while ago, and what you know now! *
709+
710+
Apart from a user wallet, what else uses a blockchain (Ethereum) address?
711+
712+
How many parameters can we have in an event?
713+
714+
What can we use to find a past event?
715+
716+
Ethereum uses something for transaction fees. What’s it called?
717+
718+
Where do the values for event parameters get stored?
719+
720+
What is the use of the **pragma solidity** statement in our smart contract?
716721

717-
<br />
722+
Do state variables stay permanently on the blockchain?
718723

719-
<Quiz quiz="lesson-1" />
724+
Can a view function modify the state of the blockchain?
720725

721-
<br />
726+
What can we use a smart contract for?
722727

723728
**Now, go to the community in Discord to share your new Open Sourcerer
724-
powers**......and find the answers too!!!
729+
powers**......and find the answers too!!!

0 commit comments

Comments
 (0)