Created
January 21, 2025 17:20
-
-
Save kissu/b1c32bf6447075ac06b573cf205d8f2f to your computer and use it in GitHub Desktop.
Programming Basics
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def coach_answer(your_message) | |
if your_message.upcase == "I AM GOING TO WORK RIGHT NOW!" | |
return "" | |
elsif your_message.end_with?("?") | |
return "Silly question, get dressed" | |
else | |
return "I don't care" | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require_relative "./coach_answer.rb" | |
puts "Hello, I am your coach, what did you want to tell me?" | |
condition = true | |
while condition != "" | |
print "> " | |
message = gets.chomp | |
condition = coach_answer(message) | |
puts condition | |
end | |
puts "Great, see ya!" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# random number 1 to 100 | |
# ask the user a number | |
# lower than my random secret number | |
# or higher | |
# you WIN! 🎖️ | |
# return the amount of tries done by the user | |
guess_number = rand(100) | |
puts "Guess a number 🤡" | |
input = gets.chomp.to_i | |
counter = 0 | |
puts input | |
while input != guess_number | |
if input > guess_number | |
puts "My guess is lower" | |
input = gets.chomp.to_i | |
elsif input < guess_number | |
puts "My guess is higher" | |
input = gets.chomp.to_i | |
end | |
counter += 1 | |
end | |
puts "You won in #{counter} times" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'date' | |
# method return numbers of days until next Xmas | |
def countdown | |
today = Date.today + 1 | |
xmas = Date.new(2025, 12, 26) | |
return (xmas - today).to_i | |
end | |
puts countdown.class == Integer | |
puts countdown == 338 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment