+ All Categories
Home > Documents > Lab 06 Exercise Solutions · Solution - declare server bound objects + route • Store users as an...

Lab 06 Exercise Solutions · Solution - declare server bound objects + route • Store users as an...

Date post: 21-Jul-2020
Category:
Upload: others
View: 1 times
Download: 0 times
Share this document with a friend
22
Lab 06 Exercise Solutions
Transcript
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,

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,
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,
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,

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,

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,

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,

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,

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,

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,

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,

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,

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,

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,

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,

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,

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,

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,

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,

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,

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,

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,

Example


Recommended