Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS

How do i connect two random elements from two arrays and print them together?( Swift)

I'm working on my own little project and having trouble accessing a random element from one array within a struct and another random element from another and printing those two together.

3 Answers

Hi Sandro!

I will give you some pointers on how you could get this done!

  • First you will have to figure out how to create a random number which can only go so low or so high.
  • You will then have to use this random number as the index of the array.
  • Finally then you will have to concatenate these two values together.

Good luck!

Thanks for responding, But the first two pointers are not the problem , the problem is combining the two random values and printing them in one string.

Try using some code like the following.

variable_name = arrayName[randomNumber1] + arrayName[randomNumber2]

Make sure that you have created all of these variables or substitute in the names of the variables that you have created.

Thanks for the help!