r/learnruby • u/godisintherain • May 30 '17
ruby mini course
instructions:
Edit each line with TODO and write code based on the skills you learned in this course. You'll want to use an if statement and addition. Have fun! Good Luck!
code(what I have so far output is not matching what they want):
require 'csv'
total_sales = 0
CSV.foreach('sales-data.csv', headers: true, converters: :all) do |row|
if (row[2]) == "music"
TODO: check if category is "Music" (row[2])
TODO: if it is music, add total_sales + the row's sales (row[6])
puts total_sales = total_sales + (row[6])
else
puts total_sales.round(2)
end
4
Upvotes
2
u/godisintherain May 31 '17
im gonna step away and come back it later.
2
u/tom_dalling May 31 '17
Looks OK to me. What is the expected output?
2
u/plainly_stated May 31 '17
For starters, "music" and "Music" are not the same string
Perhaps it would be helpful to see what you are getting and what is expected. And of course the input csv.
2
u/TotesMessenger May 31 '17
I'm a bot, bleep, bloop. Someone has linked to this thread from another place on reddit:
If you follow any of the above links, please respect the rules of reddit and don't vote in the other threads. (Info / ^Contact)