visited = []
puts "Enter all the states you've been to! Type 'done' when you're finished:"
state = gets.chomp.upcase
if state.downcase != 'done'
visited.push(state)
end
keep_going = true
while keep_going
state = gets.chomp.upcase
if state.downcase != 'done'
visited.push(state)
end
end
keep_going = true
while keep_going
state = gets.chomp.upcase
if state.downcase != 'done'
visited.push(state)
else
break
end
end
puts "You have visited the following states:"
puts visited.join(', ')
visited.each do |state|
puts state
end
# Write a program that asks the user for all U.S. states they have visited
# (followed by a return)
# Typing "done" should terminate the program.
# Print all states to the screen.
visited = []
puts "Enter all the states you've been to! Type 'done' when you're finished:"
keep_going = true
while keep_going
state = gets.chomp.upcase
if state.downcase != 'done'
visited.push(state)
else
break
end
end
puts "You have visited the following states:"
puts visited.join(', ')
# Write a program that prints the lyrics
# to 99 Bottles of Beer on the Wall
# example output:
# 99 bottles of beer on the wall
# 99 bottles of beer
# Take one down pass it around
#
# 98 bottles of beer on the wall
# 98 bottles of beer on the wall
# 98 bottles of beer
# Take one down, pass it around
# N number of bottles
number_of_bottles = 99
until number_of_bottles == 0
# Do something
end
# print 2 lines using number of bottles
# print refrain (doesn’t change)
# print a line using number - 1
# print 2 lines using number of bottles
puts "#{number_of_bottles} bottles of beer on the wall"
puts "#{number_of_bottles} bottles of beer"
# print refrain (doesn’t change)
puts "Take one down, pass it around\n\n"
#print a line using N -1
puts "#{number_of_bottles - 1} bottles of beer on the wall"
number_of_bottles = 99
until number_of_bottles == 0
# print 2 lines using N
puts "#{number_of_bottles} bottles of beer on the wall"
puts "#{number_of_bottles} bottles of beer"
# print refrain (doesn’t change)
puts "Take one down, pass it around\n\n"
#print a line using N -1
puts "#{number_of_bottles - 1} bottles of beer on the wall"
number_of_bottles -= 1
end
if number_of_bottles > 1
# print 2 lines using N
puts "#{number_of_bottles} bottles of beer on the wall"
puts "#{number_of_bottles} bottles of beer"
# print refrain (doesn’t change)
puts "Take one down, pass it around\n\n"
# print a line using N -1
puts "#{number_of_bottles - 1} bottles of beer on the wall"
else
# print 2 lines using N
puts "1 bottle of beer on the wall"
puts "1 bottle of beer"
# print refrain (doesn’t change)
puts "Take it down, pass it around"
# print a line using N -1
puts "No more bottles of beer on the wall!"
end
# Ask the user 5 yes or no questions
# Compare their answers to a list of correct answers
# Print the number of correct answers
questions = [ 'Are narwhals real?',
'Is today Halloween?',
'Do dogs say meow?',
'Does 2+2 = 4?',
'Is Jaime awesome?']
correct_answers = ['Y', 'N', 'N', 'Y', 'Y']
puts "Please answer Y or N to the following questions!"
questions.each do |question|
puts "Q: #{question}"
user_answer = gets.chomp.upcase
end
index = 0
score = 0
questions.each do |question|
puts "Q: #{question}"
user_answer = gets.chomp.upcase
if user_answer == correct_answers[index]
# Do Something
end
end
questions.each do |question|
puts "Q: #{question}"
user_answer = gets.chomp.upcase
if user_answer == correct_answers[index]
score += 1
end
index += 1
end
puts "You got #{score}/5 correct answers!"
if user_answer == 'Y' || user_answer == 'N'
if user_answer == correct_answers[index]
score += 1
end
index += 1
else
puts "Try again: Y or N?"
end
questions.each do |question|
puts "Q: #{question}"
user_answer = gets.chomp.upcase
if user_answer == 'Y' || user_answer == 'N'
if user_answer == correct_answers[index]
score += 1
end
index += 1
else
puts "Try again: Y or N?"
redo
end
end
questions = [ 'Are narwhals real?',
'Is today Halloween?',
'Do dogs say meow?',
'Does 2+2 = 4?',
'Is Jaime awesome?']
correct_answers = ['Y', 'N', 'N', 'Y', 'Y']
index = 0
score = 0
puts "Please answer Y or N to the following questions!"
questions.each do |question|
puts "Q: #{question}"
user_answer = gets.chomp.upcase
if user_answer == 'Y' || user_answer == 'N'
if user_answer == correct_answers[index]
score += 1
end
index += 1
else
puts "Try again: Y or N?"
redo
end
end
puts "You got #{score}/5 correct answers!"
questions_answers = {'Are narwhals real?'=> 'Y',
'Is today Halloween?'=> 'N',
'Do dogs say meow?' => 'N',
'Does 2+2 = 4?' => 'Y',
'Is Jaime awesome?' => 'Y'}
score = 0
puts "Please answer Y or N to the following questions!"
questions_answers.each do |question, correct_answer|
puts "Q: #{question}"
user_answer = gets.chomp.upcase
end
if user_answer == 'Y' || user_answer == 'N'
if user_answer == correct_answer
score += 1
end
else
puts "Try again: Y or N?"
redo
end
puts "You got #{score}/#{questions_answers.count} correct answers!"
questions_answers = {'Are narwhals real?' => 'Y',
'Is today Halloween?' => 'N',
'Do dogs say meow?' => 'N',
'Does 2+2 = 4?' => 'Y',
'Is Jaime awesome?' => 'Y'}
score = 0
puts "Please answer Y or N to the following questions!"
questions_answers.each do |question, correct_answer|
puts "Q: #{question}"
user_answer = gets.chomp.upcase
if user_answer == 'Y' || user_answer == 'N'
if user_answer == correct_answer
score += 1
end
else
puts "Try again: Y or N?"
redo
end
end
puts "You got #{score}/#{questions_answers.count} correct answers!"
@questions_answers = {'Are narwhals real?' => 'Y',
'Is today Halloween?' => 'N',
'Do dogs say meow?' => 'N',
'Does 2+2 = 4?' => 'Y',
'Is Jaime awesome?' => 'Y'}
@score = 0
def prompt
puts "Please answer Y or N to the following questions!"
end
def put_score
# Do something
end
def put_score(s,q_a)
puts "You got #{s}/#{q_a.count} correct answers!"
end
def ask_questions
@questions_answers.each do |question, correct_answer|
puts "Q: #{question}"
user_answer = gets.chomp.upcase
if user_answer == 'Y' || user_answer == 'N'
if user_answer == correct_answer
@score += 1
end
else
puts "Try again: Y or N?"
redo
end
end
end
def main
prompt
ask_questions
put_score(@score)
end
main
@questions_answers = {'Are narwhals real?' => 'Y',
'Is today Halloween?' => 'N',
'Do dogs say meow?' => 'N',
'Does 2+2 = 4?' => 'Y',
'Is Jaime awesome?' => 'Y'}
@score = 0
def prompt
puts "Please answer Y or N to the following questions!"
end
def ask_questions
@questions_answers.each do |question, correct_answer|
puts "Q: #{question}"
user_answer = gets.chomp.upcase
if user_answer == 'Y' || user_answer == 'N'
if user_answer == correct_answer
@score += 1
end
else
puts "Try again: Y or N?"
redo
end
end
end
def put_score(s,q_a)
puts "You got #{s}/#{q_a.count} correct answers!"
end
def main
prompt
ask_questions
put_score(@score,@questions_answers)
end
main