defmodule PentoWeb.WrongLive do use PentoWeb, :live_view def mount(_params, _session, socket) do {:ok, assign(socket, score: 0, message: "Make a guess:", time: time())} end def render(assigns) do ~H"""

Your score: <%= @score %>

<%= @message %> It's <%= @time %>


<%= for n <- 1..10 do %> <.link class="bg-blue-500 hover:bg-blue-700 text-white font-bold py-2 px-4 border border-blue-700 rounded m-1" phx-click="guess" phx-value-number={n} > <%= n %> <% end %>

""" end defp time() do DateTime.utc_now |> to_string end def handle_event("guess", %{"number" => guess}, socket) do message = "Your guess: #{guess}. Wrong. Guess again." score = socket.assigns.score - 1 {:noreply, assign(socket, message: message, score: score, time: time())} end end