wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

Apple Swift Coding I - Lesson 7 - 10

Total questions: 23

Worksheet time: 12mins

Name
Class
Date
1.

Which line is declaring a variable?

a)

name = "Johnny"

b)

let name = "Johnny"

c)

let "Johnny" = name

d)

var name = "Johnny"

2.

What best describes an algorithm?

a)

A step by step series of operations

b)

Only calculations that use advance mathematics

c)

The computer equivalent of rhythm

d)

The same thing as an identifier

3.

What is API?

a)

A safety check to make sure programs work

b)

A rating given to experienced programmers

c)

A tool for writing programs

d)

The set of functions you can use with a particular programming area

4.

What is wrong with this code?

let score = 15

score +=5

a)

Nothing

b)

The scores are wrong

c)

Score is a constant and cannot be changed

d)

+=should be =+

5.

What is the value of score after this code:

Var score = 2

score = score + 1

a)

2

b)

3

c)

1

d)

This code will not work

6.

Which line is declaring a constant?

a)

name = "Johnny"

b)

let name = "Johnny"

c)

let "Johnny" = name

d)

var name = "Johnny"

7.

What type is foo in the code below:

var foo: SolarPhenomenon

a)

Interstellar

b)

Not possible to tell

c)

SolarPhenomenon

d)

Variable

8.

What is the value of score after this code:


var score =0

score +=1

score+=1

a)

0

b)

1

c)

2

d)

This code will not work

9.

How do you pass a value out of a function?

a)

Assigning a value to one of the arguments

b)

The value of the last line of the function is passed out automatically

c)

Using a return statement

d)

You can't pass a value out of a function.

10.

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?

a)

The scores per letter

b)

The list of words the player has made

c)

The player's score

d)

Nothing

11.

What type is foo in the code below:

let foo: Double = 42

a)

Double

b)

foo

c)

42

d)

Int

12.

What does API stand for?

a)

Actually Pretty Important

b)

Application Programming Interface

c)

Available Program Interpretation

d)

Automatic Program Input

13.

What is the value of message after this code?

var message = " "

message + = "Hello"

message ++ "World"

a)

"Hello"

b)

"World"

c)

Hello World

d)

"HelloWorld"

14.

Which line declares a function that returns a string?

a)

func makeSentence ( ): String {

b)

func: String makeSentence ( ) {

c)

func makeSentence ( ) -> String {

d)

String func makeSentence ( ) {

15.

What is one way Swift determines the type of a value in your code?

a)

Type intrusion

b)

Type allegiance

c)

Type writing

d)

Type inference

16.

Which line shows correct type annotation in Swift?

a)

String: let name

b)

let String: name

c)

let name: String

d)

let String

17.

How does Swift decide what type distance should be? let distance: Double = 4

a)

Type annotation

b)

Type inference

c)

Type interference

d)

Typewriting

18.

What type is foo in the code below? let foo = "Hello"

a)

Let

b)

String

c)

"Hello"

d)

Hello

19.

What is the name for the information passed into a function?

a)

Argument

b)

Disagreements

c)

Terms

d)

Values

20.

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?

a)

Assign different value types to the variables and check for errors

b)

Option-click the constant's or variable's name in x-code

c)

Remember that variables are always strings and constants are always numbers

d)

Rewrite the section of code using different encapsulations

21.

Which line correctly declares a function that takes a String argument called word, and an Int argument called number?

a)

func makeSentence (String, Int) (Word, number) {

b)

func makeSentence (word: String, number: Int) {

c)

func makeSentence (word: String number : Int) {

d)

func makeSentence (String: word: Int: number)

22.

How can you change the type of a Constant or Variable after it's declared?

a)

Assign a new value of a different type

b)

Create the Value as a Var Variable

c)

Don't give the value a type

d)

You can't change the value of a value

23.

Which line declares a function that takes a String argument called word?

a)

func makeSentence (String:word) {

b)

func makeSentence (word:String) {

c)

func makeSentence (word, String) {

d)

func makeSentence (String, word) {