FizzBuzz method specification
Accepts a specific positive integer value as an argument
Please make the return value change according to the numerical value (conditions are as follows)
If the number is a multiple of 3, the return value is "Fizz"
If the number is a multiple of 5, the return value is "Buzz"
If the number is a multiple of 3 and a multiple of 5, the return value is "FizzBuzz"
If none of the above is met, the number itself is the return value
How to use FizzBuzz methods
Write the following line before executing the FizzBuzz method.
num_max = 100
Create a loop for integer values between 1 and num_max and execute the FizzBuzz method
Please display the return value of the FizzBuzz method in the terminal
If none of the above is met, return the value itself
The current code is a method that displays fizz and returns nil.Created code
num_max = 100
def fizzbuzz (n)
if n% 15 == 0
elsif n% 3 == 0
elsif n% 5 == 0
(1..num_max) .each do | n |
Please provide more detailed information here.
Answer # 1
The fizzbuzz method itself should only return the result and not print the result.
Please change to. (The other parts are the same)
And the caller prints the result, so
puts fizzbuzz (n)
- ruby - i want to solve the n + 1 problem when using rails where method in loop processing
- ruby - problem that status200 ok is returned in jbuilder but not displayed
- ruby - about the problem of duplicate devise error messages (allow_blank: ture doesn't work!)
- ruby on rails - i want to solve the problem that "we're sorry, but something went wrong" is displayed in the productio
- ruby on rails - i want to solve the problem that scss is not applied after modifying the scss file with rails
- it ’s a simple problem in ruby
- php: tell us about the application of the fizzbuzz problem!
- ruby - please tell me the knowledge etc to reproduce the problem solving with the solved question
- ruby on rails - about the problem that rails test does not become green in rails tutorial
- i can't use selenium with ruby it seems that there is a problem with the version of chrome, but i do not know where chrome drive
- ruby - i want to solve the problem that posts are not saved
- ruby on rails - the problem that the change button cannot be pressed
- paiza fizz buzz problem ruby
- ruby algorithm problem? what time is it before?
- ruby - i got a message like this, is there any problem?
- php - coincheck api authentication doesn't work
- php - i would like to introduce the coincheck api so that i can make payments with bitcoin on my ec site
- [php] i want to get account information using coincheck api
- python - you may need to restart the kernel to use updated packages error
- python 3x - typeerror: 'method' object is not subscriptable
- the emulator process for avd pixel_2_api_29 was killed occurred when the android studio emulator was started, so i would like to
- xcode - pod install [!] no `podfile 'found in the project directory
- vuejs - [vuetify] unable to locate target [data-app] i want to unit test to avoid warning
- android studio - unresolved reference comes out in kotlin