-
-
Save DamirSvrtan/1915441 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### 1. Create user class by implementing | |
### a. properties | |
### i. user_id | |
### ii. username | |
### iii. password | |
### iv. email | |
### b. methods | |
### i. greet (learn user to say "Hi! My name is <name>, nice to meet you." | |
### | |
### 2. Create recursive function that returns result for x^y | |
def pot(x,y) | |
y==1 ? x : x*pot(x,y-1) | |
end | |
### 3. Write a program that prints the numbers from 1 to 100. But for multiples of three | |
### print “Fizz” instead of the number and for the multiples of five print “Buzz”. For | |
### numbers which are multiples of both three and five print “FizzBuzz”. | |
(1..100).each do |x| | |
if x%3==0 && x%5==0 | |
print "Fizzbuzz\n" | |
elsif x%3==0 | |
print "Fizz\n" | |
elsif x%5==0 | |
print "Buzz\n" | |
else print "#{x}\n" | |
end | |
end | |
### da, mogao sam upotrjebit puts, znam :)) | |
### 4. Find the largest integer value in array (all values in array are integers) | |
a=[5,4,3,1] | |
a.max #=>5 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
nice job for the second, but check my shit out for the third.
I present you DIVISABLE_BY?
Check this shit out:
So now you can use
x.divisable_by? 3,5
in your code. 🍺