-
Notifications
You must be signed in to change notification settings - Fork 0
/
find_the_right_price.rb
36 lines (29 loc) · 1.12 KB
/
find_the_right_price.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# computer_choice = rand(1..5)
# # [1,2,3,4,5].sample
# puts " what is your user choice?"
# user_choice = gets.chomp.to_i
# while computer_choice != user_choice
# puts "your price is not right"
# puts " what is your user choice?"
# user_choice = gets.chomp.to_i
# puts "computer chose #{computer_choice} - you chose: #{user_choice}"
# end
# puts "computer chose #{computer_choice} - you chose: #{user_choice}"
# REFACTORING
# computer_choice = rand(1..5)
# # [1,2,3,4,5].sample
# user_choice = nil #variable initialization to be able to compare the two variable in the while statement
# while computer_choice != user_choice
# puts "what is your user choice?"
# user_choice = gets.chomp.to_i
# puts "computer chose #{computer_choice} - you chose: #{user_choice}"
# end
# refactoring with until
computer_choice = rand(1..5)
# [1,2,3,4,5].sample
user_choice = nil #variable initialization to be able to compare the two variable in the while statement
until computer_choice == user_choice
puts "what is your user choice?"
user_choice = gets.chomp.to_i
puts "computer chose #{computer_choice} - you chose: #{user_choice}"
end