diff --git a/add_up.rb b/add_up.rb new file mode 100644 index 0000000..6c7cee7 --- /dev/null +++ b/add_up.rb @@ -0,0 +1,13 @@ +def add_up(i) + sum = 0 + for a in 1..i do + sum = sum + a + end + + puts sum + +end + +add_up(11) +add_up(23) +add_up(54) \ No newline at end of file diff --git a/full_name.rb b/full_name.rb new file mode 100644 index 0000000..e746622 --- /dev/null +++ b/full_name.rb @@ -0,0 +1,17 @@ +name = [] + +puts "Please enter your first name?" +first_name = gets.chomp +name << first_name + +puts "Please enter your middle name?" +middle_name = gets.chomp +name << middle_name + +puts "Please enter your last name?" +last_name = gets.chomp +name << last_name + +print "Hello," +name.each {|item| print " " + item} +print "!" \ No newline at end of file diff --git a/leap_year.rb b/leap_year.rb new file mode 100644 index 0000000..ac56fc8 --- /dev/null +++ b/leap_year.rb @@ -0,0 +1,16 @@ +def leap_year +puts "starting year?" +startingYear= gets.chomp.to_i + +puts "ending year?" +endingYear = gets.chomp.to_i + +for i in startingYear..endingYear do + if i % 4 == 0 and !(i % 100 == 0 ) or i % 400 == 0 + puts i + +end +i +=1 +end +end +leap_year \ No newline at end of file diff --git a/sorted_words.rb b/sorted_words.rb new file mode 100644 index 0000000..3614ce5 --- /dev/null +++ b/sorted_words.rb @@ -0,0 +1,19 @@ + +def sorted_words + words = [] + print "Hi! I am a word sorting program \nPlease enter the words to be sorted " + + loop do + input = gets.chomp + words << input + break if input.empty? + print "Would you like to enter another word? If not, press enter to exit the word sorting program: " + end + + puts "Sorted list!\n* #{(words.length - 1)}*" + sleep 1 + + puts "Here is your sorted list #{words.sort.reject!(&:empty?).join(', ')}" +end + +sorted_words