- DRY = Don't Repeat Yourself
- Identifier
- Start with a lower case letter
- Camel Case
- Constant (keyword "let")
- Variable (keyword "var")
- Autocompletion - use the arrow, tab, and return keys
- Assignment operator (=)
- Making your code understandable
Pet Show code
let numberOfTickets = 150 let ticketPrice = 10 let roomRentalFee = 1000 let posterCost = 40 let revenue = numberOfTickets * ticketPrice let expenses = roomRentalFee + posterCost let income = revenue - expenses
iPhone Video code
let iPhoneCapacity = 64000 let iPhoneCapacityUsed = 10000 let iPhoneCapacityAvailable = iPhoneCapacity - iPhoneCapacityUsed let mbPerMinuteOfVideo = 180 let minutesOfVideoAvailable = iPhoneCapacityAvailable / mbPerMinuteOfVideo
Watermelons and Oranges code
Understanding this code means understanding what each of the abbreviated variable names means. Understanding the variable names means you must understand what the problem is and how to solve it. This is a mathematical problem and you should be able to figure out what they are trying to do. Understanding what you are trying to accomplish, using math, is the first part of accomplishing any programming task.
co = orange pallet count
cw = watermelon pallet count
ow = orange pallet weight
ww = watermelon pallet weight
to = total weight of oranges
tw = total weight of watermelons
ttl = total weight
es = weight on each side of the truck
lhso = orange pallets on the left hand side of the truck
rhso = orange pallets on the right hand side of the truck
No comments:
Post a Comment