Ruby: I made a FizzBuzz program!

At first

** Day 13 of Calendar Planning 2020 ** It's been about 3 months since I started studying programming, so I will leave a note of what I learned in the article as an output. I would be happy if I could help anyone entering the world of programming. Please let me know if there are any words that are wrong, wrong, or misunderstood ^^ I'm sorry if it's hard to read the words for a long time. I will do my best to get used to it little by little.

I made a FizzBuzz program

I will try to create it again for personal review!


--If you pass a number divisible by 3 as an argument, [Fizz] is returned. --If you pass a number divisible by 5 as an argument, [Buzz] is returned. --If you pass a number divisible by both 3 and 5 as an argument, it returns [FizzBuzz]. --In other cases, return the argument as a character string

This time, use the gets method to enable input to the keyboard (excluding non-numeric input)


def fizz_buzz(number)
  if number % 15 == 0
  elsif number % 3 == 0
  elsif number % 5 == 0

puts "Please enter a number"

input = gets.to_i

puts "Result is! ??"
puts fizz_buzz(number)

It should look like this! (There may be other answers!)

fizz_buzz (number) Set the method name and arguments. Use the if statement to clear the condition. The method is completed by describing the return value for the condition as a process! !!

Don't forget to perform type conversion that meets the conditions properly.

First, write the condition that "both 3 and 5 are divisible" in the contents of the if statement! The reason is the order of processing! Since it is processed in order from the top If you write the condition that "3 or 5 can be broken" first, the condition that "both can be broken" will not be caught at all ^^;

You can complete it if you pay attention only here!


When I didn't understand it yet, I was worried that I couldn't complete it because I made a mistake in this order ... ^^;

Recommended Posts

Ruby: I made a FizzBuzz program!
[Ruby] I made a simple Ping client
I made a risky die with Ruby
I made a primality test program in Java
I made a Ruby extension library in C
I made a portfolio with Ruby On Rails
I made a chat app.
[Ruby] I made a crawler with anemone and nokogiri.
I made a shopify app @java
I made a GUI with Swing
[Beginner] I made a program to sell cakes in Java
I made a simple recommendation function.
I made a matching app (Android app)
I made a package.xml generation tool.
[Android] I made a pedometer app.
I made a Ruby container image and moved the Lambda function
I tried a calendar problem in Ruby
[Ruby] A program that determines prime numbers
I made various Fibonacci sequence functions (Ruby)
I made a plugin for IntelliJ IDEA
I made a rock-paper-scissors app with kotlin
I made a calculator app on Android
I made a new Java deployment tool
I made a rock-paper-scissors app with android
I made a bulletin board using Docker 1
[Ruby] FizzBuzz problem
I made StringUtils.isBlank
I started Ruby
[Ruby] FizzBuzz problem
Ruby payroll program
I tried FizzBuzz.
FizzBuzz program (2 types)
I made a Diff tool for Java files
04. I made a front end with SpringBoot + Thymeleaf
I made a mosaic art with Pokemon images
I made a gender selection column with enum
[Ruby] A program that uses search and each_with_index
[Ruby] I want to do a method jump!
I made blackjack with Ruby (I tried using minitest)
I wrote a primality test program in Java
I made a rock-paper-scissors game in Java (CLI)
I made a viewer app that displays a PDF
I made a Docker container to run Maven
[Rails] I made a draft function using enum
I made a LINE bot with Rails + heroku
I wrote a prime factorization program in Java
I made a Docker image of SDAPS for Japanese
[Ruby] I want to make a program that displays today's day of the week!
I made a simple calculation problem game in Java
I made a check tool for the release module
Ruby score calculation program
I made a method to ask for Premium Friday
[Ruby] A program / concept that combines each_with_index and search
Created a menu program
I made a drawing chat "8bit paint chat" on WebAssembly
How to launch another command in a Ruby program
I made a Restful server and client in Spring.
I made a library that works like a Safari tab !!
I made a library for displaying tutorials on Android.
Ruby Numeric Reference Program
I made a Wrapper that calls KNP from Java