Days 41-44

in #code6 years ago

February 23rd, 24th, 25th and 26th 2018

Hello! Yes, laziness. Not really that I have working on all these days, but Mr. Procrasto was busy. So, at the ES6 course by Wes Bos I learned about sets. Not the workout type of sets, but close. So what is a set?
Set is a unique array, with an APi to manage the item. It is not index based, but it is a list of items.

        const people = new Set();

       const students = new Set(['Bob', 'Tim', 'Sammy']);

SetIterator: we can loop over it, we can use a for…of loop to loop over it.
There are also weak sets, few limitations. And it can only contain objects.
Consecuently, you cannot innumerate.

There is no .clear() method. Because they clean themselves up. When the reference no longer exists, it would automatically be garbage collected.

At the Web Development Bootcamp by Colt Steele we started to talkabout templates and EJS.

We use can use res.render() to render HTML and send it back

There is also a cute shortcut:

                c9 app.js  -  in the console to open a file in the editor.

Most HTML files are not static, but dynamic and they are called templates.
We need to npm install ejs.

What is ESJ?
ESJ is embedded javascript - we can embed it in HTML.

       app.get("/", function(req, res) {
             res.render("home.ejs");
      });

     app.get("/fallinlovewith/:thing", function(req,res){
        var thing = req.params.thing;
        res.render("love.ejs", {thingVar:thing});  -key-value pair trick
     });  

        <h1>You fell in love with: <%= thingVar.toUpperCase() %></h1>

The % part is a way to add JS to HTML. It looks neat.
Cheers!

Coin Marketplace

STEEM 0.28
TRX 0.12
JST 0.033
BTC 70893.40
ETH 3659.70
USDT 1.00
SBD 3.76