Skip to content

Commit

Permalink
Get randomness example working
Browse files Browse the repository at this point in the history
  • Loading branch information
process-bot committed Apr 25, 2016
1 parent e438f46 commit cbdae1f
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions examples/4.elm
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
import Html exposing (..)
import Html.App as Html
import Html.Events exposing (..)
import Random



main =
Html.program
{ init = init
, view = view
, update = update
, subscriptions = subscriptions
}



-- MODEL


type alias Model =
{ dieFace : Int
}


init : (Model, Cmd Msg)
init =
(Model 1, Cmd.none)



-- UPDATE


type Msg
= Roll
| NewFace Int


update : Msg -> Model -> (Model, Cmd Msg)
update msg model =
case msg of
Roll ->
(model, Random.generate NewFace (Random.int 1 6))

NewFace newFace ->
(Model newFace, Cmd.none)



-- SUBSCRIPTIONS


subscriptions : Model -> Sub Msg
subscriptions model =
Sub.none



-- VIEW


view : Model -> Html Msg
view model =
div []
[ h1 [] [ text (toString model.dieFace) ]
, button [ onClick Roll ] [ text "Roll" ]
]

0 comments on commit cbdae1f

Please sign in to comment.