Skip to content

Instantly share code, notes, and snippets.

@fractalatcarf
Created July 11, 2018 16:30
Show Gist options
  • Save fractalatcarf/1b1fc5cf770b90ff9d4e22be6898570a to your computer and use it in GitHub Desktop.
Save fractalatcarf/1b1fc5cf770b90ff9d4e22be6898570a to your computer and use it in GitHub Desktop.
yesterday's live code
# # on demande rien
# # affectation ddj dans une variable 'today'
# # affectation date du prochain noel dans 'xmas'
# # affiche xmas - today
# require 'date'
# today = Date.today
# xmas = Date.new(today.year, 12, 25)
# if today > xmas
# xmas = Date.new(today.year + 1, 12, 25)
# end
# days = (xmas - today).to_i
# puts "#{days} until next Xmas"
# count = 0
# the computer chooses a random (1 => 100) number (random)
# ask user to choose a number (number)
# while number != random
# count += 1
# if number > random, say "too much !"
# if number < random, say "not enough !"
# ask user a new number (number)
# end
# say "congrats ! in xxx attempts"
count = 0
random = 1 + rand(100)
puts random
number = nil
while number != random
puts "Pick a number between 1 and 100"
number = gets.chomp.to_i
count +=1
puts "too much !" if number > random
puts "not enough !" if number < random
# puts "Pick a number between 1 and 100"
# number = gets.chomp.to_i
end
puts "congrats ! (#{count} attempts)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment