Last active
April 3, 2018 09:58
-
-
Save ufocoder/204bb2eb5b889258ba5f15f88c615907 to your computer and use it in GitHub Desktop.
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 (..) | |
import Html exposing (..) | |
import Html.Events exposing (..) | |
import Random | |
main = | |
Html.program | |
{ init = init | |
, view = view | |
, update = update | |
, subscriptions = subscriptions | |
} | |
type alias Model = Int | |
type Msg | |
= GenerateNumber | |
| SetNumber Int | |
init : ( Model, Cmd Msg ) | |
init = | |
( 1, Cmd.none ) | |
update : Msg -> Model -> ( Model, Cmd Msg ) | |
update msg model = | |
case msg of | |
GenerateNumber -> | |
( model, Random.generate SetNumber (Random.int 1 6) ) | |
SetNumber number -> | |
( number, Cmd.none ) | |
subscriptions : Model -> Sub Msg | |
subscriptions model = | |
Sub.none | |
view : Model -> Html Msg | |
view model = | |
div [] | |
[ h1 [] [ text (toString model) ] | |
, button [ onClick GenerateNumber ] [ text "Generate" ] | |
] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment