You are viewing a single comment's thread from:

RE: Coding challenge the first.

in #coding7 years ago (edited)

I took the liberty of converting the for loop to an iterator as ruby has no for loop we speak of :)

And here is the code:

require 'time'

USERS = %w(Marvin Ray John Rick Mayte Hannah Jessica Laura)

def current_daytime
  return :night if Time.now < Time.parse("05:00 am")
  return :morning if Time.now < Time.parse("10:00 am")
  return :day if Time.now < Time.parse("15:00 am")
  return :afternoon if Time.now < Time.parse("20:00 am")
  :evening
end

def pretty_daytime
  current_daytime.to_s.capitalize
end

def greet(name)
    puts "Good #{pretty_daytime} to you, #{name}!"
end

def hello_world
  puts "Hey, what is your name?"
  name = gets.strip
  puts "Hello World, it is currently #{Time.now.to_s} for me..."
  puts "With me are #{USERS.join(', ')} and #{name}!"
  USERS.push name
  USERS.each do |user|
    greet user
  end
  puts "What a nice #{pretty_daytime} it is with all my friends!"
end

hello_world

runnable at https://repl.it/LPGy

Coin Marketplace

STEEM 0.20
TRX 0.15
JST 0.030
BTC 65628.71
ETH 2669.64
USDT 1.00
SBD 2.86