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

:scroll:add comments

parent 9d0e26ae
Branches
No related tags found
No related merge requests found
Pipeline #22346 passed
...@@ -11,10 +11,12 @@ import Html.Attributes exposing (href) ...@@ -11,10 +11,12 @@ import Html.Attributes exposing (href)
import String exposing (toLower, replace) import String exposing (toLower, replace)
-- Initialize an empty quiz.
initQuiz : Quiz initQuiz : Quiz
initQuiz = initQuiz =
Quiz "" "" Nothing [] Quiz "" "" Nothing []
-- URL parser for routing within the application.
urlParser : Url.Parser.Parser (Route -> a) a urlParser : Url.Parser.Parser (Route -> a) a
urlParser = urlParser =
Url.Parser.oneOf Url.Parser.oneOf
...@@ -24,20 +26,24 @@ urlParser = ...@@ -24,20 +26,24 @@ urlParser =
, Url.Parser.map ResultRoute <| Url.Parser.s "result" , Url.Parser.map ResultRoute <| Url.Parser.s "result"
] ]
-- Extract the route from a given URL.
getRoute : Url.Url -> Route getRoute : Url.Url -> Route
getRoute url = getRoute url =
Maybe.withDefault NotFound (Url.Parser.parse urlParser url) Maybe.withDefault NotFound (Url.Parser.parse urlParser url)
-- Create a view link element.
viewLink : String -> Html msg viewLink : String -> Html msg
viewLink path = viewLink path =
li [] [ a [ href path ] [ text path ] ] li [] [ a [ href path ] [ text path ] ]
-- Normalize a string by converting it to lowercase and removing spaces.
normalizeString : String -> String normalizeString : String -> String
normalizeString str = normalizeString str =
str str
|> toLower |> toLower
|> replace " " "" |> replace " " ""
-- Retrieve a question at a specific index from the list of questions.
getQuestionAt : Int -> List Question -> Maybe Question getQuestionAt : Int -> List Question -> Maybe Question
getQuestionAt index q = getQuestionAt index q =
case q of case q of
...@@ -49,6 +55,7 @@ getQuestionAt index q = ...@@ -49,6 +55,7 @@ getQuestionAt index q =
else else
Just x Just x
-- Update a question at a specific index with a new value.
updateQuestionsAt : Int -> String -> List Question -> List Question updateQuestionsAt : Int -> String -> List Question -> List Question
updateQuestionsAt index newValue q = updateQuestionsAt index newValue q =
case q of case q of
...@@ -62,13 +69,14 @@ updateQuestionsAt index newValue q = ...@@ -62,13 +69,14 @@ updateQuestionsAt index newValue q =
newQuestionType = case x.questionType of newQuestionType = case x.questionType of
MCQ a -> MCQ a ->
let let
-- Update the user selection for MCQ (Multiple Choice Question).
newUserSelection = if List.member newValue a.userSelection newUserSelection = if List.member newValue a.userSelection
then List.filter (\o -> o /= newValue) a.userSelection then List.filter (\o -> o /= newValue) a.userSelection
else a.userSelection ++ [newValue] else a.userSelection ++ [newValue]
in in
MCQ { a | userSelection = newUserSelection } MCQ { a | userSelection = newUserSelection }
SCQ a -> SCQ { a | userSelection = newValue } SCQ a -> SCQ { a | userSelection = newValue } -- Update the user selection for SCQ (Single Choice Question).
Input a -> Input { a | userSelection = newValue } Input a -> Input { a | userSelection = newValue } -- Update the user selection for Input type question.
newQuestion = {x | questionType = newQuestionType} newQuestion = {x | questionType = newQuestionType}
in in
newQuestion :: xs newQuestion :: xs
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment