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

No time to waste! Only got a short amount of time now so going to get a few minutes or so in!

Start Time - 20:14

Conditionals

If statement for 'love calculator' example.





So a simple example for this.

The idea will be that conditionals are used to show that the print statement will do it differently for whatever the number is.

With updated Swift, I would use the Int.random(0...100). Easy fix that would be. Also no UIInt32 needed but just an Int.

So with the if statements, it would be a STRING being returned.

 

Linked to the whole choose your own adventure - if/else for each choice.

BMI Challenge

No need to do this - easy enough to be honest. Just skimming through.

BODMAS principles...



So something I picked up on before is not needing the greater than AND less than value for the middle line (for the else if bmi > 18.5)

A better solution, which Angela is already explaining before I could say it is returning a string instead of a Double. So the value is within the string.



I much prefer string interpolation over concatenation by the way.

*Something I must remember is to create an empty value (interpretation) THEN change the value of it depending on conditions. Rather than returning that string each time. More elegant code!

NOW THIS IS COOL!



That is a really good way of doing two decimal places instead of loads! Nice - I must remember that.

For In Loops

Last bit for now!

All this is fine. Just skimming.








So this is something I need to get used to format and syntax wise. The use of 'where'. This used to be with semi-colons and was more like C+ or C++. Anyway. The where gives the condition. Cool.

Bottles of beer challenge. This was hard the first time but seems OK now. Just skimming through as it's quite long winded!



Hard to see but the for loop is used for the nos. of bottles. Then the new line value is where the beers are interpolated into. Then lyrics is added to the newline so lyrics is returned.



Again, hard to see but this is with the new lines put in.

Even better - using the reversed function! This means you will go backwards (from 70 in this case).

 
Even better - have an input as a function. I would use bottles as an Int input. Then I would interpolate with bottles rather than just number. Easy. Also have the range going up to 'bottles', rather than defined each time. Much more user friendly!

Finish Time - 20:38 (24 minutes but a LOT skimmed through!)

Next time - Fibonacci! This is REALLY hard! I've never quite found a way to do that without help. So will give it a go!

*This is where the line between coding and Mathematics gets a bit too blurry and confusing so I won't see it as failure if it does not work!

Comments

Popular posts from this blog

*Xcode Project Entry 2* F1 Quiz - part 1

Angela Yu Course Part 10 (up to lesson 112)