Skip to content

Instantly share code, notes, and snippets.

@Haumer
Created January 12, 2021 19:07
Show Gist options
  • Save Haumer/913c6d76b8c060fe6792b9ebc586a66e to your computer and use it in GitHub Desktop.
Save Haumer/913c6d76b8c060fe6792b9ebc586a66e to your computer and use it in GitHub Desktop.
puts "----------------------------------------"
puts "-----Welcome to The Price is Right!-----"
puts "----------------------------------------"
puts "Guess the price of this wonderful imaginary product"
# computer picks a random number (generate random number)
computer_number = rand(1..100)
# ask the user to enter a number => gets.chomp
user_number = gets.chomp.to_i
# we need a loop while/until
# compare user number to computer number
# count guesses
number_of_guesses = 1
until computer_number == user_number
if computer_number > user_number
puts "Try higher!"
else
puts "Try lower"
end
puts "Guess again!"
user_number = gets.chomp.to_i
number_of_guesses += 1
# number_of_guesses = number_of_guesses + 1
end
puts "You guess corretly."
puts "You took #{number_of_guesses} guesses!"
puts "The price was #{computer_number}!"
# get date object
require 'date'
# create a method => does this method take a parameter
def xmas(today_date)
# todays date
# today = Date.today
# get christmas 2021
christmas = Date.new(today_date.year, 12, 25)
# calculate difference an convert to integer
calculation = (christmas - today_date).to_i
# to check if its after christmas but in the same year
if calculation.negative?
365 + calculation
else
calculation
end
# calculation.negative? ? 365 + calculation : calculation
end
next_year_date = Date.new(1450, 12, 27)
puts xmas(next_year_date)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment