Skip to content

panda & tiger level assignment complete #9

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 3 commits into
base: master
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
12 changes: 11 additions & 1 deletion theweb.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
enable :sessions

get '/' do
erb :dashboard
about_me = Array["a human being", "female", "a programmer", "fun"]
random_about_me_choice = rand(about_me.length)
@about_me_choise = about_me[random_about_me_choice]
erb :about
end

post '/number' do
Expand All @@ -16,3 +19,10 @@
@the_number = rand(number_as_string)
erb :number
end

get '/about' do
about_me = Array["a human being", "female", "a programmer", "fun"]
random_about_me_choice = rand(about_me.length)
@about_me_choise = about_me[random_about_me_choice]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here's a fun ruby way to do this:

First, no need to use "Array", you could do

about_me = ["a human being", "female", "a programmer", "fun"]

Then, to randomly pick something out, you can reduce that to:

@about_me_choice = ["a human being", "female", "a programmer", "fun"].sample

#sample will shuffle the array and pick the first item. fun!

erb :about
end
3 changes: 3 additions & 0 deletions views/about.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<h1>ABOUT ME</h1>
<h2>I am <%= @about_me_choise %></h2>

3 changes: 3 additions & 0 deletions views/dashboard.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,6 @@
<input type="text" id="number" name="number"/>
<input type="submit" class="btn btn-large btn-primary" value="View Number"/>
</form>
<form method="GET" action="/about">
<label for="about">about dharini</label>
</form>