kitchen-boy / portfolio-generator

Module 9 - Node.js
1 stars 0 forks source link

Title: Modify the HTML template to handle more data #4

Closed kitchen-boy closed 2 years ago

kitchen-boy commented 2 years ago

Description

kitchen-boy commented 2 years ago

Summary of Module 9. 1-3: Learned:

9.4 Lesson: FINISH PORTFOLIO HTML OUTPUT

kitchen-boy commented 2 years ago

PLAN:

Screen Shot 2021-12-07 at 23 42 32

Update template function input:

kitchen-boy commented 2 years ago

9.4.3: Update Template Function Input:

To use the HTML template function in the <app.js> file, must use some of the code that was commented out in lesson 3. (9.3):

  1. Uncomment the expressions near the top of the <app.js> file:

const fs = require('fs'); const generatePage = require('./src/page-template');

  1. Copy the following commented code & place it in the function block of the second <then()> of the <promptUser()> function call.
    Screen Shot 2021-12-08 at 00 30 30

  2. Uncomment the expression that invokes the <generatePage()> with <portfolioData> and uses the result from our <inquirer> prompts as an argument called <portfolioData>.
    Screen Shot 2021-12-08 at 00 34 27

A Promise chain is a series of functions that return Promises, allow us to attach <.then()**> methods to one another.

Screen Shot 2021-12-08 at 00 39 18

kitchen-boy commented 2 years ago

PRO TIP:

const pageHTML = generatePage(mockData);

kitchen-boy commented 2 years ago

Destructure the Data:

Breaking down where this object's property data should go.

Screen Shot 2021-12-08 at 12 52 38

Can create new variables based on data stored in an object.

kitchen-boy commented 2 years ago

STUCK! # How to console.log the 3 variables???????

We'll get to this new JavaScript feature shortly; let's first confirm that it works. If we console.log() the three variables, projects, about, and now header, we'll see that all the portfolio data from templateData has now been organized into three separate sets of data. Great—now we can use this data to update the HTML template literal output!

kitchen-boy commented 2 years ago

The Spread and Rest Operators:

These 2 actions are often necessary in programming:

In the JavaScript ES6 specification: operator, <...> carries out both of these actions. -- its usage dictates what we call it.

The Spread Operator <...>:

* Spreads values across a new array or object

The Rest Operator:

* Condenses leftover array or object values into one new value.

Summary:

kitchen-boy commented 2 years ago

9.4.4. Create the Header and Footer HTML

Now we have:

DONE!:

kitchen-boy commented 2 years ago

9.4.5 Conditionally Create the About Section HTML:

NOTE: Executed a function from a template literal!

NEXT: the last & biggest set of data - the projects!

kitchen-boy commented 2 years ago

9.4.6. Create Project Section HTML:

Function for project HTML data

${generateProjects(projects)}

map() method example

Now each set of data in <projectHtmlArr> will look like the following: Each set of data in projectHtmlArr

Need to figure out how to separate the featured from the non-featured projects.

Using the <.filter()> array method:

The array <.filter()> array method is another new Java Script array method that allows us to execute a function on each element of the array to test whether or not it should be in the new array created from it.

Example of the array <.filter()> method: filter() method example

Refactored <generateProjects()> function code to filtering & mapping the HTML within the template.

NOW:

NEXT:

Note: When we destructure an object by a property that doesn't exist, instead of throwing an error because it can't find the property, it returns undefined. This way, our code won't break if something doesn't exist.

kitchen-boy commented 2 years ago

SUMMARY:

In this lesson, we did the following:

NEXT (& FINAL LESSON):