Mode:
Duration:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
module Main exposing (..)
import Browser
import Html exposing (Html, button, div, text)
import Html.Events exposing (onClick)
-- MODEL
type alias Model = { count : Int, isDark : Bool }
init : Model
init = { count = 0, isDark = False }
-- UPDATE
type Msg = Increment | Decrement | Reset | ToggleTheme
update : Msg -> Model -> Model
update msg model =
case msg of
Increment -> { model | count = model.count + 1 }
Decrement -> { model | count = model.count - 1 }
Reset -> { model | count = 0 }
ToggleTheme -> { model | isDark = not model.isDark }
-- VIEW
view : Model -> Html Msg
view model =
div []
[ div [] [ text ("Counter: " ++ String.fromInt model.count) ]
, div [] [ text ("Theme: " ++ (if model.isDark then "Dark" else "Light")) ]
, button [ onClick Increment ] [ text "+" ]
, button [ onClick Decrement ] [ text "-" ]
, button [ onClick Reset ] [ text "Reset" ]
, button [ onClick ToggleTheme ] [ text "Toggle Theme" ]
]
-- MAIN
main = Browser.sandbox { init = init, update = update, view = view }Coding works best on desktop or with an external keyboard.