Exercises
Work through these in order.
1. Create a user class
The class should have 2 properties: firstName and lastName. Hint: Use this and constructor.
2. Create an instance of the class
Use the new keyword and assign the instance in a variable.
Add a renderUserCard(user) function that accepts a User instance and renders a user card on the page (e.g. a div with firstName and lastName).
3. Create a class method
Add
getFullName: it should return the combined first and last name of the user. Use string concatenation or template literals andthisto read the properties.Add
render()onUser: it should render the user card on the page (same job asrenderUserCard(user)in exercise 2, but as an instance method). Usethis.getFullName()for the name you show on the card.Call
myUser.render()so the card appears on the page (you can stop usingrenderUserCardonce this works).
4. Creating a CV class
The CV that we will be making uses three classes: Job, Education and CV. The CV class we have made for you (with some missing functionality). The Job and Education classes you need to create.
Part 1
Create the classes Job and Education.
Jobhas five properties:id,title,description,startDateandendDate(the dates can be strings or actualDateobjects).Educationhas six properties:id,title,school,address,startDateandendDate.
Part 2
Now add the functionality for the methods in the CV class.
Remember: jobs and educations are just arrays of class instances. So use your array manipulation knowledge for the add and remove methods.
Part 3
Create a new
CVinstance using thenewkeyword, and save it in a variable calledmyCV.Apply the methods you have created on the
myCVobject. Create a fewJobandEducationobjects and add them to your CV.Remove a job and an education from
myCV.Log
myCVto the console, again, and check that the objects were removed correctly.
Part 4
Add a method to the CV class called renderCV(). This method should render out the CV using HTML. Make sure, that view updates, when data is changed.
Last updated