dimanche 24 janvier 2016

Basic Ruby: Returning a value in a string

In my teamtreehouse ruby course I am on this challenge and for some reason my solution is not clearing the challenge. What am I doing wrong

Question: In the previous challenge, we wrote a method that returned the remainder of two arguments when divided. That's cool, but it would be nicer if the method returned the remainder in a nice full sentence. Use string interpolation to return the remainder inside the sentence “The remainder of a divided by b is c.” where a is your “a” variable, b is your “b” variable, and c is the value of a % b.

My Answer

def mod(a, b)
  c = a % b
  puts "The remainder of #{a} divided by #{b} is #{c}"
end

Note We can only use two arguments

Aucun commentaire:

Enregistrer un commentaire