diff --git a/src/Utils/HelperFunction.elm b/src/Utils/HelperFunction.elm index 1c582705c09e4fb8a6ccdefbaee9ac5d32f9e680..9924aec441d7673f81efdcc777befe7c56cf6d3f 100644 --- a/src/Utils/HelperFunction.elm +++ b/src/Utils/HelperFunction.elm @@ -11,10 +11,12 @@ import Html.Attributes exposing (href) import String exposing (toLower, replace) +-- Initialize an empty quiz. initQuiz : Quiz initQuiz = Quiz "" "" Nothing [] +-- URL parser for routing within the application. urlParser : Url.Parser.Parser (Route -> a) a urlParser = Url.Parser.oneOf @@ -24,20 +26,24 @@ urlParser = , Url.Parser.map ResultRoute <| Url.Parser.s "result" ] +-- Extract the route from a given URL. getRoute : Url.Url -> Route getRoute url = Maybe.withDefault NotFound (Url.Parser.parse urlParser url) +-- Create a view link element. viewLink : String -> Html msg viewLink path = li [] [ a [ href path ] [ text path ] ] +-- Normalize a string by converting it to lowercase and removing spaces. normalizeString : String -> String normalizeString str = str |> toLower |> replace " " "" +-- Retrieve a question at a specific index from the list of questions. getQuestionAt : Int -> List Question -> Maybe Question getQuestionAt index q = case q of @@ -49,6 +55,7 @@ getQuestionAt index q = else Just x +-- Update a question at a specific index with a new value. updateQuestionsAt : Int -> String -> List Question -> List Question updateQuestionsAt index newValue q = case q of @@ -62,13 +69,14 @@ updateQuestionsAt index newValue q = newQuestionType = case x.questionType of MCQ a -> let + -- Update the user selection for MCQ (Multiple Choice Question). newUserSelection = if List.member newValue a.userSelection then List.filter (\o -> o /= newValue) a.userSelection else a.userSelection ++ [newValue] in MCQ { a | userSelection = newUserSelection } - SCQ a -> SCQ { a | userSelection = newValue } - Input a -> Input { a | userSelection = newValue } + SCQ a -> SCQ { a | userSelection = newValue } -- Update the user selection for SCQ (Single Choice Question). + Input a -> Input { a | userSelection = newValue } -- Update the user selection for Input type question. newQuestion = {x | questionType = newQuestionType} in - newQuestion :: xs \ No newline at end of file + newQuestion :: xs