Skip to content
Snippets Groups Projects
Commit 9d0e26ae authored by Jannik Wurche's avatar Jannik Wurche
Browse files

:scroll: add comments

parent ae00c2ca
No related branches found
No related tags found
No related merge requests found
......@@ -7,9 +7,11 @@ import Html.Events exposing (onClick)
import Utils.HelperFunction exposing (normalizeString)
import LaTeX.Expression
-- Main function to render the result view of the quiz.
resultView : Model -> Html Msg
resultView model =
let
-- Convert the answers to an HTML table.
content = answersToTable model.quiz.questions
in
div [ class "resultView" ]
......@@ -21,35 +23,40 @@ resultView model =
, a [ class "btn", href "/home", onClick ResetQuizID ] [ text "neu" ]]
]
-- Convert model.answers to a table
-- Convert list of questions to an HTML table.
answersToTable : List Question -> Html Msg
answersToTable q =
table []
[ tbody [] ( List.map answerToRow q) ]
-- Convert a single question to a table row.
answerToRow : Question -> Html Msg
answerToRow q =
let
key = "Frage " ++ (String.fromInt (q.id + 1))
-- Check if the user's answer is correct.
gotCorrect = evaluateQuestion q.questionType
-- Create a colored div based on correctness.
colorDiv = if gotCorrect
then
div [ class "colorDiv correct" ] []
else
div [ class "colorDiv false" ] []
-- Display the result based on question type.
result = case q.questionType of
MCQ a -> displayMcqResult gotCorrect a.correct a.userSelection
SCQ a -> displayScqResult gotCorrect a.correct a.userSelection
Input a -> displayInputResult gotCorrect a.correct a.userSelection
task = div [ class "task" ] [ LaTeX.Expression.compile q.task ]
in
-- Wrap the key, color div, and result in a table row.
tr []
[ td [] [ text key ]
, td [] [ colorDiv ]
, td [] [ div [] [ task, result] ]
]
-- Evaluate if the user's answer to a question is correct.
evaluateQuestion : QuestionType -> Bool
evaluateQuestion q =
case q of
......@@ -60,11 +67,12 @@ evaluateQuestion q =
str = if a.sensitive then a.userSelection else (normalizeString a.userSelection)
in List.member str a.correct
-- Display result for Multiple Choice Questions (MCQ).
displayMcqResult : Bool -> List String -> List String -> Html Msg
displayMcqResult gotCorrect correctAnswers userAnswers =
let
thisWasCorrect = String.join " und " correctAnswers
yourAnswer = String.join " und " userAnswers
thisWasCorrect = String.join " und " correctAnswers
yourAnswer = String.join " und " userAnswers
feedback = if gotCorrect
then
div [ class "innerResult" ]
......@@ -74,8 +82,10 @@ displayMcqResult gotCorrect correctAnswers userAnswers =
else
wrongAnswerDiv thisWasCorrect yourAnswer
in
-- Wrap the feedback in a result div.
div [ class "result"] [ feedback ]
-- Display result for Single Choice Questions (SCQ).
displayScqResult : Bool -> String -> String -> Html Msg
displayScqResult gotCorrect correctAnswer userAnswer =
let
......@@ -88,12 +98,14 @@ displayScqResult gotCorrect correctAnswer userAnswer =
else
wrongAnswerDiv correctAnswer userAnswer
in
-- Wrap the feedback in a result div.
div [ class "result"] [ feedback ]
-- Display result for input-based questions.
displayInputResult : Bool -> List String -> String -> Html Msg
displayInputResult gotCorrect correctAnswers userAnswer =
let
thisWasCorrect = String.join " oder " correctAnswers
thisWasCorrect = String.join " oder " correctAnswers
feedback = if gotCorrect
then
div [ class "innerResult" ]
......@@ -103,12 +115,15 @@ displayInputResult gotCorrect correctAnswers userAnswer =
else
wrongAnswerDiv thisWasCorrect userAnswer
in
-- Wrap the feedback in a result div.
div [ class "result"] [ feedback ]
-- Check if all elements in list 'a' are present in list 'b'.
areAllIn : List String -> List String -> Bool
areAllIn a b =
List.all (\x -> List.member x a) b
-- Display feedback for incorrect answers.
wrongAnswerDiv : String -> String -> Html Msg
wrongAnswerDiv correctAnswer userAnswer =
div [ class "innerResult" ]
......@@ -118,4 +133,4 @@ wrongAnswerDiv correctAnswer userAnswer =
, div [ class "vertical-line" ] []
, div [ class "answer" ]
[ p [ class "answer" ] [ text "Deine Antwort: "]
, p [ class "follow" ] [ LaTeX.Expression.compile userAnswer ] ]]
\ No newline at end of file
, p [ class "follow" ] [ LaTeX.Expression.compile userAnswer ] ]]
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment