|
| 1 | +# In-class exercises |
| 2 | + |
| 3 | +## Exercise 1 |
| 4 | +### Create a user class |
| 5 | + |
| 6 | +The class should have 2 fields: firstName and lastName. Hint: Use `this` and `constructor`. |
| 7 | + |
| 8 | +## Exercise 2 |
| 9 | +### Create an instance of the class |
| 10 | + |
| 11 | +Use the `new` keyword and save the instance in a variable. |
| 12 | + |
| 13 | +* Try to log out the variable to the console. |
| 14 | +* Try to log out the `firstName` by accessing it on the user object. |
| 15 | + |
| 16 | +## Exercise 3 |
| 17 | +### Create a class method |
| 18 | + |
| 19 | +The method should be called `getFullName`, and should return the combined first name and last name of the user. Use string concatenation (`"myString1 + " " + myString2"`). Remember to use the `this` keyword to access the values on the class, e.g., `this.valueInConstructor`. |
| 20 | + |
| 21 | +Call the `getFullName` method and log the result to the console. |
| 22 | + |
| 23 | +## Exercise 4 - Creating a CV class |
| 24 | + |
| 25 | +The CV that we will be making uses three classes: `Job`, `Education` and |
| 26 | +`CV`. The `CV` class we have made for you (with some missing functionality). The `Job` and `Education` classes you need to create. |
| 27 | + |
| 28 | +### Part 1: |
| 29 | + |
| 30 | +- `Job` has three properties: `title`, `description`, `startDate` and `endDate` (the dates can be strings or actual `Date` objects). |
| 31 | +- `Education` has three properties: `title`, `school`, `address`, `startDate` and `endDate`. |
| 32 | + |
| 33 | +Create those classes. |
| 34 | + |
| 35 | +### Part 2: |
| 36 | + |
| 37 | +Now add the functionality for the methods in the `CV` class. |
| 38 | + |
| 39 | +*Remember*: jobs and educations are just arrays of objects. So use your array manipulation knowledge for the add and remove methods. |
| 40 | + |
| 41 | +```js |
| 42 | +class CV { |
| 43 | + constructor(jobs, educations, email) { |
| 44 | + // write code here |
| 45 | + } |
| 46 | + |
| 47 | + addJob(job) { |
| 48 | + // add functionality here |
| 49 | + } |
| 50 | + |
| 51 | + removeJob(job) { |
| 52 | + // add functionality here |
| 53 | + } |
| 54 | + |
| 55 | + addEducation(education) { |
| 56 | + // add functionality here |
| 57 | + } |
| 58 | + |
| 59 | + removeEducation(education) { |
| 60 | + // add functionality here |
| 61 | + } |
| 62 | +} |
| 63 | +``` |
| 64 | + |
| 65 | +### Part 3: |
| 66 | + |
| 67 | +Create a new `CV` object using the `new` keyword, and save it in a variable called `myCV`. |
| 68 | + |
| 69 | +Apply the methods you have created on the `myCV` object. Create a few `job` and `education` objects and add them to your CV. |
| 70 | + |
| 71 | +Log `myCV` to the console. |
| 72 | + |
| 73 | +Remove a job and an education from `myCV`. |
| 74 | + |
| 75 | +Log `myCV` to the console, again, and check that the objects were removed correctly. |
| 76 | + |
| 77 | +### Part 4: |
| 78 | + |
| 79 | +Add a method to the `CV` class called `renderCV()`. This method should render out the CV using HTML. Use `document.getElementById("<id>")` and `document.createElement("<element>")`, as well as `element.appendChild(<element>)` to build your HTML using JavaScript. |
0 commit comments