Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed answer value always undefined error. #67

Merged
merged 1 commit into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
<v-container>
<v-row class="pa-0 d-flex w-100 justify-space-between align-center">
<v-btn color="green" :disabled="!selected && !providedAnswer"
@click="checkCorrectAnswer(card, selected.length ? selected : [providedAnswer])" variant="text" border>
@click="checkCorrectAnswer(card, selected.length ? selected : [providedAnswer])" variant="text"
border>
<v-icon icon="mdi-check" size="large" start/>
Check Answer
</v-btn>
Expand Down Expand Up @@ -98,16 +99,19 @@ const toggleOption = (option: string, card: Card) => {
const checkCorrectAnswer = (card: Card, answers: string[]) => {
answerShown.value = !answerShown.value;
const correctAnswer = getCorrectAnswer(card);
console.log(correctAnswer);
isCorrectAnswer.value = answers.every(answer => correctAnswer?.includes(answer));
};

const getCorrectAnswer = (card: Card) => {
console.log("card type is " , card.type);
switch (card.type) {
case CardType.SINGLE_CHOICE:
return card.options[Number(card.correctOption)];
case CardType.SIMPLEQA:
return [card.answer];
case CardType.MULTIPLE_CHOICE:
console.log("correct options are here ", card.correctOptions);
return card.correctOptions.map(i => card.options[Number(i)]).join(", ");
}
};
Expand Down
6 changes: 3 additions & 3 deletions frontend/src/feature/cards/model/card.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export enum CardType {
SIMPLEQA = 'qna',
SINGLE_CHOICE = 'scq',
MULTIPLE_CHOICE = 'mcq'
SIMPLEQA = 'QNA',
SINGLE_CHOICE = 'SCQ',
MULTIPLE_CHOICE = 'MCQ'
}

export type CardItem = {
Expand Down
Loading