In Ruby, I'm trying to solve a quiz as like a FizzBuzz Challenge. My question is "How I can print the integer number |n|
adding a comma and space(", ")
at the end of they?"
To separate the Nama
and Team
strings I'm using $stdout.print "Team, " && $stdout.print "Nama, "
. But for the integers my syntax is $stdout.print n
:
Code right now:
puts "Enter the maximum amount of numbers"
print ">"
upper_limit = gets.chomp.to_i
(1..upper_limit).each do |n|
if n % 35 == 0
$stdout.print "NamaTeam"
elsif n % 7 == 0
$stdout.print "Team, "
elsif n % 5 == 0
$stdout.print "Nama, "
else
$stdout.print n
end
end
I already tried to use .join(' ')
and .split(' ')
methods but they don't work with integer
numbers D:
Best Regards for the community!