diff --git a/add_up.rb b/add_up.rb new file mode 100644 index 0000000..2e12346 --- /dev/null +++ b/add_up.rb @@ -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) diff --git a/full_name.rb b/full_name.rb new file mode 100644 index 0000000..50cef3e --- /dev/null +++ b/full_name.rb @@ -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(' ')}!" diff --git a/leap_year.rb b/leap_year.rb new file mode 100644 index 0000000..995f22e --- /dev/null +++ b/leap_year.rb @@ -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(' ')}" diff --git a/sorted_words.rb b/sorted_words.rb new file mode 100644 index 0000000..f82ef6b --- /dev/null +++ b/sorted_words.rb @@ -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(",")}"