Exercise 2: Greet Randomly

Greet in various languages.

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"].


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.

Create a free account to access the full course.

By signing up, you agree to Educative's Terms of Service and Privacy Policy