This course is ideal for beginners eager to learn the fundamental concepts that underpin the Swift programming language. Explore the basic programming concepts and data structures that are core to any language, while discovering the unique aspects that make Swift as versatile as it is today.
In this course, you will receive hands-on practice utilizing these concepts. More specifically, you will learn how to use constants and variables with different data types and explore how to sort and store information in collection types such as arrays, tuples and dictionaries. Finally, you will discover how to make your code reusable and more expressive by using functions and closures.
Enroll on Coursera
Q1. In the exercise, you were prompted to make a note of the code output. What was the last printed statement of the output?
Q2. What did you use to store the fixed temperature value of a specific day?
Q3. What did you use to store the current temperature during a certain period of the current day?
Q4. How many times can you change the value of the temperature variable?
Q1. What is the output of the following code?
let levelScore = 10
var gameScore = 0
gameScore += levelScore
print("The game's score is (gameScore).")
Q2. What is the difference between 20 and 20.0?
Q3. What is the output of the following code?
let levelScore = 5
var gameScore = 10.4
gameScore += Double(levelScore)
print("The game's score is (gameScore).")
Q4. What is the result of 20 / 5?
Q1. If you were to store the name of a planet, which would be the best to store this in?
Q2. Which of the following would be ideal to store in a variable?
Q3. The keyword ‘let’ is used to declare what in Swift?
Q4. Which of the following would be inferred as a double by Swift?
Q5. Are 3 and 3.0 the same in Swift?
Q1. In the exercise, you were prompted to make a note of the code output. What was the last printed statement of the output?
Q2. What did you use to determine the current time from its components?
Q3. What did you use to print the current day and time to the console?
Q1. Which operator is used to concatenate two strings together?
Q2. Which of the following would be used to put the variable name in a string?
Q3. Which of the following would be used to return the number of characters in a string called name?
Q4. A character is a one-letter string.
Q5. What line of code should you insert in line 4 to concatenate the strings in lines 1, 2 and 3 to ensure the printed message reads correctly?
let veggies = "carrots"
let fruits = "strawberries"
let snacks = "crisps"
print("I have (picnicBasket) in my picnic basket.")
Q1.What do you call the type of value that’s been assigned to the freeApp constant?
let freeApp = true
if freeApp == true {
print("You are using the free version of the app. Buy the full version of the app to get access to all of its features.")
}
Q2. What is the output of the following code?
let temperatureDegree = "Celsius"
if temperatureDegree == "Fahrenheit" {
print("The weather app works with Fahrenheit degrees.")
} else {
print("The weather app works with Celsius degrees.")
}
Q3. What is the output of the following code?
let temperatureDegree = "Fahrenheit"
if temperatureDegree == "Celsius" || temperatureDegree == "Fahrenheit" {
print("The weather app is configured properly.")
} else {
print("The weather app isn't configured properly.")
}
Q4. What type of condition did you use to check if you are using the free version of the app?
Q5. What type of condition did you use to check what kind of degrees the weather app uses?
Q6. What logical operator did you use to evaluate the default temperature degree settings?
Q1. Suppose you are using a conditional statement to check if a user’s age is less than another user’s age. Which operator would you use?
Q2. Which of the following operators means “OR”?
Q3. What is the value of the count variable after the code below is executed?
var count = 10
if count < 5 {
count += 1
} else if count > 10 {
count -= 1
}
Q4. What is the output of the following code?
let degrees = "Fahrenheit"
switch degrees {
case "Fahrenheit": print("The weather app is configured for the US.")
case "Celsius": print("The weather app is configured for Europe.")
default: break
}
Q5. Which is more efficient for checking many values?
Q1. Which of the following is optimized to loop a set number of times?
Q2. Which of the following is best for looping an unknown number of times?
Q3. Which of the following will always loop at least once?
Q4. The for in loop requires the in keyword.
Q5. Are for in loops optimized for iterating over a string?
Q1. In the exercise, you were prompted to make a note of the code output.
What was the third level of the output?
Q2. Which statement do you use to make sure only the free levels are playable?
Q3. Which statement do you use to skip any bonus levels of the game?
Q4. Which type of loop is best to implement the game logic?
Q1. In the exercise, you were prompted to review the code output of your program.
What was the last printed statement of the output?
Q2. When do you use the forced unwrapping operator?
Q3. When do you use optional binding?
Q1. An optional for an Int type can only hold integers.
Q2. Which of the following operators are used to force unwrap an optional?
Q3. he if let statement is used in optional binding.
Q4. Which of the following operators are used to define an implicitly unwrapped optional?
Q5. What is the output of the following code?
let text = "10"
if let number = Int(text) {
print("The number is (number).")
} else {
print("Invalid number!")
}
Q6. What is the output of the following code?
let text = "text"
if let number = Int(text) {
print("The number is (number).")
} else {
print("Invalid number!")
}
Q1. If you were to store the balance of a bank account, which would be the best to store this in?
Q2. Which of the following would be ideal to store in a constant?
Q4. The keyword var is used to declare what in Swift?
Q5. What operator do you use to check if two strings are the same?
Q6. Swift’s Strings are Unicode compliant.
Q6. Which operator means greater than?
Q7. Switch statements do require a default keyword.
Q8. A “for loop” can use ranges to define the number of loops.
Q9. Which of the following operators are used to define an optional?
Q10. What is the output of the following code?
let text = "text"
if let number = Int(text) {
print("The number is (number).")
} else {
print("Invalid number!")
}
Q1. In the exercise, you were prompted to make a note of the code output.
What was the last printed statement of the output?
Q2. What is the index of the first element in an array?
Q3. How do you create an empty array to store integer values?
Q1. In the exercise, you were prompted to review the code output.
What was the first printed statement of the output?
Q2. Tuples, like arrays, follow a particular order.
Q3. Tuples are defined by placing a list of items within brackets, for example, ().
Q4. What is the index of the first element in a tuple?
Q5. What type of elements can a tuple have?
Q1. Which of the following is an array literal?
Q2. Which method would add a 5 to the end of an array called numbers? Select all that apply.
Q3. Which method would you use to change the value held at index 1 of an array called numbers?
Q4. Assuming an array called numbers isn’t empty, which method would you use to change the last index of an array?
Q5. Individual elements of a tuple can be named when it is created.
Q6. How do you declare an empty array of integers?
Q7. What is the output of the following code?
let emptyArray: [Int] = []
if emptyArray.count == 0 {
print("The array is empty!")
} else {
print("The array isn’t empty!")
}
Q8. What is the output of the following code?
let emptyArray: [Int] = [0]
if emptyArray.count == 0 {
print("The array is empty!")
} else {
print("The array isn’t empty!")
}
Q9. How do you access the elements of the following tuple?
let dailyTemperature = (“Monday”, 70)
Q10. How do you access the elements of the following tuple?
let dailyTemperature = (day: “Monday”, temperature: 70)
Select all that apply:
Q1. In the exercise, you were prompted to make a note of the code output.
What was the last printed statement of the output?
Q2. When accessing a key’s associated value in a dictionary, force unwrapping terminates code execution if the value isn’t present.
Q3. When do you use optional binding with dictionaries?
Q1. In the exercise, you were prompted to run the program and review the output to the console.
Which of the following options best resembles the last printed statement in the console?
Q2. What type of loop did you use with arrays?
Q3. What type of loop did you use with dictionaries?
Q1. Which of the following is a dictionary literal?
Q2. Which method would you use to add the key-value pair to a dictionary called travelMiles?
Q3. Which method would you use to modify a value held by a key in a dictionary? Select all that apply.
Q4. The following command [“A”:1, “B”:2, “C”:3, “D”:4].count will return what value?
Q5. You can extract all the keys from a dictionary using the following syntax:
Q6. How do you declare an empty dictionary of string keys and integer values?
Q7. What is the output of the following code?
let emptyDictionary: [String: Int] = [:]
if emptyDictionary.count == 0 {
print("The dictionary is empty!")
} else {
print("The dictionary isn’t empty!")
}
Q8. What is the output of the following code?
let emptyDictionary: [String: Int] = ["": 0]
if emptyDictionary.count == 0 {
print("The dictionary is empty!")
} else {
print("The dictionary isn’t empty!")
}
Q1. Which of the following is optimized for looping over an array?
Q2. Which of the following is optimized for looping over a dictionary?
Q3. Individual elements of a tuple have index numbers.
Q4. Which method would you use to add a value 5 to the end of an array called numbers? Select all that apply.
Q5. Individual elements of a tuple can be accessed using a name/label if they were added when it was created.
Q6. You can extract all the values from a dictionary using the following syntax:
Q7.Which of the following will remove keys and values from a dictionary? Select all that apply.
Q8. The following code block terminates code execution:
var weeklyTemperatures = ["Monday": 70, "Tuesday": 75, "Wednesday": 80, "Thursday": 85, "Friday": 90]
weeklyTemperatures["Sunday"]! += 10
Q9. What is the output of the following code?
let emptyArray: [Int] = [0]
if emptyArray.count == 0 {
print("The array is empty!")
} else {
print("The array isn’t empty!")
}
Q10. How do you access the elements of the following tuple?
let dailyTemperature = (“Monday”, 70)
Q1. Which keyword defines a function?
Q2. In func unlockTreasureChest(inventory: Int) -> Int, the inventory is a:
Q3. You can omit the return keyword in a function that returns an implicit expression.
Q1. In func incrementInventory(inventory: Int, by amount: Int) -> Int, how many parameters are there?
Q2. In func incrementInventory(inventory: Int, by amount: Int) -> Int, the by keyword is a(n):
Q3. You can set a default value for an in-out parameter.
Q1. Which of the following is the correct layout when defining a function in Swift?
Q2. Functions must always return a value when called.
Q3. You can use () and Void interchangeably.
Q4. Which way is valid for calling the following function?
func hiThere(firstName: String, lastName: String) {
}
Q5. Which way is valid for calling the following function?
func hiThere(_ firstName: String, _ lastName: String) {
}
Q6. In func incrementInventory(inventory: Int, by amount: Int), what is the return type?
Q7. What do you call the block of code that comes right after a function’s signature declaration?
Q8. You cannot use an argument label on an in-out parameter.
Q1. You can create a closure in one of three forms.
Q2. You can set a default parameter value in a closure.
Q3. Closure expressions have a name.
Q1. A closure expression written in a function’s final parameter is called a trailing closure.
Q2. When would you want to use the Void return type in a closure?
Q3. You can have only one closure parameter inside a function signature.
Q1. Functions are special cases of closures with a name and don’t capture any values.
Q2. Which of the following is the correct layout when defining a function in Swift?
Q3. Which of the following is the correct layout when defining a closure in Swift?
Q4. Which of the following is the way in which you can call this function?
func hiThere(firstNamefn:String, secondNamesn:String)
Q5. Closures are self-contained blocks of functionality that can be stored in a variable.
Q6. A function can be identified by a combination of its name, parameter types and return types.
Q7. You can pass a closure as a function parameter.
Q8. You cannot use an argument label on an in-out parameter.
Q9. Function parameters are immutable by default.
Q10. Only one in-out parameter is allowed for each function.
Q1. In the exercise, you were prompted to make a note of the code output.
What was the first printed statement of the output?
Q2. What type of loop did you use to create the bank account
Q3. Why do you need a default case inside a switch statement?
Q4. Which case is the default case inside a switch statement?
Q5. Why did you use a break statement inside the default case of the switch statement?
Q1. Which of the following examples demonstrate chaining multiple if statements together?
Q2. What did you use when you defined a function?
Q3. What did you use when you called a function?
Q4. Where did you use the parameters of a function?
Q5. Where did you use the arguments of a function?
Q6. What is the relationship between the parameters and arguments of a function?
Q7. When can you assign the result of a function to a constant or variable?
Q1. In the exercise, you were prompted to make a note of the code output.
What was the sixth printed statement of the output?
Q2. What type of loop did you use to perform operations for your bank account?
Q3. What type of conditional statement can you use to rewrite a switch statement?
Q1. If you were to store a date of birth, which would be the best to store this in?
Q2. Which of the following would be inferred as a Bool by Swift?
Q3. An Optional for a Bool type can only hold integers.
Q4. You can use an “if” statement for optional binding.
Q5. One use case of the “>” operator is to compare the lexicographical order between two strings.
Q6. Which method would you use to add a value “last item” to the end of an Array called strings? Select all that apply.
Q7. Which of the following is a greater than or equal to operator?
Q8. Functions must always store a return value in a variable when called.
Q9. Tuples, like dictionaries, do not follow any particular order.
Q10. Which of the following is a dictionary literal?
I hope this Programming Fundamentals in Swift Coursera Quiz Answers would be useful for you to learn something new from the Course. If it helped you, don’t forget to bookmark our site for more Quiz Answers.
This course is intended for audiences of all experiences who are interested in learning about new skills in a business context; there are no prerequisite courses.
Keep Learning!
Former Vice President Phelekezela Mphoko has died aged 84, presidency spokesman George Charamba has confirmed.…
The Zimbabwe School Examinations Council (ZIMSEC) opened its online portal for Grade 7 results…
2024 ZIMSEC Grade 7 Results Now Out The Zimbabwe School Examinations Council (ZIMSEC) has officially…
We’re bringing free WiFi to different parts of Zimbabwe to help you access eduzim.co.zw for…
Sadza is a simple, hearty dish that forms the backbone of many Zimbabwean meals. It's…
Caesar Salad A classic Caesar salad is a simple yet flavorful dish with crisp romaine…