Skip to content

Instantly share code, notes, and snippets.

@tedi
Created May 20, 2014 21:37
Show Gist options
  • Save tedi/8653bd986240d7b8a58b to your computer and use it in GitHub Desktop.
Save tedi/8653bd986240d7b8a58b to your computer and use it in GitHub Desktop.
# Teddit Contionals - Solution Code.
# Let's add a new Teddit feature. Upvotes!
def get_input
gets.strip
end
def calculate_upvotes(story, category)
upvotes = 1
if story.downcase.include? 'cat'
upvotes *= 5
elsif story.downcase.include? 'bacon'
upvotes *= 8
end
if category.downcase == "food"
upvotes *= 3
end
upvotes
end
puts "Welcome to Teddit! a text based news aggregator. Get today's news tomorrow!"
puts "Please enter a News story:"
story = get_input
puts "Please give it a category:"
category = get_input
upvotes = calculate_upvotes(story, category)
puts "New story added! #{story}, Category: #{category.capitalize}, Current Upvotes: #{upvotes}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment