I’m new to Ruby and slowly learning the ropes, I have been spending hours in the last few days trying to catch up and I’m really not getting this (I’m sure it is obvious!)
I can easily output “My Name” using .upcase but it keeps throwing up issues and wont allow me to move on to the next challenge - any tips there would be helpful.
code
my_name = “Jordan”
Please write your code below this line…
…and above this line.
puts “My name is #{upper(my_name)}”
Instruction
"Write a method called upper that will output Jordan all in upper case.
Note that we’re passing the variable my_name as argument when we’re calling the method, that should give you a hint on what you need to include. Please don’t change any of our code, you can only write new code or reuse previous code.
Your output should read as below :
My name is JORDAN
Your method should be a template - this can then be used for any variables that are passed through it.
Now we have to decide what our method will be doing so we can name it accordingly and set up the operational code. Your method will be named, upper and will take one parameter, a String type. You already know the Ruby built-in, upcase so all you need to do is write an expression in your method and return it.
Note that Ruby automatically treats the last line of a method as an implicit return so that keyword is not needed.
I different ways to do this including having .upcase. the process states I cannot use other lines…I’m out of options, I really don’t know what to try next other than ignore the requirements and write my own code.
I figured it out but I’m stuck on this following bit.
The code I have done so far:
name = “Jordan”
def upper(string)
string.upcase
end
def lower(string)
string.downcase
end
def random_name
[“Ollie”, “Ana”].sample
end
def random_case(string)
[upper(string), lower(string)].sample
end
Please write your code between this line…
… and this line
puts “My name is #{random_both()}”
In the section where I have to write my code, I need the code to generate the names Ana and Ollie at random, and also their first letter needs be upper/lowercase at random.
I have tried several ways and I keep getting it wrong.
Hello! As well as the prompt by ~mtf, in your array, you have the random_case(string) function-and it takes the argument string. Yet where is that argument coming from?
Because as @codeneutrino pointed out, string is undefined. We defined it with the call to random_name(), which returns a random string. We can then pass that return value to the random_case() method which returns the random case.
Your approach was loading an array with two already random values and picking one or the other value. The logic is flawed.