Skip to content

Instantly share code, notes, and snippets.

@jjthrash
Created July 9, 2014 17:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jjthrash/91189cc1fea21aa62721 to your computer and use it in GitHub Desktop.
Save jjthrash/91189cc1fea21aa62721 to your computer and use it in GitHub Desktop.
(page "index.html")
(def multipliers [1 2 4 7 10 15])
(def default-counts [0 0 0 0 0 0])
(defc counts default-counts)
(defc= score (reduce + (map * counts multipliers)))
(defn increment-counter [idx c]
(assoc c idx (inc (get c idx))))
(html
(head
(link :rel "stylesheet" :type "text/css" :href "css/main.css"))
(body
(text "total score: ~{score}")
(ul
(map (fn [idx]
(li
(button :on-click (fn [x] (swap! counts (partial increment-counter idx)))
(let [label (+ idx 1)]
(text "~{label}")))
(let [count (cell= (get counts idx))]
(text "(~{count})"))))
(range (count @counts))))
(p (button :on-click (fn [x] (swap! counts (constantly default-counts)))
(text "reset")))))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment