Skip to content

Commit

Permalink
cleaned up formatting for final submission
Browse files Browse the repository at this point in the history
  • Loading branch information
dcardona23 committed Aug 27, 2024
1 parent 83e43ed commit 06a380b
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 19 deletions.
10 changes: 1 addition & 9 deletions lib/deck.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
# require_relative './card.rb' (may need to add to make method to add cards work)

class Deck
attr_reader :card, :cards
attr_writer :cards

def initialize(cards)
@cards = cards
end
# require 'pry'; binding.pry

def count
@cards.length
end
Expand All @@ -17,9 +14,4 @@ def cards_in_category(category)
category == card.category
end
end

def add_card(new_card)
@cards << new_card
end

end
3 changes: 1 addition & 2 deletions lib/flashcard_runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ def start
puts "Question: #{@round.current_card.question}"
user_input = gets.chomp
new_turn = @round.take_turn(user_input)
# require 'pry'; binding.pry
puts new_turn.feedback
end

puts "****** Game over! ******"
puts "You had #{@round.number_correct} correct guesses out of #{@cards.length} for a total score of #{@round.percent_correct}%."
puts "You had #{@round.number_correct} correct guesses out of #{@cards.length} for a total score of #{@round.percent_correct}."
@round.return_percent_correct_by_category
end

Expand Down
10 changes: 4 additions & 6 deletions lib/round.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
require_relative './card.rb'

class Round
attr_reader :deck, :turns, :current_card, :user_guesses, :number_correct, :card_number, :number_correct_by_category, :percent_correct, :percent_correct_by_category, :turn_number, :new_turn_category
attr_writer :turns
attr_reader :deck, :turns, :current_card, :user_guesses, :number_correct, :card_number, :number_correct_by_category, :percent_correct, :percent_correct_by_category, :turn_number, :new_turn_category, :new_card

def initialize(deck)
@deck = deck
Expand All @@ -16,7 +15,6 @@ def initialize(deck)
@current_card = current_card
@percent_correct = 0.0
@percent_correct_by_category = 0
@new_turn_category = []
@correct_by_category = Hash.new(0)

end
Expand All @@ -34,7 +32,7 @@ def take_turn(guess)
@number_correct += 1
@correct_by_category[current_card.category] += 1 #@correct_by_category hash tracks the number of correct guesses by category
end
# require 'pry'; binding.pry

@card_number += 1
@turn_number += 1
new_turn
Expand All @@ -52,7 +50,7 @@ def percent_correct_by_category(category)
total_in_category = @turns.count { |turn| turn.card.category == category} #use block code here - |turn| is the argument, and the block iterates over each turn in the @turns array
#identifies whether the category of the card associated with each turn in the @turns array matches the cateegory of the argument passed into the method

return 0.0 if total_in_category == 0 #don't care about empty categories
return 0 if total_in_category == 0
((number_correct_by_category(category).to_f / total_in_category) * 100).round(2)

end
Expand All @@ -63,7 +61,7 @@ def unique_categories

def return_percent_correct_by_category
unique_categories.each do |category|
puts "#{category}: #{percent_correct_by_category(category)}%"
puts "#{category}: #{percent_correct_by_category(category)}% correct"
end
end

Expand Down
3 changes: 1 addition & 2 deletions lib/turn.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
class Turn
attr_reader :card, :guess
attr_writer :card, :guess

def initialize(guess, card)
@guess = guess
Expand All @@ -13,7 +12,7 @@ def correct?
end

def feedback
if card.answer.downcase == guess.downcase
if correct?
"Correct!"
else
"Incorrect."
Expand Down

0 comments on commit 06a380b

Please sign in to comment.