MCPcopy Create free account
hub / github.com/code100x/daily-code / handleSubmit

Function handleSubmit

apps/web/components/mcq/MCQCard.tsx:38–77  ·  view source on GitHub ↗
(score: number)

Source from the content-addressed store, hash-verified

36 };
37
38 const handleSubmit = (score: number) => {
39 setIsSubmitted(!isSubmitted);
40 function getScore(atempted: any) {
41 let score = 0;
42 for (const key in atempted) {
43 if (atempted[key]) {
44 score++;
45 }
46 }
47 score = parseInt(((score / questions.length) * 100).toPrecision(3));
48 return score;
49 }
50 setScore(getScore(atempted));
51
52 console.log("in submit", score);
53 async function submitQuiz() {
54 try {
55 let score = getScore(atempted);
56 console.log("in submit", atempted);
57 await createQuizScore({
58 userId,
59 score,
60 problemId: problem.id,
61 });
62 toast({
63 description: "Submitted Successfully",
64 });
65 } catch (error) {
66 console.error("Error submitting quiz:", error);
67 toast({
68 description: "Failed to submit the quiz.",
69 });
70 }
71 }
72 toast({
73 description: "Submitting...",
74 });
75 console.log("Submitting...");
76 submitQuiz();
77 };
78
79 function giveFeedback() {
80 let scoreP = parseInt(((score / questions.length) * 100).toPrecision(3));

Callers 1

MCQCardFunction · 0.70

Calls 3

toastFunction · 0.90
getScoreFunction · 0.85
submitQuizFunction · 0.85

Tested by

no test coverage detected