Last active
January 1, 2020 01:11
-
-
Save lucamug/5fb5ad9379a3c2dea4677428db656187 to your computer and use it in GitHub Desktop.
Code for https://ellie-app.com/7DjWTc7DgRGa1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Main exposing (main) | |
import Browser | |
import Html exposing (..) | |
import Html.Attributes exposing (..) | |
import Html.Events exposing (..) | |
init = { a = "1", b = "2" } | |
type Msg = ChangeA String | ChangeB String | |
update msg model = | |
case msg of | |
ChangeA value -> { model | a = value } | |
ChangeB value -> { model | b = value } | |
view model = | |
div [] | |
[ input [ onInput ChangeA, value model.a, type_ "number"] [] | |
, input [ onInput ChangeB, value model.b, type_ "number"] [] | |
, p [] | |
[ text <| String.join " " | |
[ model.a | |
, "+" | |
, model.b | |
, "=" | |
, case Maybe.map2 (+) (String.toFloat model.a) (String.toFloat model.b) of | |
Just value -> String.fromFloat value | |
Nothing -> "undefined" | |
] | |
] | |
] | |
main = Browser.sandbox { init = init, view = view, update = update } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment