12
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

ElixirAdvent Calendar 2023

Day 4

リハビリアプリを作ろう(その2)

Last updated at Posted at 2023-12-04

こちらの続きです

1-25の数字押していくゲームを作りたいです
このコラムの範囲

  • 1-25の数字をランダムに表示

1-25の数字のシャッフルされたリストを生成

lib/num_web/live/user_live/index.ex
defmodule NumWeb.UserLive.Index do
  use NumWeb, :live_view

  @impl true
  def mount(_params, _session, socket) do
    num =
    1..25
    |> Enum.shuffle()
    socket = assign(socket, num: num)
    {:ok, socket}
  end

end

5づつ改行する

lib/num_web/live/user_live/index.html.heex
<%= for {s, i} <- Enum.with_index(@num, 1) do %>
  <div class="float-left w-28 h-28 m-2 bg-blue-200 text-center ">
    <p class="pt-7 text-5xl text-blue-700 "><%= s %></p>
  </div>
  <%= if rem(i, 5) == 0 do  %>
    <br>
  <% end %>
<% end %>

現時点結果

image.png

今回はここまで

12
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
12
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?