I’m a beginner | Sololearn: Learn to code for FREE!
¡Nuevo curso! ¡Todo programador debería aprender IA Generativa!
Prueba una lección gratuita
+ 1

I’m a beginner

The first question is to write a method in Ruby that takes in a number as a parameter and prints “This number is even” if the number is even or “This number is odd” If it’s odd.

4th Sep 2019, 12:41 AM
Renee Johnson
Renee Johnson - avatar
3 Respuestas
+ 2
you can do this with if statements, for example, you make an input field then you can say if the number is 1,3,5,7, etc, the output will be odd and same for even
4th Sep 2019, 1:21 AM
luna
luna - avatar
+ 2
Make an initial attempt and share your code. If you get stuck people can help.
4th Sep 2019, 3:46 AM
Sonic
Sonic - avatar
0
thank you! here is what I have initially: def even?(x) puts "The number is even" end even?(8) def odd?(x) puts "The number is odd" end odd?(7)
5th Sep 2019, 12:11 AM
Renee Johnson
Renee Johnson - avatar