Object-Oriented Programming - Classes, Objects Methods, Strings
Lab 06 Exercise Solutions · Solution - declare server bound objects + route • Store users as an...
Transcript of Lab 06 Exercise Solutions · Solution - declare server bound objects + route • Store users as an...
![Page 1: Lab 06 Exercise Solutions · Solution - declare server bound objects + route • Store users as an Object, rather than an array. • This object will contain multiple ‘user’ objects,](https://reader034.fdocuments.in/reader034/viewer/2022050217/5f62922a2f3c2663777a2c12/html5/thumbnails/1.jpg)
Lab 06 Exercise Solutions
![Page 2: Lab 06 Exercise Solutions · Solution - declare server bound objects + route • Store users as an Object, rather than an array. • This object will contain multiple ‘user’ objects,](https://reader034.fdocuments.in/reader034/viewer/2022050217/5f62922a2f3c2663777a2c12/html5/thumbnails/2.jpg)
![Page 3: Lab 06 Exercise Solutions · Solution - declare server bound objects + route • Store users as an Object, rather than an array. • This object will contain multiple ‘user’ objects,](https://reader034.fdocuments.in/reader034/viewer/2022050217/5f62922a2f3c2663777a2c12/html5/thumbnails/3.jpg)
![Page 4: Lab 06 Exercise Solutions · Solution - declare server bound objects + route • Store users as an Object, rather than an array. • This object will contain multiple ‘user’ objects,](https://reader034.fdocuments.in/reader034/viewer/2022050217/5f62922a2f3c2663777a2c12/html5/thumbnails/4.jpg)
Solution - declare server bound objects + route
• Store users as an Object, rather than an array.
• This object will contain multiple ‘user’ objects, keyed using the email of each new user object.
![Page 5: Lab 06 Exercise Solutions · Solution - declare server bound objects + route • Store users as an Object, rather than an array. • This object will contain multiple ‘user’ objects,](https://reader034.fdocuments.in/reader034/viewer/2022050217/5f62922a2f3c2663777a2c12/html5/thumbnails/5.jpg)
Solution - preload users
• initUsers an object literal
• It contains 2 name/value pairs
• Name is an email of a user
• Value is an object
• server users initialised with initUsers
const initUsers = { '[email protected]': { firstName: 'bart', lastName: 'simpson', email: '[email protected]', password: 'secret', }, '[email protected]': { firstName: 'lisa', lastName: 'simpson', email: '[email protected]', password: 'secret', },};server.bind({ currentUser: {}, users: initUsers, donations: [],});
![Page 6: Lab 06 Exercise Solutions · Solution - declare server bound objects + route • Store users as an Object, rather than an array. • This object will contain multiple ‘user’ objects,](https://reader034.fdocuments.in/reader034/viewer/2022050217/5f62922a2f3c2663777a2c12/html5/thumbnails/6.jpg)
Solution - implement register
• ‘users’ defined as a server-bound object.
• Insert new User objects, keyed by the new users email
![Page 7: Lab 06 Exercise Solutions · Solution - declare server bound objects + route • Store users as an Object, rather than an array. • This object will contain multiple ‘user’ objects,](https://reader034.fdocuments.in/reader034/viewer/2022050217/5f62922a2f3c2663777a2c12/html5/thumbnails/7.jpg)
Solution 3 - implement authenticate, storing current user
• Looking up a user simplified (not need to iterate through an array)
• Reach directly into the users object, using the key (email) field
![Page 8: Lab 06 Exercise Solutions · Solution - declare server bound objects + route • Store users as an Object, rather than an array. • This object will contain multiple ‘user’ objects,](https://reader034.fdocuments.in/reader034/viewer/2022050217/5f62922a2f3c2663777a2c12/html5/thumbnails/8.jpg)
Solution 4 - have donate record donor (current user)
![Page 9: Lab 06 Exercise Solutions · Solution - declare server bound objects + route • Store users as an Object, rather than an array. • This object will contain multiple ‘user’ objects,](https://reader034.fdocuments.in/reader034/viewer/2022050217/5f62922a2f3c2663777a2c12/html5/thumbnails/9.jpg)
JavaScript Skills - FreeCodeCamp
![Page 10: Lab 06 Exercise Solutions · Solution - declare server bound objects + route • Store users as an Object, rather than an array. • This object will contain multiple ‘user’ objects,](https://reader034.fdocuments.in/reader034/viewer/2022050217/5f62922a2f3c2663777a2c12/html5/thumbnails/10.jpg)
JavaScript Programming
• Large proportion of curriculum devoted to javascript skills
• Front End Development contains excellent JavaScript practice problems/solutions
![Page 11: Lab 06 Exercise Solutions · Solution - declare server bound objects + route • Store users as an Object, rather than an array. • This object will contain multiple ‘user’ objects,](https://reader034.fdocuments.in/reader034/viewer/2022050217/5f62922a2f3c2663777a2c12/html5/thumbnails/11.jpg)
Front End Development
• 5 sections - 162 hours of practice
• Basic Javascript
• Object Oriented & Functional Programming
• Basic Algorithm Scripting
• Intermediate Algorithm Scripting
• Advanced Algorithm Scripting
![Page 12: Lab 06 Exercise Solutions · Solution - declare server bound objects + route • Store users as an Object, rather than an array. • This object will contain multiple ‘user’ objects,](https://reader034.fdocuments.in/reader034/viewer/2022050217/5f62922a2f3c2663777a2c12/html5/thumbnails/12.jpg)
Basic Javascript (1) - 10 hours
• 10 hours
![Page 13: Lab 06 Exercise Solutions · Solution - declare server bound objects + route • Store users as an Object, rather than an array. • This object will contain multiple ‘user’ objects,](https://reader034.fdocuments.in/reader034/viewer/2022050217/5f62922a2f3c2663777a2c12/html5/thumbnails/13.jpg)
Basic Javascript (2)
![Page 14: Lab 06 Exercise Solutions · Solution - declare server bound objects + route • Store users as an Object, rather than an array. • This object will contain multiple ‘user’ objects,](https://reader034.fdocuments.in/reader034/viewer/2022050217/5f62922a2f3c2663777a2c12/html5/thumbnails/14.jpg)
Basic Javascript Example
![Page 15: Lab 06 Exercise Solutions · Solution - declare server bound objects + route • Store users as an Object, rather than an array. • This object will contain multiple ‘user’ objects,](https://reader034.fdocuments.in/reader034/viewer/2022050217/5f62922a2f3c2663777a2c12/html5/thumbnails/15.jpg)
Object Oriented & Functional Programming
• 2 hours
![Page 16: Lab 06 Exercise Solutions · Solution - declare server bound objects + route • Store users as an Object, rather than an array. • This object will contain multiple ‘user’ objects,](https://reader034.fdocuments.in/reader034/viewer/2022050217/5f62922a2f3c2663777a2c12/html5/thumbnails/16.jpg)
Example
![Page 17: Lab 06 Exercise Solutions · Solution - declare server bound objects + route • Store users as an Object, rather than an array. • This object will contain multiple ‘user’ objects,](https://reader034.fdocuments.in/reader034/viewer/2022050217/5f62922a2f3c2663777a2c12/html5/thumbnails/17.jpg)
Basic Algorithm Scripting
• 50 Hours
![Page 18: Lab 06 Exercise Solutions · Solution - declare server bound objects + route • Store users as an Object, rather than an array. • This object will contain multiple ‘user’ objects,](https://reader034.fdocuments.in/reader034/viewer/2022050217/5f62922a2f3c2663777a2c12/html5/thumbnails/18.jpg)
Example
![Page 19: Lab 06 Exercise Solutions · Solution - declare server bound objects + route • Store users as an Object, rather than an array. • This object will contain multiple ‘user’ objects,](https://reader034.fdocuments.in/reader034/viewer/2022050217/5f62922a2f3c2663777a2c12/html5/thumbnails/19.jpg)
Intermediate Algorithm Scripting
• 50 Hours
![Page 20: Lab 06 Exercise Solutions · Solution - declare server bound objects + route • Store users as an Object, rather than an array. • This object will contain multiple ‘user’ objects,](https://reader034.fdocuments.in/reader034/viewer/2022050217/5f62922a2f3c2663777a2c12/html5/thumbnails/20.jpg)
Example
![Page 21: Lab 06 Exercise Solutions · Solution - declare server bound objects + route • Store users as an Object, rather than an array. • This object will contain multiple ‘user’ objects,](https://reader034.fdocuments.in/reader034/viewer/2022050217/5f62922a2f3c2663777a2c12/html5/thumbnails/21.jpg)
Advanced Algorithm Scripting
• 50 Hours
![Page 22: Lab 06 Exercise Solutions · Solution - declare server bound objects + route • Store users as an Object, rather than an array. • This object will contain multiple ‘user’ objects,](https://reader034.fdocuments.in/reader034/viewer/2022050217/5f62922a2f3c2663777a2c12/html5/thumbnails/22.jpg)
Example