Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

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!