Skip to content

state_capitals (Jeff Heller) #188

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 26 additions & 0 deletions capitals.rb
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,29 @@
name: "Wyoming",
capital: "Cheyenne"
}]

# add score to each state score[0] = correct, score[1] = incorrect
game_states = states.each{|state| state[:score] = [0, 0]}

puts "Welcome to the state capital game. Press enter to get started!"
gets

def start_game (game_states)
game_states.shuffle!
game_states.each{|state|
puts "What is the capital of " + state[:name] + "?"
input = gets.chomp
if input == state[:capital] then state[:score][0] += 1
puts "Nice job! You're score for this state is " + state[:score][0].to_s + " correct and " + state[:score][1].to_s + " incorrect."
else state[:score][1] +=1
puts "Wrong! You're score for this state is " + state[:score][0].to_s + " correct and " + state[:score][1].to_s + " incorrect."
end
}
puts "Round over. Would you like to play again? (y/n)"
new_game = gets.chomp
if new_game == "y" then start_game(game_states)
else puts "Thanks for playing!"
end
end

start_game(game_states)