Skip to content

Instantly share code, notes, and snippets.

@b-rodrigues
Created May 9, 2019 19:39
Show Gist options
  • Save b-rodrigues/d0d505aa8412b2cb3b66a749f902d418 to your computer and use it in GitHub Desktop.
Save b-rodrigues/d0d505aa8412b2cb3b66a749f902d418 to your computer and use it in GitHub Desktop.
elm reverse, but it's not working
import Browser
import Html exposing (Html, Attribute, div, input, text, button)
import Html.Attributes exposing (..)
import Html.Events exposing (onClick)
-- MAIN
main =
Browser.sandbox { init = init, update = update, view = view }
-- MODEL
type alias Model =
{ content : String,
reversed : String
}
init : Model
init =
{ content = "",
reversed = ""}
-- UPDATE
type Msg = Reverse
update : Msg -> Model -> Model
update msg model =
case msg of
Reverse ->
{ model | reversed = String.reverse model.content }
-- VIEW
view : Model -> Html Msg
view model =
div []
[ input [placeholder "Text to reverse"] []
, button [ onClick Reverse ] [ text "Reverse" ]
, div[] [ text model.reversed ]
]
@b-rodrigues
Copy link
Author

nothing happens when clicking on the button

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment