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
19 changes: 19 additions & 0 deletions add_up.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
def add_up(i)
if (i.class !=Integer) || (i <1)

Choose a reason for hiding this comment

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

nice validation!

puts "Please enter a positive integer"
else
sum = 0
loop do
sum += i
i -= 1
if i == 0
break
end
end
puts sum
end
end

Choose a reason for hiding this comment

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

indentation is a bit off

add_up(6)
add_up(-8)
add_up(5)
15 changes: 15 additions & 0 deletions full_name.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
def Ask(question)
puts question
string = gets.chomp + " "

Choose a reason for hiding this comment

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

rather than adding a space to the end of the word here I would probably wait till the end of the method and just use join(' ')

return string
end




full_name.push(Ask("Enter your first name, please"))
full_name.push(Ask("Enter your middle name, please"))
full_name.push(Ask("Enter your last name please"))

puts "Hello " + full_name[0] + full_name[1] + full_name[2] + "!"

Choose a reason for hiding this comment

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

sorta same as the above, I would use full_name.join(' ')


22 changes: 22 additions & 0 deletions leap_year.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
def is_leap(year)
if year %400 == 0
return true
elsif year % 100 == 0
return false
elsif year % 4 == 0
return true
else
return false

end
end

year = begin_year

Choose a reason for hiding this comment

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

not sure what this line is doing. begin_year is not defined at this point

while year <= end_year do

if is_leap(year)
puts year
end
year +=1
end

15 changes: 15 additions & 0 deletions sorted_words.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
words = []

while true do

Choose a reason for hiding this comment

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

I try to avoid using while true loops, because then if any of the branches within that loop do not break correctly you end up with an infinite loop, which is no good

puts "Please enter a word. Type Enter to quit"
word = gets.chomp
if word == ''
break
elsif word.index(/[^A-Za-z]/)

Choose a reason for hiding this comment

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

good validation!

puts "Not a word. Please try again"
else
words.push(word)
end
end
words = words.sort
words.each {|word| puts word}