Skip to content

new commit #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
--color
--format documentation
--order default
--require spec_helper
62 changes: 31 additions & 31 deletions app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,50 +5,50 @@
erb(:homepage)
end

get("/dice/2/6") do
@rolls = []

2.times do
die = rand(1..6)

@rolls.push(die)
end
get("/dice/:dice/:sides") do
@dice = params[:dice].to_i
@sides = params[:sides].to_i
@rolls = Array.new(@dice) { rand(1..@sides) }
@heading_text = "#{@dice}d#{@sides}" # Change here to match expected format
erb(:randomdice)
end

get("/dice/2/6") do
@rolls = Array.new(2) { rand(1..6) }
@heading_text = "2d6" # Change here to match expected format
erb(:two_six)
end

get("/dice/2/10") do
@rolls = []

2.times do
die = rand(1..10)

@rolls.push(die)
end

@rolls = Array.new(2) { rand(1..10) }
@heading_text = "2d10" # Change here to match expected format
erb(:two_ten)
end

get("/dice/1/20") do
@rolls = []

1.times do
die = rand(1..20)

@rolls.push(die)
end

@rolls = Array.new(1) { rand(1..20) }
@heading_text = "1d20" # Change here to match expected format
erb(:one_twenty)
end

get("/dice/5/4") do
@rolls = []

5.times do
die = rand(1..4)
@rolls = Array.new(5) { rand(1..4) }
@heading_text = "5d4" # Change here to match expected format
erb(:five_four)
end

@rolls.push(die)
end
get("/dynamic/:number_of_dice/:how_many_sides") do
@num_dice = params.fetch("number_of_dice").to_i
@sides = params.fetch("how_many_sides").to_i
@rolls = Array.new(@num_dice) { rand(1..@sides) }
@heading_text = "#{@num_dice}d#{@sides}" # Change here to match expected format
erb(:flexible)
end

erb(:five_four)
get("/dice/[RANDOM_DICE]/[RANDOM_SIDES]") do
random_dice = rand(2..100)
random_sides = rand(2..100)
@rolls = Array.new(random_dice) { rand(1..random_sides) }
@heading_text = "#{random_dice}d#{random_sides}" # Change here to match expected format
erb(:randomdice)
end
32 changes: 32 additions & 0 deletions views/flexible.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<h1><%= @num_dice %>d<%=num_of_@sides%></h1>

<ul>
<% @rolls.each do |a_roll| %>
<li>
<%= a_roll%>
</li>
<%end%>
</ul>

<h1>50d6</h1>

<ul>
<% @rolls.each do |a_roll| %>
<li>
<%= a_roll %>
</li>
<% end %>
</ul>

<%= params.fetch("number_of_dice") %>

<h1>50d6</h1>

<ul>
<% @rolls.each do |a_roll| %>
<li>
<%= a_roll %>
</li>
<% end %>
</ul>

3 changes: 2 additions & 1 deletion views/homepage.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<h1>Dice Roll</h1>
<h1>Dice Roll Options</h1>

<ul>
<li><a href="/dice/2/6">Roll two 6-sided dice</a></li>
<li><a href="/dice/2/10">Roll two 10-sided dice</a></li>
<li><a href="/dice/1/20">Roll one 20-sided die</a></li>
<li><a href="/dice/5/4">Roll five 4-sided dice</a></li>
<li><a href="/dice/[RANDOM_DICE]/[RANDOM_SIDES]">Roll random dice</a></li>
</ul>
47 changes: 25 additions & 22 deletions views/layout.erb
Original file line number Diff line number Diff line change
@@ -1,28 +1,31 @@
<!DOCTYPE html>
<html>
<head>
<title>Sinatra Dice Roll</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<head>
<title>Sinatra Dice Roll</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
.navbar {
display: flex;
justify-content: space-around;
}
</style>
</head>

<style>
.navbar {
display: flex;
justify-content: space-around;
}
</style>
</head>
<body>
<div class="navbar">
<div><a href="/">Home</a></div>
<div><a href="/dice/2/6">2d6</a></div>
<div><a href="/dice/2/10">2d10</a></div>
<div><a href="/dice/1/20">1d20</a></div>
<div><a href="/dice/5/4">5d4</a></div>
<div><a href="/dice/[RANDOM_DICE]/[RANDOM_SIDES]">Random Dice</a></div>
</div>

<body>
<div class="navbar">
<div><a href="/">Home</a></div>
<div><a href="/dice/2/6">2d6</a></div>
<div><a href="/dice/2/10">2d10</a></div>
<div><a href="/dice/1/20">1d20</a></div>
<div><a href="/dice/5/4">5d4</a></div>
</div>
<h1 style="text-align: center; font-family: Helvetica, Arial; font-size: 22px; color: #888; margin: 20px;">
<%= @heading_text %>
</h1>

<%= yield %>

</body>
<%= yield %>
</body>
</html>
6 changes: 6 additions & 0 deletions views/randomdice.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<h2>Rolling Results:</h2>
<ul>
<% @rolls.each do |roll| %>
<li><%= roll %></li>
<% end %>
</ul>