Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Description: Work with an array of color names in Swift based on a set of requirements. Purpose: This challenge provides experience in working with arrays

Description: Work with an array of color names in Swift based on a set of requirements.

Purpose: This challenge provides experience in working with arrays in Swift.

Requirements:

Write and test the code that meets the following requirements. Submit the code in the text box provided with the assignment.

It is recommended you create an Xcode project or playground to write and test the code. Do not submit the Xcode project or playground. Submit the block of code in the assignment text box.

Declare a variable called colors that is an array that holds the string names of a collection of colors and is initialized with the following color names: red, orange, yellow, and pink.

Remove the last item from the colors array using an array method. (This will remove pink.)

Add green to the end of the colors array.

Create a constant called numColors and set it equal to the number of colors in the array. (Use the computed property available on the array that provides the number of items in the array.)

Print the number of colors in the array using the format: number of colors =

Print the string colors:

Iterate through the colors array using a for-in loop and print out each array element.

Declare a constant called moreColors that is an array that is initialized with the following color names: blue, purple

Declare a variable called allColors and assign it the combined elements of colors and moreColors. The colors elements are to come first and the moreColorselements are to come second in allColors.

Print the string all colors:

Iterate through the allColors array using a for-in loop and print out each array element.

The output of your program should look like the following:

number of colors = 4 colors: red orange yellow green all colors: red orange yellow green blue purple

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database Upgrade Migration And Transformation Tips And Techniques

Authors: Edward Whalen ,Jim Czuprynski

1st Edition

0071846050, 978-0071846059

More Books

Students also viewed these Databases questions