Skip to content
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
17 changes: 17 additions & 0 deletions add_up.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Alannah Smith
# 3/31/21

def add_up(i)
puts "Enter a positive number"
mo = gets.chomp.to_i
if( mo % 2 == 0 )
x =0.upto(mo).inject{|memo, i| memo +=i; memo}
puts x
else
puts "Oops, we needed a positive number"
end
end

add_up(2)
add_up(3)
add_up(4)
15 changes: 15 additions & 0 deletions full_name.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Alannah Smith
# 3/31/21

name = []

puts "Enter First Name: "
name.push gets.chomp

puts "Enter Middle Name: "
name.push gets.chomp

puts "Enter Last Name: "
name.push gets.chomp

puts "Hello #{name.join(' ')}!"
19 changes: 19 additions & 0 deletions leap_year.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Alannah Smith
# 3/31/21

def leap_years(start_year, end_year)
(start_year..end_year).select { |year|
year % 400 == 0 || (year % 100 != 0 && year % 4 == 0) }

end


puts "Enter a start year: "

start_year = gets.chomp.to_i

puts "Enter a end year: "

end_year = gets.chomp.to_i

puts "The leap years between #{start_year} and #{end_year} are: #{leap_years(start_year, end_year).join(' ')}"
15 changes: 15 additions & 0 deletions sorted_words.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Alannah Smith
# 3/31/21

words = []

loop do
puts "Enter a word or press the enter key to leave"
word = gets.chomp
words.sort
if word == ""
break
end
words.push(word)
end
puts "Your Words Are: #{words.join(",")}"
Comment on lines +14 to +15
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You forgot to sort the array before print it out)