Creating your own version


#1


I have completed a night at the movies activity and since I am interested in stocks I created a watch list from that model. If anyone is a ruby 2.4 expert please give me advice. (The one on code academy is 1.8 I believe).

stocks = { 


}

puts "What would you like to do?"
puts "-- Type 'add' to add a stock.”
puts "--Type'update' to update a stocks amount of shares.”
puts "-- Type 'display' to display all stocks.”
puts "-- Type 'delete' to delete a stock from your watchlist.”
end

choice = gets.chomp.downcase
case choice
when 'add'
  puts “What stock would you like to add to your watchlist?”
  ticker = gets.chomp
  if stocks[ticker.to_sym].nil?
    puts “How many shares did you buy?” (Type a number 1 and above.)”
    shares = gets.chomp
    stocks[ticker.to_sym] = shares.to_i
    puts “You added #{shares[shares.to_i]} of #{ticker} to your portfolio/watchlist”
  else
    puts "That stock has previously been added!."
  end
when 'update'
  puts "What stock do you want to update?"
  ticker = gets.chomp
  if stocks[ticker.to_sym].nil?
    puts "Movie not found!"
  else
    puts "What's the new amount of shares?"
    shares = gets.chomp
    stocks[ticker.to_sym] = shares.to_i
    puts "#{ticker} has been updated with new amount of #{shares}.”
  end
when 'display'
  stocks.each do |ticker, shares|
    puts “#{ticker}: #{shares}”
  end
when 'delete'
  puts "What stock do you want to delete from your watch list?”
  ticker = gets.chomp
  if stocks[title.to_sym].nil?
    puts "Movie not found!"
  else
    stocks.delete(ticker.to_sym)
    puts "#{ticker} has been removed."
  end
else
  puts "Sorry, that stock doesn’t exist.”
end

Thank you.


#2

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.