The third project for iOS pre-course using conditionals.
- Read "Control Structures, Loops and Collections" intro to conditionals and the switch statement
- For Objective-C make sure you've read all of RyPress's C Basics. It's a great resource to go back to when you have questions on how to do something in Objective-C
- For Swift read "Section 1" of this Introduction to Swift. Feel free to read the whole thing, but you only need Section 1 for this project. Of course you can also read the section on Comparison Operators in the Apple Documentation
- Either create a project locally and push to GitHub
- Or fork this project and clone it to your computer
Note:
- For more detailed instructions of 'Step 1' see the first project
- 'Step 1' is something we will do hundreds of times in class. You need to be able to do it quickly and without running into issues so it doesn't slow class down.
- Declare two integers (karl and leonard)
- Set the value of karl to 10 and leonard to 7
- Declare two more integers (karlPlace and leonardPlace)
- You need to set those integers in the same line you create them using a ternary operator
- Example:
variablePlace = variable > 7 ? 1 : 2
- That code checks if joshua is greater than 7 and if it is it sets joshuaPlace to 1 otherwise it sets it to 2
- Example:
- If karl is > 7 it should be set to 1 otherwise it should be set to 2
- If leonard is > 7 leonardPlace should be set to 1 otherwise it should be set to 2
- Check if leonardPlace and karlPlace are both equal to 1
- If true log "Both teachers are placed 1"
- If they are not both 1 check if karlPlace is equal to 1
- If true log "Karl is placed 1 and Leonard is placed 2"
- If karlPlace is not equal to 1 check if leonardPlace is equal to 1
- If true log "Leonard is placed 1 and Karl is placed 2"
- If leonardPlace is not equal to 1
- If that's false as well, log "Karl and Leonard are placed 2"
- It should print that "Karl is placed 1 and Leonard is placed 2"
- Feel free to play with the scores of each name and validate that your placement check work correctly