NEW
Font size
WorksheetsApple Swift Coding I - Lesson 7 - 10
Total questions: 23
Worksheet time: 12mins
Which line is declaring a variable?
name = "Johnny"
let name = "Johnny"
let "Johnny" = name
var name = "Johnny"
What best describes an algorithm?
A step by step series of operations
Only calculations that use advance mathematics
The computer equivalent of rhythm
The same thing as an identifier
What is API?
A safety check to make sure programs work
A rating given to experienced programmers
A tool for writing programs
The set of functions you can use with a particular programming area
What is wrong with this code?
let score = 15
score +=5
Nothing
The scores are wrong
Score is a constant and cannot be changed
+=should be =+
What is the value of score after this code:
Var score = 2
score = score + 1
2
3
1
This code will not work
Which line is declaring a constant?
name = "Johnny"
let name = "Johnny"
let "Johnny" = name
var name = "Johnny"
What type is foo in the code below:
var foo: SolarPhenomenon
Interstellar
Not possible to tell
SolarPhenomenon
Variable
What is the value of score after this code:
var score =0
score +=1
score+=1
0
1
2
This code will not work
How do you pass a value out of a function?
Assigning a value to one of the arguments
The value of the last line of the function is passed out automatically
Using a return statement
You can't pass a value out of a function.
You're writing a program for scoring a word game . Each letter has a value between 1 and 10 and players earn points for making words. What would be stored as a constant in the program?
The scores per letter
The list of words the player has made
The player's score
Nothing
What type is foo in the code below:
let foo: Double = 42
Double
foo
42
Int
What does API stand for?
Actually Pretty Important
Application Programming Interface
Available Program Interpretation
Automatic Program Input
What is the value of message after this code?
var message = " "
message + = "Hello"
message ++ "World"
"Hello"
"World"
Hello World
"HelloWorld"
Which line declares a function that returns a string?
func makeSentence ( ): String {
func: String makeSentence ( ) {
func makeSentence ( ) -> String {
String func makeSentence ( ) {
What is one way Swift determines the type of a value in your code?
Type intrusion
Type allegiance
Type writing
Type inference
Which line shows correct type annotation in Swift?
String: let name
let String: name
let name: String
let String
How does Swift decide what type distance should be? let distance: Double = 4
Type annotation
Type inference
Type interference
Typewriting
What type is foo in the code below? let foo = "Hello"
Let
String
"Hello"
Hello
What is the name for the information passed into a function?
Argument
Disagreements
Terms
Values
If you're reading code and aren't sure of the type of a variable or constant, what's the quickest way to find out?
Assign different value types to the variables and check for errors
Option-click the constant's or variable's name in x-code
Remember that variables are always strings and constants are always numbers
Rewrite the section of code using different encapsulations
Which line correctly declares a function that takes a String argument called word, and an Int argument called number?
func makeSentence (String, Int) (Word, number) {
func makeSentence (word: String, number: Int) {
func makeSentence (word: String number : Int) {
func makeSentence (String: word: Int: number)
How can you change the type of a Constant or Variable after it's declared?
Assign a new value of a different type
Create the Value as a Var Variable
Don't give the value a type
You can't change the value of a value
Which line declares a function that takes a String argument called word?
func makeSentence (String:word) {
func makeSentence (word:String) {
func makeSentence (word, String) {
func makeSentence (String, word) {
