Giter Site home page Giter Site logo

ios-control-flow-lab's Introduction

Control Flow Lab

Instructions for lab submission

  1. Fork the assignment repo
  2. Clone your Fork to your machine
  3. Complete the lab
  4. Push your changes to your Fork
  5. Submit a Pull Request back to the assignment repo
  6. Paste a link to of your Fork on Canvas and submit

Question 1

What will be printed when the code below is run? Select all that apply.

let conditionOne = !(4 < 5) || !(3 > 8)
let conditionTwo = !(!true)

if conditionOne {
 print("A")
} else if conditionTwo {
 print("B")
}
if conditionTwo {
 print("C")
}
print("D")
  • A
  • B
  • C
  • D Answer = A,C,D

Question 2

What will the code block below print? Select all that apply:

let appInfo = (name: "myCoolApp", version: 0.4)
switch appInfo {
 case (_, 0.0..<1.0):
 print("\(appInfo.0) hasn't released yet")
 case ("myCoolApp", _):
 print("Thanks for looking at myCoolApp!")
 default:
 print("I'm not quite sure what you are looking at")
}
  • appInfo.0 hasn't released yet
  • myCoolApp hasn't released yet
  • Thanks for looking at myCoolApp!
  • I'm not quite sure what you are looking at
  • It will give a compile-time error

Answer= myCoolApp hasnt released yet


Question 3

What will be printed to the console when the code below is run? Select all that apply.

let x: Int = 4
switch x {
case 0..<4:
 print("A")
case 5..<10:
 print("B")
case is Double:
 print("C")
default:
 print("D")
}
  • A
  • B
  • C
  • D

Answer= D


Question 4

What are the errors in the code below for the switch statement? Select all that apply.

let candyType : String = "skittles"

switch candyType {
case "mAndM":
 print("Melts in your mouth, not in your hand")
case "skittles":
 print("Taste the rainbow")
case "snickers":
 print("Hungry? Grab a Snickers")
}
  • No parentheses around the conditions
  • No opening and closing brackets in each of the cases
  • No default case in the switch statement
  • No print statement right outside the switch statement

Answer= No default case in the switch statement


Question 5

Given the current weather conditions (rain, sunny, snow), use a switch statement to print an appropriate message to the user

let currentWeather = "rain"

// enter code below

let currentWeather = "rain"

switch currentWeather {
case "rain":
print("bring your umbrella")
case "sunny":
print("bring sunglasses")
case "snow":
print("bring your snowboots")
default:
print("idk")
}

Question 6

Given the first name and last name of a Fellow, declare fullName variable and use string interpolation to concatenate the Fellow's full name and print to the console e.g The Fellow's full name is John Appleseed

let firstName = "John"
let lastName = "Appleseed"

let firstName = "John"
let lastName = "Appleseed"

var fullName = "\(firstName)  \(lastName)"
print ("The Fellow's full name is \(fullName)")

ios-control-flow-lab's People

Contributors

davidlawrencer avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.