Exercise 2: Greet Randomly
Learn to create a Ruby method that randomly selects a greeting phrase from a list and appends it to a provided name. This exercise helps you understand method definition, working with arrays, and how to add variety to outputs in Ruby programming.
We'll cover the following...
Problem statement
Now, change the greet method so that instead of always using "Hello ", it picks a random string from the array ["Hello", "Hi", "Ohai", "ZOMG"].
Example
If the name “Ada” is passed as an argument, then it should print out either "Hello Ada!", "Hi Ada!", "Ohai Ada!", or "ZOMG Ada!" every time you run the program.
Note: You just need to provide the definition of the method, and it will be automatically evaluated on the given input value.
Try it yourself
To complete this task, you’re expected to either consult the documentation or look at the hint below.