Nick Walter Challenges (Part 2)

So 5 days without coding is a poor effort! I have a very small amount of time (20 minutes) to do some then I will make up for it by doing more at the weekend. As it's a short time, I'm going straight back to Nick Walter's challenges, rather than Angela's more in-depth and theoretical stuff. Right here we go!

Start time - 15:55

Print and comments

// 1) Write a single line comment

// 2) Write a multi line comment


// 3) Print a String, Int and Double all in one print statement

These should all be fine. Let's do it!

// Here is my single line comment

/* Multi line comment:

 This will go over several lines

 No problem at all

 */

var name = "Josh"

var myAge = 33

var shoeSize = 8.5

print("My name is \(name), my age is \(myAge) and my shoe size is \(shoeSize)")


All easy peasy!

Boolean and If Statements

//1) Make a boolean variable that's true

//2) Make a boolean constant that's false

//3) Make a constant called age that's an Int. Then make an if statment that prints "adult" if age is 18 or older. And f younger than 18, print "minor".

//4) Make an if statement that also uses an OR


Again, these look like no problem. Last ones for now though!


//1
var canSwim = true


//2
let fatherTedFan = false


//3
let newAge = 23

if newAge >= 18 {
    print("Adult")
} else {
    print("Minor")
}

//4

var gotName = "Tywin Lannister"

if gotName.hasSuffix("Lannister") {
    print("A Lannister alway pays his debts")
} else if gotName.hasSuffix("Stark") {
    print("Winter is coming")
} else {
    print("Neither a Lannister nor a Stark!")
}

Ok so I misunderstood the last one...I was looking at OR as if else. Let's just do the last one again...

if gotName.hasSuffix("Lannister") || gotName.hasPrefix("Tywin") {
    print("This is an important name")
} else {
    print("Not imporant enough!")
}

Boom!

Finish time - 16:08 (13 minutes total)

Well, 13 minutes is better than nothing. Basically 'keeping my eye in' before I do a proper session at the weekend. All of the challenges were very easy to be honest but they're worth doing as they're application rather than passive learning. Until tomorrow! 

Comments

Popular posts from this blog

*Xcode Project Entry 2* F1 Quiz - part 1

Angela Yu Course Part 10 (up to lesson 112)

Angela Yu Xcode 12 Course - Part 7 (lectures 74 to 79)