Skip to content

Instantly share code, notes, and snippets.

@canweriotnow
Last active December 24, 2015 04:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save canweriotnow/6748010 to your computer and use it in GitHub Desktop.
Save canweriotnow/6748010 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
puts "How much IP do you have?"
ip_have = STDIN.gets.chomp #don't really need the STDIN
puts "Which champion do you want to buy?"
champion_want = STDIN.gets.chomp
lucian = #{lucian_value} #The #{} construct is for inside double-quoted strings, otherwise # just indicates a comment.
lucian_value = 6300
puts "#{champion_want} is #{champion_want} IP, so this means you need #{lucian_value} - #{ip_have}" #The math has to happen inside the #{} block... also, ip_have is read as a String, need to convert to an integer.
#If the user enters "lucian" I want it to be 6300. so I can subtract the 6300 from the amount the user has (ip_have)
#need to test for an entry of "lucian", but that's step 2. For what you've got here, see the next file.
#!/usr/bin/env ruby
puts "How much IP do you have?"
ip_have = gets.chomp.to_i #to_i converts to an Integer.
puts "Which champion?"
champion_want = gets.chomp
lucian_value = 6300
lucian = lucian_value
puts "#{champion_want} is #{champion_want} IP, so this means you need #{lucian_value - ip_have}" #do the math in the block.
#!/usr/bin/env ruby
def champion_value(name)
case name
when "lucian"
6300
when "mudkipz"
5
when "baby lettuce"
1002
else
return nil
end
end
puts "How much IP do you have?"
ip_have = gets.chomp.to_i
puts "Which champion?"
champion_want = gets.chomp
value = champion_value(champion_want) #look up the value
if value #make sure we found the champion
if value > ip_have
puts "#{champion_want} is #{value} IP, so this means you need #{value - ip_have}" #do the math in the block.
elsif value <= ip_have
puts "You have enough IP, after buying #{champion_want}, you will have #{ip_have - value} remaining."
end
else
puts "We don't have a value for #{champion_want} at the moment, sorry."
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment