Full Transcript

·YouTLDR

Become a Fullstack Developer from Scratch – Full Beginner’s Tutorial

47:29:22EnglishBy freeCodeCamp.orgTranscribed Jul 24, 2026
Analyze another video with Pro30-day money-back guarantee
0:00

This massive course will prepare you to

0:02

be a full stack developer. It's taught

0:04

by many different instructors and put

0:07

together by Scribba. Here's Pere

0:10

Borggan, the CEO of Scribba, introducing

0:13

the course. Hi there and welcome to this

0:16

massive full stack developer path. These

0:19

modules that you are about to watch have

0:20

helped countless students over on

0:22

scribble.com break into the tech

0:24

industry as developers and not in the

0:27

boring theoretical way. No, in a fun way

0:30

where you build games, clone Google and

0:32

Instagram, build AI investing apps, even

0:35

Chrome extensions. And when I say you, I

0:38

really mean you. Because the only way to

0:39

learn this is to type the code out

0:41

yourself. Throughout this course, the

0:43

teachers will throw challenges your way,

0:45

actually over 500 times. And the starter

0:48

code for these challenges can be found

0:50

on GitHub or over on scrimba.com in the

0:53

interactive expanded version of this

0:56

course. We're going to start out with

0:57

the basics of HTML, CSS, JavaScript, and

1:01

so forth, and then move on to the

1:02

frameworks and technologies that are

1:04

used in the industry like React, Node,

1:06

Next, SQL, TypeScript, testing, and even

1:10

AI engineering. So, this really is your

1:12

one-stop shop towards becoming a

1:15

professional fullstack developer. Now, I

1:17

would love to follow you on this

1:19

journey. So, be sure to send me a

1:20

LinkedIn connection request so that I

1:22

can share for you from the sidelines.

1:25

With that, let's dive in.

1:30

>> The French philosopher Renee Deart once

1:33

said three clever words,

1:36

ergo, sum, which translates in English

1:39

to I code, therefore I am. So let us

1:43

prove to ourselves that we actually do

1:44

exist by coding this out in HTML. And

1:48

the way we do that is actually not too

1:50

different from how you would write this

1:52

out in a regular text editor. as there

1:54

you would simply write out the sentence.

1:56

And then if you wanted it a bit more

1:58

prominent, you'd probably highlight it

2:00

and then click on normal text here and

2:02

choose another content type for your

2:05

text. You can see heading one, heading

2:07

two, heading three. Let's hover over

2:09

heading one and then click on it. And

2:11

there you can see that the text became a

2:13

lot more prominent. It became a heading

2:16

one. Now if we want to do this in HTML,

2:18

we'd simply create an HTML file which

2:21

you can see here. It's called

2:22

index.html. HTML as that is a common

2:24

name to give your HTML files. And here I

2:28

would write I code therefore I am. Now

2:33

if we open up a browser and point this

2:35

browser to our HTML file and then run it

2:38

then we can see that the text indeed

2:40

appears in the browser. However, it's

2:43

pretty small. So if we wanted to turn it

2:45

into a heading one instead what we do is

2:48

wrap the text in HTML tags. So before

2:51

the text, I'll do this two angle

2:54

brackets with the text H1 inside of

2:57

them. That's short for heading one. And

3:00

then at the very end of the text, I

3:01

would do the same H1. But since this is

3:04

a closing tag and not an opening tag, I

3:07

would also have to give it a slash

3:09

before the text. And now if I rerun the

3:12

code, there you go. We have made our

3:14

text a lot more prominent. Now I think

3:17

our website should give proper credit

3:19

here. So let's write reneart underneath

3:22

the H1 like that. If we now rerun the

3:25

code, you can see that the text is just

3:28

normal. It's not an H1. And that is

3:30

because it is only the text which is

3:33

within the opening H1 and closing H1

3:36

that gets formatted as a proper heading

3:39

in the browser. In my view, this line

3:41

right here should be a bit bigger. I

3:43

want it to instead look something like

3:45

this where the name is pretty thick and

3:47

big but not as big as the heading one.

3:50

And that brings me to your first

3:52

challenge. I'm going to paste it in

3:54

here. So, what you are going to do is

3:57

try to make our web page look like the

3:59

design in the provided slide. And if you

4:01

are struggling to think of what kind of

4:03

HTML tag you'll have to wrap this name

4:06

in, well, I've got a little hint for

4:07

you. What comes after one? So, pause

4:11

this scrim, jump into the code, and try

4:13

to solve this challenge right now. And

4:15

then when you return back to me, I will

4:17

of course show you the solution as well.

4:19

Good luck.

4:25

Okay, hopefully that went well. The way

4:27

you solve this is by instead of using

4:29

the H1, using its smaller sibling, the

4:33

H2. Like that. It has the exact same

4:36

so-called syntax as the H1. So instead

4:39

of a one you use a two. If we now run

4:42

this, there you go. We have achieved the

4:45

design we wanted. So great job. Let's

4:47

move on.

4:50

Before we move on to the next challenge,

4:53

there's one thing I want to make sure

4:54

that you are aware of. And that is that

4:57

if you have an HTML file locally on your

4:59

computer and you have a browser, what

5:02

you can do is simply drag and drop that

5:04

file into the browser and then it'll be

5:07

rendered. So that is actually more or

5:10

less the same thing that's happening

5:11

here on Scribba. Though here we have a

5:14

mini browser and the text editor inside

5:16

of well your browser because Scribba

5:19

itself is browser based. So a little bit

5:21

meta but it's essentially the same

5:23

thing. Okay. Now, it's time for you to

5:25

get some more muscle memory on how to

5:27

write HTML tags and also get to know two

5:30

new tags because I want you to create a

5:32

news article and more specifically this

5:35

news article right here which has a

5:37

title that says humans have reached

5:38

Mars. It has a subheading right here and

5:41

also some regular text. And the HTML

5:44

tags are H1 for the title, H3 for this

5:47

one. You haven't used an H3 for, but I

5:49

think you know how to do it. And then

5:50

there's finally a P tag for the text at

5:53

the bottom. P is short for paragraph and

5:56

I have provided a little syntax example

5:58

for you here. However, if you've

6:00

understood the logic of how to write

6:02

these tags by now, it shouldn't come as

6:04

a surprise how you do that. Okay, here

6:06

is also the text so that you don't have

6:08

to write all of that out. You can just

6:10

copy paste it instead. So now starting

6:12

here on line 13, write the HTML we need

6:15

in order to create this news article.

6:22

Okay, hopefully that went well. Let's

6:25

start with the H1. I'm going to create

6:27

the open and closing tag and then paste

6:29

in the text like that. Running the code.

6:32

Yes, it works. Moving on to the H3.

6:38

Copying the text.

6:40

Then rerunning the browser. And there we

6:42

go. Finally, there is the paragraph

6:48

like this.

6:51

rerunning the code and there we go. We

6:53

have achieved this exact layout. Great

6:55

job. Let's move on.

7:00

Now you are going to learn about images

7:02

because I really think our Mars article

7:05

needs an image. The way to do that is by

7:07

using the img tag. So we start with our

7:11

angle brackets and then write simply img

7:14

inside of those. And what's unique about

7:16

this tag is that you don't need a

7:18

closing tag. So there is no closing img

7:21

as there is a closing a run or closing

7:24

paragraph. This is simply not needed. So

7:27

it's often called a self-closing tag and

7:30

some people use the slash at the end of

7:32

the opening tag like this just to

7:34

signify that it is closing itself.

7:37

However, it's not really needed. So we

7:39

can skip it. And I think in general that

7:41

less code is better code. So I am just

7:43

going to skip it. However, if you prefer

7:45

to have it like this, that's totally

7:47

fine as well. Okay, enough syntax. How

7:50

do we get this image to work? Because

7:52

right now, if we rerender this page,

7:55

nothing has happened. And that is

7:56

because we haven't told the image tag

7:58

which image we want to render. And the

8:00

way to do that is by writing src, which

8:03

is short for source. And then we write

8:06

equals, and then two quotes, because

8:08

inside of these two quotes, we're going

8:10

to specify the image we want to render.

8:12

And here on the left hand side you can

8:14

see I have mars.jpeg.

8:16

It is in the same directory as our

8:18

index.html file. Meaning I can simply do

8:22

mars.jpg.

8:24

Then run the code. And there we go. We

8:27

have our image. That is super cool.

8:30

However, you can see that this image

8:32

behaves a little bit differently from

8:34

our paragraph for example because where

8:36

is the paragraph take up the entire

8:38

width? the image just take up whatever

8:40

width it needs, leaving us with white

8:43

space on the right hand side if the

8:44

browser is too wide or cutting off the

8:47

image if the browser is too narrow. And

8:50

I actually want this image to behave

8:52

like our other paragraphs. So I'm going

8:54

to show you a little hack to do that

8:56

because normally you'd use CSS for doing

8:58

this. But there is a little trick we can

9:00

use by simply utilizing the width

9:03

attribute. So that is an attribute just

9:06

like source is an attribute and it uses

9:08

the same syntax. We'll do with equals

9:10

and then two quotes and then inside of

9:13

the quotes we can write for example

9:15

100%.

9:17

If we now rerun this you can see yes our

9:20

image is now scaling with the size of

9:23

our browser looking super neat. Now as I

9:26

said this is a hack. So, if you show

9:29

this around to people, you might get

9:30

this annoying guy saying, "Well,

9:33

actually, that's not valid HTML

9:35

according to the specification." But you

9:37

know what? Let's not care about that. At

9:40

this point, you should not give a darn

9:41

about specifications, validity, and aka

9:45

correct HTML. You should instead look at

9:47

yourself like a hacker who grabs

9:49

whatever tool you need in order to get

9:51

the job done. So now we're going to use

9:53

this even though we know it's a hack

9:55

because later down the line you're going

9:57

to learn the proper way of doing this

9:59

using CSS, the language we use for

10:02

styling websites. So with that out of

10:04

the way, I want to show you one more

10:05

thing before I give you a challenge.

10:07

Because one thing that's super cool is

10:09

that you can actually borrow images from

10:11

wherever you want online. So if you find

10:14

an image you like, you can borrow it and

10:16

use it in your project. Let me show you

10:18

how. So if we Google Mars for example

10:21

and click on the images tab and then

10:23

click on whatever image we think is

10:25

cool. For example, this one right here.

10:26

And then in this image view on the right

10:28

hand side here, you can rightclick and

10:30

choose copy image address. Once you've

10:33

copied that, you can simply paste it

10:35

into the source attribute. So I'm going

10:38

to remove Mars.jpeg and paste in the

10:41

image address which I just copied. If we

10:44

now run the code, you can see there we

10:46

go. We have borrowed this super cool

10:49

image from another website online.

10:52

So, it's time for a challenge. What I

10:55

want you to do now is add a second image

10:57

to our article. I want you to find one

10:59

via Google and then place it under the

11:02

H1 element but above the H3 element. So,

11:05

that is right here. And finally,

11:07

remember to use the width attribute to

11:09

make the image as wide as the other

11:11

elements. I'm going to leave you here

11:13

with the marks image again and wish you

11:15

good luck. go ahead and solve this

11:17

challenge right now.

11:21

Okay, hopefully that went well. What you

11:23

needed to do was write the angle

11:24

brackets img. Then set the source to

11:27

whatever image you found online. I'm

11:29

going to reuse the one I found earlier

11:31

like that. If we're rendering this, this

11:34

is a really wide image by default.

11:36

That's not what we want. We want it to

11:38

scale with our browser. So, we need the

11:40

width attribute. width equals a 100%

11:45

like that. And now we have two super

11:48

cool images in our article, both scaling

11:51

up and down with the size of the

11:53

browser. Great job. Let's move on.

11:59

Okay, now you're going to learn about

12:01

something called nesting, which is the

12:03

act of nesting HTML elements inside of

12:06

other HTML elements. So, let me show it

12:09

to you in practice. Let's say that we

12:11

want to group all of these elements here

12:14

together. What we then do is above all

12:17

of the HTML tags, write another HTML

12:20

tag. And in this case, we use the

12:21

so-called div, which is short for

12:24

divider. However, I don't think that is

12:26

a very good name. I would rather call

12:27

this, for example, a container, though

12:30

div is what it's called. So, we're just

12:31

going to have to stick with that. Now,

12:33

in order to nest elements inside of this

12:36

div, we'd write the closing tag below

12:39

all of the HTML tags in our article. And

12:41

then for readability purposes, we'd

12:43

indent all of the tags in our article.

12:45

So now our H1, image, H3, P, and image

12:49

here are all children of this div tag

12:52

right here. This doesn't change our

12:54

layout at all. So this div tag here is

12:57

invisible. However, it has now given us

12:59

the ability to target the entire article

13:03

just by targeting this div right here.

13:05

And that is useful if we, for example,

13:07

want to add some styling to our entire

13:10

article using CSS or somehow manipulated

13:13

using JavaScript, which is the

13:15

programming language that you use in

13:16

browsers. And very often, you'll

13:19

actually see a ton of divs on a page. So

13:21

for example, you'd see another div

13:23

around this image element here, which

13:25

then would have been indented yet

13:27

another time in order to signal that

13:29

this is indeed a child of this div,

13:31

which again is a child element of this

13:34

div. Now if we were to visualize an HTML

13:37

document, it would look something like

13:38

this. You'd have, for example, a div up

13:41

here and it would have two children

13:43

which could be their own divs like this.

13:46

And then this lefth hand div here would

13:48

for example have an image tag as its

13:50

first child and also an H3 as its second

13:52

child. The other div on the right hand

13:54

side could have an H1 tag as its child,

13:57

P tag as its child, maybe even another

13:59

div as its child. And then if we go yet

14:02

another level deep, this paragraph tag

14:04

might have its own child, which could be

14:06

for example an A tag, which you haven't

14:08

learned about yet, but which you'll

14:10

learn about soon, as that is the

14:11

so-called anchor tag that allows you to

14:13

create links on websites. And looking at

14:16

this visualization, you might think,

14:18

well, this kind of looks like a family

14:20

tree. And yes, it does. And that is

14:22

exactly why we call this structure the

14:24

HTML document tree because we are inside

14:27

of an HTML document. and how they are

14:30

nested inside of each other becomes kind

14:32

of like a tree where you have a trunk

14:35

and then branches going out from that

14:37

and then yet again new branches going

14:39

out from those branches and so on and so

14:41

on. So now that you know that let's move

14:44

on to the next scrimm.

14:49

Okay, now we're going to use your newly

14:51

acquired internet superpowers in order

14:53

to perform a little practical joke

14:56

because you might have a friend who is

14:58

far too obsessed with a sports team. For

15:00

example, I myself am a Manchester United

15:03

fan and one of the worst things I can

15:05

imagine is if some rich billionaire buys

15:08

the club and changes its name. That

15:11

would make me truly outrageous. So, what

15:14

we're going to do now is change the news

15:16

on BBC Sports so that you then can show

15:19

this page to a Man United fan and thus

15:22

make them really upset while you get a

15:25

good laugh. So, let's go ahead and do

15:27

this here on the BBC Sports page on this

15:30

top article here. I'm going to write

15:32

click on the text and then you can see

15:35

it gives me the option to choose

15:36

inspect. Now, note that this is on a

15:39

Chrome browser as that is what I'm

15:41

using. If you're in a different browser,

15:42

there might be slightly different steps

15:44

here or a different wording, but overall

15:47

in general, the steps are the same. So,

15:49

I'm going to click on inspect. And then

15:51

you can see that it opens up this panel

15:54

on the bottom of the browser. This is

15:56

called the developer tools. And here you

15:58

can see we are in the elements tab. And

16:01

that shows us the HTML elements that are

16:04

on the page. And here the one we have

16:06

chosen now which happens to light up

16:08

this area on the BBC site contains the

16:11

title of our article and it is an A tag

16:14

which I've just briefly mentioned and

16:15

that you're going to learn more about

16:16

later. Now we can't see any text here.

16:19

So I'm going to click on this age tag

16:21

and there you can see it contains an

16:23

age3 tag nested inside of it. If we

16:26

click on that one as well you can see

16:28

that there we see the text that is

16:30

rendered in the browser. So here we can

16:33

double click on that text and change it

16:35

for example to something as awful as

16:38

Jeff Bezos to buy Man United and rename

16:40

the club after himself. Oh my god that

16:44

is about the worst piece of news any

16:46

United fan can read. So if we now hit

16:49

enter there you can see boom we have

16:51

changed the text on BBC. Now let's click

16:54

on this paragraph here as well open it

16:57

up because there we can also change the

16:59

text that is written underneath the

17:00

title. Let's paste in the US billionaire

17:03

says he doesn't follow the Premier

17:04

League but wants to own the club to grow

17:06

his personal brand. This just gets worse

17:10

and worse. So now if we hit enter that

17:12

is also rendered in the browser. Now I'm

17:15

going to scroll a little bit up in the

17:16

dev tools here and hover over this div

17:18

tag here because as you can see that

17:20

highlights our image. So it seems to be

17:23

that our image is nested inside of a div

17:25

tag. Let's open it up by clicking on

17:27

this triangle. And there we can see

17:29

another div tag. Well, okay. Still

17:31

highlighting the image. Let's open up

17:33

that one as well. Oh, wow. There we have

17:36

yet another div tag. A div inside of a

17:38

div inside of a div. This is web

17:40

development in a nutshell. Let's open it

17:42

up again. And there, yes, we can see our

17:45

image tag. I'll scroll a bit down. And

17:48

you can see there are tons of different

17:50

attributes here. We're going to ignore

17:52

almost all of these and then instead

17:55

direct our attention towards the src

17:57

attribute. That one we know because that

17:59

is the one we need to change in order to

18:01

change this image. So now let's open up

18:04

a new window. Search for Jeff Bezos.

18:07

Click on an image we like. For example,

18:09

this one right here. Right click on it

18:11

and choose copy image address. Then can

18:14

do now is double click on this source

18:16

and then remove the existing source

18:18

inside of the quotes like that and then

18:21

paste in our image of Jeff Bezos.

18:23

However, if we now hit enter, you can

18:25

see nothing changed. And that is because

18:27

BBC is a little bit fancy here. They use

18:30

another attribute called src set, which

18:33

helps the browser render different sized

18:36

images on different types of screens

18:38

depending on what kind of image is

18:40

appropriate for the given screen the

18:42

website is rendered on. So, what we're

18:44

going to do here is just double click on

18:46

the src set so that everything's

18:48

highlighted and just delete all of it

18:50

and then hit enter. And boom, there you

18:52

go. We have Jeff Bezos looking pretty

18:56

ready to acquire this football club and

18:58

rename it Bezos United. Finally, I'm

19:00

going to close this panel by clicking on

19:02

the X in the right corner here. And

19:05

there you go. We have our article. So

19:07

now the final step is just to take this

19:09

site, show it to someone who is a

19:11

Manchester United fan, and get a good

19:14

laugh. Now, a final notice. If you

19:16

refresh this page, you will lose your

19:18

changes because you only made your

19:20

changes locally. And when you refresh

19:22

it, the entire page gets the fresh data

19:25

from the database of BBC and not from

19:27

whatever local changes you did. And

19:29

since it is local, that also, of course,

19:31

implies that your changes only happen on

19:33

your computer. You don't change BBC in

19:36

production, of course. So, go ahead and

19:38

play around with some sites online. See

19:40

if you can come up with a fun little

19:42

practical joke for a friend. Have fun

19:45

and I'll see you in the next Scrim.

19:49

Now, we're going to get you on boarded

19:51

to the Scriber community because this

19:53

career path is so much more than just a

19:56

course. It's also a social experience

19:59

where you are able to get help, meet

20:02

like-minded people, network, and find

20:05

inspiration. Our Discord server is at

20:07

the heart of our community and thousands

20:10

of coding students just like you are

20:12

online at any given time. We pride

20:15

ourselves on keeping our Discord an

20:17

ultra supportive and friendly space and

20:19

we welcome coders of all abilities from

20:22

complete beginner to professional and we

20:24

have a ton of channels for all kinds of

20:26

coding and workrelated subjects. So in a

20:28

moment click on this link, this

20:30

screenshot or any of the screenshots you

20:32

see in this scrim. That's right.

20:34

Remember, a scrim is not a video. So,

20:36

the link that you can see right here,

20:38

that is a live link. You can click it.

20:40

This is going to take you through to

20:41

Discord, and you can just follow the

20:43

steps to get registered and onboarded

20:45

into our Discord server. And that will

20:47

no doubt involve proving that you're

20:49

human by identifying elks or something.

20:52

Once you're done, why not make your

20:54

first stop on our Discord server, the

20:56

introduce yourself channel. Let us know

20:58

who you are, where you're from, what

21:00

your aims are, what you like to do when

21:02

you're not coding. This is your first

21:04

opportunity to interact with the

21:06

community. And then why not browse the

21:08

channels? And I'm just going to point

21:10

out a few highlights. We have the

21:12

announcements channel for news and

21:14

updates. There's a stay accountable

21:16

section with today I will and today I

21:19

did. These channels can help you set

21:21

goals and brag about your success.

21:23

Career chat, as the name suggests, is

21:25

where you can get and give help on

21:27

career related matters. The I built this

21:29

channel is a great place to show off the

21:31

amazing projects you've been building.

21:33

And if we just scroll down a little bit

21:35

more, we can see that we've got the

21:36

general help channels here for

21:38

JavaScript, design, HTML, React. And

21:41

then here we've got specific channels

21:43

for each module of this career path. So

21:46

you can always go there if you get stuck

21:48

and you need a bit of help or if you

21:50

want to pay it forward and help out some

21:52

other students. Now, if we go right back

21:54

up to the top, we have event. And this

21:56

will show you up and cominging events

21:58

for the Scriber community. Every Tuesday

22:00

we host the Scriber town hall on

22:02

Discord. And if you click into events,

22:05

you'll see that the next town hall is

22:07

already scheduled and it will show you

22:08

the time in your local time zone. So for

22:11

me here in the UK, it's at 5:00 p.m. on

22:13

Tuesdays. The town hall is a live event

22:16

especially for the Scriber community

22:18

with 45 minutes to an hour of chat on

22:20

all things Scrimber, learning to code,

22:22

and getting jobs in tech. Each week is a

22:26

bit different. Sometimes we interview

22:28

students who recently got hired to hear

22:30

about the process for example or we

22:32

review some code or give feedback on a

22:34

CV. But we always have time to answer

22:36

your questions. So do come along and

22:39

join us. It's an interactive experience.

22:41

You can chat with us and it would be

22:43

great to see you there. It's a great

22:45

chance for you to interact with the

22:47

Scriber team and have your say. You'll

22:49

find the town hall channel right here in

22:51

the sidebar. Also check out the

22:53

Scrimbert podcast. There is a new

22:56

episode every week and it's packed with

22:58

motivational advice and job hunting

23:00

strategies from developers who've been

23:02

exactly where you are now. You can click

23:05

this slide or find it wherever you

23:07

usually get your podcasts. I'm going to

23:10

leave you with these two links. We've

23:11

got the Scriber podcast and our Discord

23:14

server. Once you've checked them out,

23:15

come back here and you're ready to get

23:17

started coding your very first web app.

23:23

Now you're going to learn about your

23:24

very first interactive HTML element and

23:27

that is the button tag because buttons

23:30

are all over the web. So to create a

23:32

button, simply start with your angle

23:34

bracket and a button opening tag and

23:36

then a button closing tag like that. And

23:39

in between the two tags, you write

23:40

whatever text you want inside of your

23:42

button. Now, as you can see, it's styled

23:45

with a background color that also has a

23:47

border around it. And you can even click

23:49

it. Now, this button doesn't do

23:51

anything. In order to hook this up with

23:54

some kind of feature, for example,

23:55

trigger a purchase. Then you'd have to

23:57

learn JavaScript, and that is outside

23:59

the scope of this course, but something

24:01

you'll learn later in the front-end

24:03

developer career path. So, for now, our

24:05

button will just be there and pretend to

24:07

do something while actually being pretty

24:09

useless. Now that you've seen this once,

24:11

I want to put you on the spot and give

24:13

you a challenge. I want you to create a

24:16

layout according to the design in this

24:18

slide. So imagine that you are building

24:21

a website where people are to sign up.

24:23

Then it would be very natural to have

24:24

something like this where you have an H1

24:26

at the top welcoming them, a paragraph

24:28

with a little message and then a sign up

24:30

button. So I want you to create this

24:33

layout. You don't have to write the text

24:35

because I've provided it here. Just make

24:37

sure that you set up the HTML tags

24:39

correctly so that it renders properly on

24:41

the page. Good luck.

24:47

Okay, hopefully that went well. Let's

24:49

now do it together. I'll start with the

24:51

welcome H1 tag like that. Paste that in.

24:55

And boom, there we go. Next up, there's

24:58

the paragraph, opening tag, closing tag,

25:01

and then pasting the text in between.

25:04

Running this code. It still looks

25:05

correct. Finally, the button like that

25:09

with sign up written inside of it. And

25:11

boom, there we go. We have our

25:13

completely useless signup form that

25:16

doesn't do anything. But in the next

25:18

scrim, we're going to add on to this. So

25:20

stay tuned and then I'll see you there.

25:25

The signup section we have here is

25:27

actually pretty useless because there's

25:29

no way for our users to add, for

25:31

example, their username or a password.

25:33

So in this scrim, we're going to fix

25:35

that. Which leads us to the input tag.

25:37

The input tag is just like images, a

25:40

self-closing tag. So we only write the

25:42

opening tag and not the closing tag like

25:44

we do with buttons for example. However,

25:46

we have to specify what kind of type our

25:49

input should be. So it has this type

25:51

attribute just as the image has a source

25:55

attribute and the value of the type can

25:57

be a range of different options, but

25:58

we're going to start off with the most

25:59

common one and that is text. If we run

26:02

this, you can see we get this nice

26:04

little text box in the browser. Another

26:06

handy attribute is the placeholder.

26:09

That's where we can give the user a hint

26:11

about what kind of data we're asking

26:12

for. So, for example, enter username

26:15

like that. If we run this, you can see

26:17

it says enter username. Okay, let's do a

26:20

mini challenge. We of course want them

26:22

to enter their password as well. So, I

26:24

want you to create a new input field on

26:26

line four, which is identical to the one

26:28

on line three, though it should say

26:30

enter password in the placeholder as

26:32

opposed to enter username. And don't

26:34

just copy this line and change this

26:36

word. I want you to get some muscle

26:38

memory here. So, go ahead and do that

26:40

right now.

26:46

Okay, hopefully you did like this. Input

26:49

type equals text placeholder enter

26:53

password like that. And there we go. Now

26:56

you can enter a username and a password.

26:59

However, in the real world, passwords

27:01

are never exposed like that. The

27:03

characters are always masked. And the

27:05

way we achieve that is simply by

27:07

changing the type from text to password

27:09

like that. If we run the code now, you

27:11

can see the username is shown but the

27:14

password is masked. Really nice. And

27:17

speaking of this type attribute here, it

27:19

can take a range of different values

27:21

which turn into really interesting

27:23

interactive elements on the page. For

27:25

example, you can do type equals date.

27:28

Let's say you want the user to add their

27:30

birth date during sign up. And then you

27:32

get this nice little date picker. Or you

27:34

can do type equals time. For example, if

27:37

you want the user to be able to

27:38

configure when they should get some kind

27:40

of notification, that gives the user a

27:42

nice time picker. Or let's say you want

27:45

to give the user a way to configure the

27:47

theme of their profile with colors. Then

27:49

you can do type equals color. And then

27:51

you get this powerful color picker where

27:53

the user can add basically any color

27:55

there is through moving around on these

27:57

dots. So, the input tag is a really

28:00

versatile tool in your toolbox. Okay,

28:03

let's move on to the main challenge

28:05

because I want our users to have profile

28:08

pictures, which means that you need to

28:10

add an HTML input field that lets them

28:13

upload image files. And I'm not going to

28:15

tell you what kind of type that input

28:18

field has. I'm just going to show you

28:20

how it looks, which is like this. You've

28:22

probably seen it online before. It's

28:24

basically a button. And when you click

28:25

it, it lets you choose an image from

28:27

your local file system. And the reason I

28:30

want you to figure out what the type

28:32

attributes should be here is because

28:34

being good at Googling is actually huge

28:36

part of being a good programmer. And the

28:38

two are actually not that easy to

28:40

separate from each other. So this gives

28:42

you a way to practice those Googling

28:44

skills. And I'm going to give you a hint

28:46

that the keywords you should use are

28:49

found in this last sentence right here.

28:52

So go ahead and solve this challenge

28:54

right now and then I will of course show

28:56

you the solution when you return back to

28:58

me.

29:10

Okay, hopefully that went well. Let's do

29:12

this. The keywords I think are important

29:15

here are HTML input because we know

29:17

we're looking for an HTML input tag. And

29:20

then what is our intent? Well, it is to

29:22

upload image files. And I think Google

29:24

can handle this just by combining HTML

29:26

input upload image files. If we just

29:29

paste that into Google, let's see what

29:31

we get. And as you can see, when we

29:33

search for that, we get a first hit from

29:35

developer.mmazilla.org.

29:37

Let's click into that. And here you can

29:39

see the title is input type equals file.

29:42

And we get this little code snippet

29:43

here. And it also says input elements

29:45

with type file let the user choose one

29:48

or more files from their device storage.

29:51

Sounds pretty good so far. Let's zoom in

29:53

on the code here. And there you can see

29:54

that they are actually using the profile

29:56

picture example themselves. Choose a

29:58

profile picture with this button which

30:00

looks suspiciously similar to what I

30:02

just showed you a couple of minutes ago.

30:04

So I think we've found it. What we're

30:06

looking for is type equals file. Let's

30:09

add this up above the signup button.

30:12

put a equals file like that. If we run

30:17

this code, yes, there we go. We get this

30:20

button which looks like exactly what

30:21

we're looking for.

30:26

Okay, now we're going to move on from

30:28

using Google to building Google. I mean,

30:31

how cool is that? You've learned HTML

30:33

for just about 30 minutes and now you're

30:36

going to build the most visited website

30:38

in the world. That is just amazing. As

30:40

you can see here on the similar web

30:42

overview, Google is at the very top

30:45

amongst the most visited websites in the

30:47

world, beating sites like YouTube,

30:49

Facebook, Instagram, Wikipedia, and all

30:52

the way at 10th, a pornography site, of

30:54

course. And by the way, it's a little

30:57

bit sad to see that this adult site has

30:59

almost three times the average visit

31:02

ruration of Wikipedia. So, a pretty deep

31:05

insight about humankind right there.

31:08

Anyway, we are going to build google.com

31:11

and it'll look like this. However, now

31:14

you're probably wondering, how can we

31:15

make a page look like this? This doesn't

31:17

look like regular HTML. And that is

31:20

because I've cheated a little bit and

31:22

added this line up here, which is a link

31:24

tag to styles.css. And if you look at

31:27

the file menu in the left hand side, you

31:29

can see that actually we have a file

31:31

called styles.css, CSS which contains

31:34

exactly that cascading stylesheets which

31:36

is the language for styling websites and

31:39

which you're going to learn all about a

31:41

little bit later in this course.

31:42

However, for now, I want you to

31:44

completely ignore this. What you should

31:46

do instead is just create the four HTML

31:49

tags we need in order to create a

31:51

google.com clone. And then this CSS will

31:55

be pulled in and take care of styling

31:58

the elements as they should be. So that

32:00

it will look like this. And to give you

32:02

a hint, this is an image file pointing

32:05

to google.png, the file I've added here.

32:08

And PNG is just a file format just like

32:11

JPEG. You can use it in the exact same

32:13

way as we used JPEGs earlier on. So you

32:15

should know how to do that. And this is

32:17

an input field. You have to figure out

32:19

what kind of type it is. I think you

32:21

might have a clue. This is a button on

32:23

the left hand side. And this is also a

32:24

button. So basically it is these four

32:26

tags you need to create in order to

32:28

build a clone of the world's biggest

32:31

website. So go ahead and do that. Start

32:33

down here and ignore the line up here.

32:36

And then when you return back to me, I

32:38

will of course show you the solution as

32:40

well. Good luck.

32:47

Okay, hopefully that went well. If not,

32:50

no worries. Let's do it together. So,

32:54

starting with the image tag for the

32:56

Google logo, I'm going to do img like

33:00

that. And it's a self-closing one. So, I

33:02

don't need a closing tag, but I need a

33:04

source attribute. And it should point to

33:07

the Google.png file. So, I'll just do

33:09

Google.png

33:11

like that. And let's run this. And ooh,

33:14

there we go. We got the logo. Okay,

33:17

moving on. Let's do the input field.

33:19

Also, a self-closing tag.

33:24

running the code and there we go. We

33:27

have a input field looking pretty good.

33:30

Okay, next up there's the two buttons.

33:32

One saying Google search and one saying

33:34

I'm feeling lucky. So I'm going to add

33:36

both of these button Google search and

33:40

then since I'm lazy I'm going to copy it

33:43

and do I'm feeling lucky like that.

33:45

Let's run this. And there we go. We have

33:49

a Google clone with just four HTML

33:52

elements. So, if you did this, give

33:55

yourself a pat on the back. It is

33:57

fantastically well done. You should

33:58

really be proud of yourself. And if you

34:01

didn't manage to do it, just try it

34:02

again and I think you'll make it. At

34:05

this point, it might be a good idea to

34:06

take a little break and digest

34:08

everything you've learned. And then when

34:09

you are ready to continue, I will see

34:11

you in the next scrim.

34:17

Okay. Now that you've built google.com,

34:19

you probably want to showcase your

34:21

project on some kind of portfolio page.

34:24

So, let's pretend we're creating exactly

34:26

that. Here we have the index.html page,

34:29

the main page of our portfolio. And as

34:31

you can see, it says Pier Harold

34:33

Borggan, developer, teacher,

34:35

procrastinator. So, a really good

34:37

description of myself. Though, what it

34:39

lacks is some kind of page or section

34:41

which describes my projects. though I

34:44

have actually created the underlying

34:46

page for exactly that over here on

34:48

work.html.

34:50

As you can see, this is a few tags that

34:52

describes my google.com project.

34:54

However, there's no way for the users to

34:57

know this. The only way they can get to

34:58

this page now is by actually typing

35:01

work.html up in the browser here and

35:04

then it is rendered. We don't want that.

35:06

Instead, we want some kind of link from

35:08

the index page that is this one that

35:11

points towards the work.html. HTML. And

35:14

in order for us to achieve that, you

35:16

have to learn about anchor tags, aka

35:19

links. An anchor tag is simply an HTML

35:22

tag with an A. So, let's open and close

35:24

an anchor tag and write, for example,

35:27

check out my projects

35:30

here. Like that. If we run this,

35:34

it seemingly looks just like our

35:36

paragraph. And we can't click it either.

35:38

And that is because for anchor tags, you

35:40

also have to provide it with an href

35:42

attribute. That's short for hypertext

35:45

reference. Really fancy, scary looking

35:47

word right there. Don't worry about it.

35:49

All this attribute does is decide where

35:52

the link should point to. So if we do

35:54

equal and then two quotes, we can inside

35:56

the quotes simply write work.html.

36:00

If we now run this, you can see that it

36:02

renders as a link. And when we click it,

36:04

boom, we're taken to the work.html HTML

36:07

page. Really nice. Now, another thing I

36:11

want to show you with with anchor tags

36:12

is that you can nest them inside of

36:15

other tags and actually inline in a text

36:17

block. So, let's say that we want to

36:19

link to google.com from this site. Then,

36:22

we'll create a paragraph, which can say

36:24

something like check out the live demo

36:28

here. And we only want the here word to

36:31

be a clickable link. Well, then we'll

36:33

simply wrap the anchor tag around here

36:36

as well and we'll close it before we

36:40

close the paragraph. And then we'll do

36:42

the href paste in the URL to google.com.

36:46

Now, this is a link that points to an

36:47

external website, not to any of our

36:50

pages. So, if we run this, you can see

36:52

that the link is now only over the

36:54

hairword. However, if I click this link

36:56

now, the Scribba mini browser will try

36:59

to head over to google.com and we only

37:01

allow the mini browser to render Scribba

37:03

projects at the moment. So, that won't

37:05

work. Instead, what I'm going to do is

37:07

make this link open in a new tab. The

37:10

way we do that is through a new

37:11

attribute. So, first I'm just going to

37:13

break this into a new line just to

37:15

improve the readability a little bit.

37:17

And then here I'm going to write target

37:20

equals

37:23

blank. Now, that is a cryptic way of

37:26

saying that you want the link to open up

37:29

in a new tab. I know. But if we now run

37:31

this, if you click on this link, what

37:33

you'll see is that in your main browser,

37:36

a new tab will be opened at the

37:38

Google.com homepage. So, I'm not going

37:40

to go deeper into why it's called target

37:43

equals blank, but this is the way to do

37:46

it. I of course wish that HTML had a

37:49

better solution for this. for example,

37:51

new tab equals yes, that would have made

37:55

a lot more sense to me. But this is how

37:57

it is. You just have to accept it. Okay,

38:00

that was a lot of talking for me. Now,

38:02

it's time for a challenge. I want you to

38:04

create an anchor tag that links back to

38:07

the index.html page because if a user

38:10

ends up on this page, they also need a

38:12

way to get back to the main page. So,

38:14

create that link here however you want

38:17

and then I will show you the solution

38:18

when you return back to me.

38:25

Okay, hopefully that went well. Let's

38:28

create this anchor tag. I'll wrap it

38:30

inside of a paragraph and write turn to

38:33

homepage and then I'll simply wrap the

38:35

homepage word in an anchor tag like that

38:38

and point that anchor tag to index.html.

38:43

If we run this, you can see return to

38:44

homepage. And if we click that, we are

38:46

back at the homepage. Great job. Let's

38:50

move on.

38:53

Okay, we're back at our Google example

38:55

here. And now I want you to add a anchor

38:57

tag to the page because sometimes you'll

39:00

see that Google adds a little text

39:02

underneath the buttons. For example,

39:03

something about privacy like we protect

39:05

your privacy then with a learn how link

39:07

that you can click on to read more about

39:09

that. So that is exactly what I want you

39:12

to do. I want you to add an anchor tag

39:14

that points to blog.html.

39:17

As you can see, I've added a blog.html

39:19

file up here. And I want you to wrap the

39:22

link inside of a paragraph tag. So, just

39:24

as it is here, you can see it's an

39:26

entire paragraph here, but the anchor

39:29

tag is only wrapping the second

39:31

sentence. So, go ahead and do that right

39:34

now.

39:40

Okay. Hopefully that went well. Let's do

39:42

it. We'll start with the paragraph

39:44

opening and closing tag. and then do we

39:47

protect your privacy like that. And here

39:50

we're going to add the anchor tag in

39:52

line. So I'll do a open and close and do

39:56

an href as well. Point it to blog.html

40:01

and the text should be learn how. Let's

40:04

run this. And boom, there we go. We have

40:07

added a nice little link here. If we

40:09

want to learn more about Google privacy,

40:11

then we can click this link. But not

40:14

much to see here. Turns out that privacy

40:17

probably isn't as important for a

40:18

company who makes money by showing ads

40:20

to users. Anyway, we can click on this

40:23

link, return back to Google, and there

40:25

we are. Great job solving this

40:27

challenge. Let's move on.

40:32

Okay, now we're going to talk about how

40:33

to structure HTML documents because the

40:37

structure we have here isn't actually

40:39

correct. It's a very simplified

40:41

structure compared to how it should be.

40:43

Though it does work. So, I didn't want

40:45

to give you all of these theoretical

40:47

boring structure things up front. I

40:49

wanted you to build stuff from the get-

40:51

go without the added complexity of the

40:53

proper HTML structure as my philosophy

40:56

is first make it work and then make it

40:58

better. However, now we're at the point

41:00

where we should make it better. So,

41:03

let's have a look at how to structure

41:04

HTML documents properly. And HTML is

41:08

actually quite like us humans. It has a

41:10

head and a body. And what do you place

41:12

inside of these elements? Well, in the

41:14

body, that's where you place the tags

41:16

you see on the page. And that is these

41:19

tags here. So, our image, our input,

41:21

button, paragraph, and our anchor tag

41:24

because these are visible on the page.

41:26

Now, of course, the CSS styling up here

41:28

also results in a different layout, but

41:31

the link tag in itself is not something

41:33

that is rendered on the page. So, it

41:35

should not be in the body tag. So, let's

41:38

just add the body right here. We'll add

41:41

the starting tag and then the closing

41:42

tag down here on line nine. And then

41:44

we'll indent everything inside of the

41:46

body like that. So, moving on to the

41:49

head. That's where we add metadata. And

41:52

what do I mean about that? Well, it can

41:53

be many things. For example, styles. So,

41:56

this link right here should be inside of

41:58

the head. We'll do head and then close

42:01

it off here like that. Other things

42:03

we'll have in the head is the title tag.

42:05

So let's have a look at what that is. If

42:08

we navigate over to the BBC football

42:10

page and zoom in on the top, you can see

42:12

up in the tab, it has a icon. It says

42:15

football-b

42:20

icon at the beginning here and this

42:22

sentence is controlled by elements we

42:24

place inside of the heads tag. So if we

42:26

want to add a title text in a tab,

42:29

simply write title and then for example

42:31

google.com would be natural to write

42:33

here. Though we haven't implemented tabs

42:35

in the mini browser here on screen so

42:37

you won't see that. But had we done that

42:39

it would have looked like this though of

42:41

course would have said google.com

42:42

instead. So we don't need that. So let's

42:45

just remove it. Another thing that is

42:47

controlled by tags inside of the head

42:49

tag is how articles are shown on social

42:52

media. So if we zoom out a little bit

42:54

here and click in on this article at the

42:56

top here and if we now were to take this

42:59

URL and share it for example on Twitter,

43:01

what we then would get is a different

43:04

heading on the Twitter card than what

43:06

the article natively has and also a

43:08

different image than the main image on

43:10

the article. So this is metadata that

43:13

has told Twitter that if this article is

43:15

shared on Twitter, we want you to use

43:18

this heading instead of the heading that

43:20

is inside of the article. and also this

43:22

image instead of this image right here.

43:24

So that was a lot about the head tag.

43:27

We're not going to use the head that

43:28

much, but I wanted to give you an

43:30

understanding about why it is important.

43:32

Now there's one more HTML tag we need

43:35

and that is the HTML tag in itself which

43:38

should wrap all other HTML tags. So we

43:41

need to up here at the very top write

43:44

HTML and at the very bottom close it off

43:48

and also then indent everything inside

43:50

of it like that. And then there's one

43:53

more thing which is to me a little bit

43:55

annoying that we need that is the dock

43:57

type declaration because you have to

44:00

tell the browser that we're actually

44:01

using HTML 5 and not HTML 4. That's just

44:05

a version of the HTML specification and

44:08

that is done by this line up here. You

44:10

can see it's blue and it starts with an

44:11

exclamation mark. So, it's actually not

44:13

an HTML tag. It's just metadata for the

44:16

browser. Because if you don't do this,

44:18

the browser will assume that you're not

44:20

using HTML 5, but an earlier version of

44:22

HTML, and that might result in some

44:24

quirks on the page. Though, in 99% of

44:27

cases, there will be no difference

44:28

between adding this and not having it.

44:30

So, at times, you'll probably see

44:32

tutorials on Scribba where I've

44:34

forgotten to add this because for the

44:36

purposes of our example, it won't make

44:38

any difference. But if you have

44:40

something that you want to deploy to the

44:41

world and have in production, then you

44:43

just have to accept that you need this

44:45

sign up at the top. And sometimes you'll

44:47

see people write it in capital letters

44:49

as well. Doesn't really matter. I prefer

44:51

having lowercase letters. Okay, that was

44:54

a lot of theory. It's time to get your

44:56

hands on the keyboard. And luckily

44:58

though, we have a blog.html file which

45:01

doesn't have the proper HTML structure.

45:03

So your challenge is simply to add the

45:05

proper HTML document structure to this

45:08

page. And I don't want you to copy paste

45:10

my tags, but write them out on your own

45:12

instead so that you build up that ever

45:14

so important muscle memory. Go ahead and

45:16

give this one a shot right now and then

45:18

I will of course do it myself when you

45:20

return back to me.

45:26

Okay, let's do this. I'll start with the

45:29

body as that should wrap our visible

45:33

elements on the page like that. Then

45:36

I'll do the head. Though we haven't

45:38

linked to the styles on this page. So

45:40

the head will actually just be empty

45:42

like this. So I'll keep it on one line.

45:43

Moving on. It is the HTML document. And

45:46

that should wrap everything. So I'll do

45:48

like that. And at the very end, I'll add

45:51

the dock type HTML to tell the browser

45:53

that we are working with HTML 5, not

45:56

HTML 4. So if we now navigate over to

45:59

the blog.html site, you can see that

46:02

nothing has seemingly changed. And as

46:04

goes for the main page itself. This

46:06

structure we've added doesn't result in

46:08

any visible change. We just have a more

46:10

correct underlying code file to work

46:12

with. Great job. Let's move on.

46:17

Now you're going to learn about lists

46:19

because let's say that you for example

46:21

want to create some kind of tribute

46:23

site. It could be for whatever. For

46:25

example, uh I don't know the Beijing

46:28

Winter Olympics. If that's one of your

46:31

interests, you might want to create a

46:32

tribute site where you list out the top

46:35

nations who competed or something like

46:37

that. And if so, you would have to use

46:39

an HTML list. So, let's first just

46:42

figure out which nation actually won the

46:44

most medals in the Beijing Olympics. So,

46:46

I'm going to click on the medals tab

46:47

here on the Olympics site. And here we

46:50

got it. And zoom in a little bit. And

46:53

oh, wow. It turns out that actually

46:57

Norway, my country, completely

47:01

obliterated

47:02

the other countries with 16 gold medals

47:06

over other nations like Germany, China,

47:09

and the US.

47:12

That is really astonishing, especially

47:15

consider the fact that the size of the

47:17

Norwegian population is this compared to

47:20

the other nations here. I mean, way to

47:23

go Norway. We got to create this list in

47:26

HTML. Okay. So, how do we do that? Well,

47:30

we have to use two different tags. One

47:33

tag for wrapping the entire list and

47:35

another tag for each list item. The

47:37

wrapper tag is one called O. That's

47:40

short for ordered list. And then inside

47:44

of the ordered list, we place the list

47:46

items, the li.

47:48

So when we do this and write Norway here

47:52

render this you can see that the browser

47:54

gives this a number as it is the first

47:57

item in the list and also indents it a

47:59

little bit from the left hand side. So

48:02

adding another one here it then gets the

48:05

number two and is stacked below the

48:07

first one. So let's add the final ones

48:12

like that. Looking pretty good. We have

48:16

a list just like on the Olympic site.

48:19

Now, if we wanted to be a little bit

48:20

more diplomatic here and not brag too

48:22

much about this insane victory by

48:24

Norway, we could change this O to a UL.

48:29

That is an unordered list. And as you

48:31

can see, then the numbers are replaced

48:34

with dots. And now you might ask

48:36

yourself, well, why do we need these

48:38

unordered list? They look like kind of

48:40

boring elements you just use in Word

48:42

documents or something like that. Well,

48:44

once you learn about CSS, you'll be able

48:47

to style your list however you want and

48:50

thus make it much more usable. If we,

48:52

for example, head over to BBC Sports

48:54

here and rightclick on the navbar here

48:57

and click inspect, then we'll see that

49:00

actually this entire navbar is an

49:02

unordered list item with each of the

49:05

categories being its own list items. So,

49:08

lists are all over the web and important

49:11

to learn. Okay, now I'm going to remove

49:14

all of this and give you a quick little

49:16

challenge because I want you to create

49:18

an ordered list inside of the body tag

49:21

and then fill it with your top three

49:23

favorite foods.

49:25

So, go ahead and give this a shot right

49:27

now.

49:33

Okay, hopefully that went well. Let's do

49:36

it. So, we start out with an O tag that

49:39

we're opening up and closing. And as for

49:42

the list items, even though Norway is a

49:45

great Winter Olympics country, it is a

49:47

truly mediocre country when it comes to

49:50

food. So, my favorite food is definitely

49:52

from other places than where I'm from. I

49:54

love Italian pasta. I love Japanese

49:57

ramen soup.

49:59

And lately, I've been really into pai.

50:04

So, there we have it. Rendered out on

50:06

the page. Really good job learning about

50:08

HTML lists. Let's keep up the pace and

50:11

move on.

50:14

Okay, now you have arrived to the main

50:16

project of this section. You are going

50:18

to build a website about yourself and

50:21

we're going to personalize it as well

50:23

plus deploy it to the world so that

50:25

anyone around the world can visit this

50:27

website. It is going to be so much fun.

50:30

And here is the website itself. As you

50:32

can see, it's pretty simple with hardly

50:34

any styling by default. Just a little

50:36

bit on the button and the input field

50:38

here. as with the border around this

50:40

image. And building this lightly styled

50:43

design is the first part, part one of

50:46

the challenge. And then in part two of

50:48

the challenge, we are going to go crazy

50:50

on the styling with just a few

50:52

parameters that you are to tweak and

50:53

it's going to look so cool. But let's

50:56

not get ahead of ourselves here. Let's

50:57

first just run through what kind of tags

50:59

you need in order to build this website.

51:02

So, first off, there is an image tag and

51:04

the image you should use should be added

51:06

to the file system on the left hand side

51:08

here. As you can see, there is a

51:10

pair.jpeg image here. And the way to add

51:12

an image to this file system is simply

51:15

by drag and dropping it over this

51:17

section. Next up, there's an H1 here as

51:20

well with a title. Of course, you should

51:22

write your own name, not my name. And

51:24

then there's an H2 heading as we need

51:26

some fun facts about you. The fun facts

51:28

itself are built using an unordered list

51:31

plus list items inside of the ul

51:33

element. And then there is a paragraph

51:35

with a link nested inside of it that

51:38

should go to your LinkedIn profile. So

51:40

the point here obviously is to replace

51:42

all of this information with fun facts

51:44

about you with your name with your image

51:47

your LinkedIn profile so that when you

51:49

share this with the Scribba community

51:51

other people will be able to get to know

51:53

you better. And then finally, we have an

51:55

input field here and a button that won't

51:58

really do anything cuz we're not hooking

52:00

this up with a real newsletter. We are

52:03

just pretending that you have a

52:04

newsletter that people can sign up to.

52:06

So once you've done this, you've

52:08

completed part one of the challenge and

52:10

you've also filled up this body element

52:12

here with HTML tags. Next, you'll move

52:16

on to part two of the challenge. What

52:18

you'll do there is take your existing

52:20

design and modify it. So, if we head

52:23

over to the index.javaScript file, you

52:26

can see that there are a bunch of

52:27

so-called JavaScript functions, which

52:29

probably look really scary at this

52:31

point, but don't worry. The only thing

52:33

you're going to do here is take the word

52:36

that you see inside of the quotes right

52:38

here, and replace them with one of the

52:41

words that are commented out in the line

52:43

above. because this will give you the

52:45

opportunity to change the styling on the

52:47

page according to what word you change

52:50

this argument to. So what you are to do

52:53

here is look at the name of this

52:54

function. It says favorite movie genre

52:56

and what is that? Do you like space

52:58

movies, scary movies, military movies,

53:01

romantic movies, cowboy movies and so

53:03

on. And then just take your preference

53:05

and change it like this. So if you

53:07

choose cowboy for example, what then

53:09

will happen is that the font on the

53:11

website suddenly became like a western

53:13

movie. That's pretty cool. And moving on

53:16

here you are to answer what is your

53:18

favorite fruit? Is it watermelon,

53:20

tomato, banana? If it for example is

53:23

banana, then you should replace regular

53:25

with banana. And what will then happen?

53:27

If you run the code, then suddenly your

53:29

page is banana colored. Really nice. So

53:33

now you are a cowboy banana. That's

53:35

pretty cool. Finally, there's two more

53:38

parameters you can tweak. First, tell me

53:41

is your favorite mode on your computer.

53:43

Light mode or dark mode. If you choose

53:45

dark and run the code again, then you

53:48

can see the colors have flipped and now

53:50

it is primarily dark with the brown

53:52

background and the light yellow color as

53:55

opposed to how it was previously with

53:57

the yellow background and brown text

53:58

color. And then at the very end, you are

54:01

to choose what kind of style you like

54:03

your edges to be. Sharp, soft, or round.

54:07

Let's say you like round. Well, then

54:08

you'll simply replace sharp with round.

54:11

And there we go. We have a nice round

54:13

layout where the image and the input and

54:16

button now have a much more round

54:19

feeling to it. So, what happens here is

54:21

that these are JavaScript functions that

54:24

execute code, which you can see further

54:26

down in the index.js js file and change

54:29

the layout accordingly. Though, you

54:32

should ignore everything below this

54:34

line. Don't even try to understand it.

54:36

It's far outside the scope of this

54:37

course and you're going to learn

54:39

JavaScript later in the front-end

54:40

developer path anyway. So, it's nothing

54:42

for you to worry about right now. Now,

54:45

I'm going to reset all of these. Set

54:48

these two to regular and these two to

54:50

light and sharp as that is the default

54:53

styling that we should have. And then

54:56

I'll leave you with this image right

54:58

here as it now is your turn to build

55:00

this layout, personalize it with the

55:02

JavaScript functions so that you have

55:04

your very own completely unique website.

55:08

So go ahead and do this right now and

55:10

then I will see you when you return back

55:11

to me.

55:17

Okay, hopefully that went well. Let's

55:19

now do this together. First, we need the

55:21

image tag. So I'm going to do img. The

55:24

source is the pier.jpeg

55:27

which I'd already added. Yes, there we

55:29

can see it is rendering properly. Next

55:32

up, there is an H1.

55:34

I my name is Pear like that. Very good.

55:39

Moving on, we have the H2

55:42

fun facts about me like that. And then

55:47

there's the unordered list and the list

55:49

items. So, I'll do ul close that ul

55:53

because the list items need to be inside

55:55

of the ul and the first one is 36 years

55:59

old. I'm going to copy this one

56:03

like that. And I live in Norway and I

56:08

sing in a choir.

56:11

And there we go. Looking pretty good.

56:13

Next up, there is the paragraph with the

56:15

inline anchor tag. Here's the paragraph.

56:19

connect with me on LinkedIn like that.

56:24

Oops, it should say me on LinkedIn here.

56:27

And then we are to wrap LinkedIn here

56:31

into an href like that. And then I'm

56:36

going to paste in the URL to my LinkedIn

56:38

right here. And if you actually want to

56:40

connect with me on LinkedIn, feel free

56:42

to click on this link as soon as I've

56:44

added the target equals

56:47

blank so that it opens up in a new tab.

56:51

Okay. Finally, we we need to add the

56:53

input and the button.

56:55

Input type text like that and button

57:00

with join newsletter as the text.

57:05

Yes, that worked. And we finally just

57:08

need the placeholder in the input.

57:11

And here we're going to write enter

57:13

email. Enter email. Like that. And that

57:18

actually

57:20

looks pretty good to me. That is what we

57:23

were looking for. Yes. Okay. Next step.

57:26

We are going to personalize it. This

57:28

will be easy for me. I really love

57:31

movies about space. So I'm going to

57:33

choose space here as my favorite movie

57:34

genre. It gives me this really neat

57:36

sci-fiish font. And I am a huge avocado

57:40

fan. So, got to do that. Woo! Looking

57:43

pretty good. I tend to prefer both light

57:46

mode and dark mode, but let's try dark.

57:48

Yeah, not bad. And as for favorite edge

57:52

style, I'm not going to do completely

57:54

round, not completely sharp, but

57:56

something in between, as I think the

57:58

answer often is something in between.

58:01

And yes, there we go. Pretty cool

58:03

website. Now, the final thing I want you

58:06

to do is head back to your note where

58:08

you created your website and then click

58:11

on the bottom right icon, the cog wheel,

58:14

and choose download as zip because

58:17

that'll download your project to your

58:19

local machine. And we need that in order

58:21

to deploy this project over the next few

58:23

scrims. So, what I'd recommend you to do

58:26

is on your computer, create a dev folder

58:29

and move that zip file you just

58:31

downloaded to this dev folder. Double

58:33

click on it to open it. That'll give it

58:35

this long obscure ID. So if I were you,

58:38

I would change that to something

58:40

understandable, for example, personal

58:41

site and just save it so that you have

58:44

your project neatly placed with a good

58:46

name on your local computer so that we

58:48

are ready to share it with the world

58:50

over the next few scrims. It is going to

58:52

be epic. So I look forward to see you in

58:55

the next scrim after you've done all of

58:57

this. I'll see you there.

59:01

In order to get your personal site live

59:03

on the worldwide web, we are going to

59:06

use a service called Netlifi as it is

59:08

both free, easy to use, and powerful as

59:11

it's used by tons of professional

59:13

developers. So, if you're following this

59:15

course on scrimma.com, just click on

59:18

this slide right here and you'll be

59:19

taken to Netlify. Or if you're following

59:22

this course on YouTube, just head over

59:24

to netify.com and you'll get to the

59:26

exact same page. Once you're there, I

59:28

want you to click at the sign up button

59:30

as that'll take you to an authentication

59:32

screen where you can choose a bunch of

59:34

different options. I am going to go with

59:36

the email option. So, I'll click on that

59:39

and fill in my email and also choose a

59:41

password. Then I'll click sign up, which

59:43

again will trigger Netify to send a

59:46

verification email to my inbox. So, I'll

59:48

head over to my inbox and click on

59:50

verify email. That'll take me to the

59:53

Netlefy onboarding page where I have to

59:55

tell them a little bit about myself. So

59:57

here I'm going to say that I'm using

59:58

Netlefi for personal reasons. And

1:00:01

opening up this select box here, I'm

1:00:02

going to classify myself as a hobby

1:00:04

developer. And my first project will be

1:00:06

a personal/portfolio

1:00:08

site. Then I'll scroll a bit down and

1:00:10

give my team a name. I am just going to

1:00:13

call my team pair as it's common to use

1:00:15

your first name, but you can choose

1:00:16

whatever name you want on your team.

1:00:18

Once you're done with all of that, click

1:00:20

on the setup and continue. Then you are

1:00:22

taken to the page where you are to

1:00:24

deploy your first project. You can

1:00:26

either import an existing project, start

1:00:29

from a template, or deploy manually. And

1:00:31

that's exactly what we are going to do.

1:00:34

So, what I want you to do here is return

1:00:36

back to the folder you created in the

1:00:38

previous scrim called personal site. And

1:00:41

then mark all of the files and drag and

1:00:44

drop them into this rectangle. Once

1:00:46

you've done that, your browser might ask

1:00:48

you if you actually want to upload the

1:00:50

files to the site. Just confirm that by

1:00:52

clicking on upload and then Netlify

1:00:55

starts its magic. At this point, they

1:00:57

are working under the hood deploying

1:00:59

your site to the web. So here you might

1:01:01

have to wait for a couple of minutes

1:01:03

until you see this icon right here turn

1:01:05

into a screenshot of your personal site.

1:01:08

Now if that doesn't happen within a

1:01:09

couple of minutes, just try to refresh

1:01:11

the site itself as that'll probably do

1:01:13

the trick. Then you can simply click on

1:01:15

this URL right here and boom, you have

1:01:18

deployed your site so that anyone in the

1:01:20

world can access it. That is a

1:01:23

phenomenally great job and you should

1:01:25

truly be proud of yourself. The final

1:01:28

step I think you should do now is to

1:01:30

share your creation with the world. I

1:01:32

would recommend you to use either

1:01:34

LinkedIn or Twitter as both of those

1:01:36

have huge communities of developers. So

1:01:39

what you should do is basically what

1:01:40

Jolene and Jess are doing here. Share a

1:01:43

link to your personal site. Write a

1:01:45

couple of sentences about it. And also

1:01:47

feel free to mention anyone else who've

1:01:48

been involved in this project and add a

1:01:51

relevant hashtag like Jess is doing

1:01:53

here. For example, 100 days of code.

1:01:55

That that is a great hashtag to follow

1:01:57

and to use as it puts you in touch with

1:02:00

a bunch of other people online who are

1:02:02

going through the same learning journey

1:02:04

as you are. So I am looking forward to

1:02:06

see your personal site either on

1:02:08

LinkedIn or Twitter. And I'm also

1:02:10

looking forward to see you in the next

1:02:13

scrim.

1:02:16

Guess who is my favorite person in the

1:02:19

world right now? You are because you

1:02:22

have just completed the HTML section of

1:02:24

this course and that is a huge

1:02:26

milestone. So now let's have a look at

1:02:29

all of the awesome things you've

1:02:30

learned. Starting out you learned about

1:02:32

the core HTML tags that is the heading

1:02:35

H1 H2 and so on and also the paragraph

1:02:38

tag. And then you learned about nesting,

1:02:40

which is how some tags are inside of

1:02:43

other tags, which again are inside of

1:02:45

yet other tags, eventually creating a

1:02:47

tree structure of HTML tags. Then you

1:02:50

learned about buttons and input fields,

1:02:52

which are the elements that make your

1:02:54

website interactive. And then we talked

1:02:56

about anchor tags, a super important

1:02:58

concept as it allows you to create links

1:03:01

between different websites or web pages

1:03:03

on the web. And then of course we had to

1:03:06

learn about proper HTML document

1:03:08

structure as that is important with the

1:03:10

doc type declaration the HTML tag head

1:03:13

tag and also the body tag. From there,

1:03:16

we moved on to lists. Both unordered

1:03:19

lists like this one right here and

1:03:21

ordered lists, which is super cool and

1:03:23

almost as cool as what you followed up

1:03:25

with, which was to deploy your personal

1:03:28

web page to the web so that anyone

1:03:30

around the world can navigate to it and

1:03:33

check out your creation. This was a lot

1:03:36

of learning. I completely understand if

1:03:39

you're a little bit overwhelmed right

1:03:40

now. And it's totally okay to now take a

1:03:43

break, relax a little bit as in the next

1:03:45

section you are going to learn about CSS

1:03:48

aka cascading stylesheets. That is how

1:03:52

we design our web pages so that they go

1:03:54

from the dull default HTML styling into

1:03:58

being beautifully designed, polished

1:04:00

products that people enjoy looking at.

1:04:03

So super exciting times ahead of us. So

1:04:06

when you are ready, I will see you in

1:04:07

the CSS section.

1:04:11

Welcome to the second section of this

1:04:13

course where you are going to graduate

1:04:15

from HTML into the world of CSS or

1:04:19

cascading stylesheets as it stands for.

1:04:22

This is super exciting because now

1:04:24

you'll be able to make your sites look

1:04:26

beautiful as well. So the main project

1:04:28

of this section is actually the

1:04:30

google.com homepage because this time

1:04:32

around you are going to write the CSS as

1:04:36

well. And this probably looks a little

1:04:38

bit frightening right now, but don't

1:04:40

worry. I'm going to take you through it

1:04:42

step by step. And actually, before we

1:04:44

get going with Google, we're going to

1:04:46

get you familiar with the syntax here

1:04:47

and have some fun destroying

1:04:49

vikipedia.org.

1:04:51

So, it's going to be a lot of fun and we

1:04:52

have no time to lose. Let's just get

1:04:55

started.

1:04:59

Okay, so let's get you writing your

1:05:01

first lines of CSS straight out of the

1:05:03

gate. As you can see here, we have an

1:05:05

HTML file which has a body that simply

1:05:08

has please accept our cookies as text

1:05:11

directly in the body tag and that is

1:05:14

rendered here in the mini browser.

1:05:16

However, as you'll notice, the style

1:05:18

doesn't exactly look like default

1:05:20

browser styling. And that is because

1:05:22

we've added this line here which says

1:05:25

link meaning it's linking to something.

1:05:27

And what kind of relation does this link

1:05:30

has to our HTML? Well, it's real

1:05:32

stylesheet. It is a sheet that contains

1:05:35

styles. And where does this sheet live?

1:05:39

Well, that is dictated by the href

1:05:41

attribute, which you probably recognize

1:05:43

from anchor tags. And it's pointing to

1:05:45

styles.css.

1:05:47

And lo and behold, in our file system,

1:05:50

we have a styles.css file. And there we

1:05:53

can see a few lines of scary looking

1:05:55

code you've never seen before, perhaps.

1:05:57

However, don't worry. We're going to go

1:05:59

through this. So what happens here is

1:06:01

that this CSS code is being pulled into

1:06:04

the HTML file by this line three here

1:06:07

and then it is applied to the website

1:06:09

when it is rendered. So if we were to

1:06:12

comment out this line three here and

1:06:15

rerun the example, it'll look very

1:06:16

boring like this. So let's undo that.

1:06:19

Doesn't exactly look great now either,

1:06:21

but it's at least some styling. Although

1:06:24

this cookie widget is a little bit

1:06:26

weirdly designed in my opinion, which

1:06:29

leads me to your challenge. You are

1:06:31

going to redesign this cookie widget by

1:06:35

changing the values inside of this body

1:06:39

selector. And now you might ask, well,

1:06:41

what is a selector? Okay, let's go

1:06:43

through that because that is the basic

1:06:46

CSS syntax you need to know in order to

1:06:48

solve this challenge. So CSS works by

1:06:52

selecting certain elements on the page

1:06:54

that is HTML elements and then styling

1:06:57

them however you want. And the element

1:07:00

you select is what you start with when

1:07:02

writing a CSS rule. Here we are

1:07:04

selecting the body. That is the exact

1:07:07

same thing we're doing here. And what's

1:07:09

our body? Well, it is this tag right

1:07:11

here. Then in order to apply some

1:07:14

specific styling to the body tag, we

1:07:16

write an opening curly bracket and a

1:07:18

close curly bracket. And then inside of

1:07:21

those brackets, we have something called

1:07:23

a property, which in this case is color,

1:07:25

and a value, which in this case is red.

1:07:28

So here we're saying that the color,

1:07:30

which is actually text color, that's

1:07:32

what color means here. The text color in

1:07:35

the body should be red. So if I now

1:07:38

change the color property from blue to

1:07:42

red, you can see in the main browser we

1:07:44

have changed the text inside of our body

1:07:47

to red because if we head over to the

1:07:49

HTML, this text is indeed inside of our

1:07:52

body.

1:07:54

Now as you might have noticed as well,

1:07:56

the property is followed by colon and

1:07:59

the value is followed by semicolon. And

1:08:02

you have to have that notation,

1:08:04

otherwise you'll break the example.

1:08:07

So, what I want you to do now is

1:08:10

redesign this cookie widget. Make sure

1:08:12

you change all of the listed CSS

1:08:15

properties. That's background color,

1:08:17

font size, font weight, text align, and

1:08:19

margin top. And what you'll change it to

1:08:22

is up to you, but I've given you the

1:08:23

hints of what kind of values the

1:08:26

properties expect. Here in the comments

1:08:29

on the right hand side you can see

1:08:31

comments in CSS is done with this star

1:08:34

and slash character. So the gradeout

1:08:36

text as in with the HTML is not

1:08:39

interpreted by the browser. It's just

1:08:40

help text for you in order to solve this

1:08:43

challenge. And I'm intentionally not

1:08:46

giving you any more information about

1:08:49

what each of these properties mean

1:08:51

because I think they're pretty

1:08:53

self-explanatory. So, I want you to

1:08:55

experiment with changing them and draw

1:08:57

your own conclusions as to what, for

1:09:00

example, the font size does to the

1:09:03

styling on our page. And then once

1:09:04

you've done this, once you've redesigned

1:09:06

the cookie widget, move on to the next

1:09:08

scrim. And then I will show you how I

1:09:11

would do it as well. Good luck.

1:09:16

So, really good job writing your first

1:09:18

lines of CSS. That is no small

1:09:21

accomplishment. Now, I'm going to show

1:09:23

you how I would design my cookie widget.

1:09:26

So, I want my widget to have cookie

1:09:28

colors. So, for my background property,

1:09:30

which is what sets the background color

1:09:32

of the body, which fills up the entire

1:09:34

browser at this point, I'm going to

1:09:36

choose a color called saddle brown. Like

1:09:39

that. And you might wonder, well, how

1:09:42

did I know that saddle brown is a color

1:09:44

that CSS supports? Well, you might have

1:09:47

noticed as you wrote CSS values that VS

1:09:50

Code, our editor, starts suggesting

1:09:52

values for you as you start typing. So

1:09:55

that is how I found Saddle Brown. This

1:09:57

suggestion box here isn't recorded by

1:10:00

Scribba itself. So you won't see it in

1:10:02

recording, but you will see it as you

1:10:04

interact with the code yourself. So we

1:10:06

have the background. Now let's move on

1:10:07

to the next property, which is color.

1:10:10

And that dictates the color of the text.

1:10:12

It is set to red. Though let's choose

1:10:14

white here. That looks pretty good. The

1:10:17

next one, font size dictates well the

1:10:19

size of the font. And here you can see

1:10:21

we are using px values which is short

1:10:23

for pixels. And you can choose whatever

1:10:26

value you want. Let's see what happens

1:10:28

if we increase it up to 200. Oh wow,

1:10:31

that is far too big. So instead, let's

1:10:34

try something like 25. Yeah, that's

1:10:37

pretty good. Next, there's the font

1:10:39

weight. You can choose between lighter,

1:10:41

normal, or bold. And if we change this

1:10:43

to bold, you'll see there that our text

1:10:46

suddenly got a bit thicker, which is

1:10:47

exactly what this property does. It

1:10:49

changes the thickness of the font. Okay,

1:10:51

text align. It is set to right, but we

1:10:54

can also set it to left or center. Let's

1:10:56

see what happens if we do left. And that

1:10:58

bumps the text over to the left hand

1:11:00

side. I think we should have our cookie

1:11:01

widget with centered text like that.

1:11:04

Finally, margin top. What does that do?

1:11:07

Well, if we try to change this to, for

1:11:08

example, 50, you can see that. Oh, wow.

1:11:10

That created more space here at the top.

1:11:13

So it adds margin aka spacing at the

1:11:16

top. And here I think maybe 50 was a bit

1:11:18

too much. Let's do 30. Yeah, that is

1:11:21

just right. Now you probably ended at a

1:11:24

completely different styling than this.

1:11:26

That is okay. The point here was to

1:11:28

experiment. Before you leave, I'll give

1:11:30

you a sneak peek at another tool you can

1:11:32

experiment with, and that is a different

1:11:34

way of describing colors in CSS called

1:11:37

hex codes. So here I'll paste in this

1:11:40

weird looking code starting with a

1:11:42

hashtag. And as you can see it created

1:11:44

the exact same color. So this here is

1:11:46

actually a recipe for the saddle brown

1:11:49

color. And it's actually a description

1:11:51

of three different things. How much red,

1:11:54

green, and blue this saddle brown color

1:11:57

consists of. So if I change this eight

1:12:00

here to one instead, you can see that

1:12:02

completely changes the color. Now if

1:12:04

that is confusing, don't worry. You'll

1:12:06

learn more about that later. I just

1:12:08

wanted to give you a sneak peek on it.

1:12:10

As with all of these other properties,

1:12:12

you are going to get more comfortable

1:12:13

with all of this. So, it's not a problem

1:12:16

at all if you completely forget about

1:12:18

all of these properties and values over

1:12:20

time as you do it again and again. It'll

1:12:22

become a part of your muscle memory. So,

1:12:24

with that, let's carry on.

1:12:29

Now that you know enough CSS to be

1:12:31

dangerous, let's use your newly acquired

1:12:34

superpower in order to destroy

1:12:36

Wikipedia. And for that, we need a

1:12:38

Wikipedia page. And about the coolest

1:12:41

one there is is this list of helicopter

1:12:44

prison escapes. I mean, oh my god, how

1:12:47

insane is that? So, click this image and

1:12:50

you'll be taken to this article and then

1:12:52

I'll show you step by step how we can

1:12:54

destroy it with CSS. So the first thing

1:12:57

you need to do is to right click as

1:12:59

that'll open this menu where you can

1:13:01

choose inspect and once you click that

1:13:03

the dev tools will open. Then choose the

1:13:06

icon in the far left as that allows you

1:13:08

to use your cursor to select elements on

1:13:10

the page. So that when you hover over an

1:13:12

element like this one, you'll see that

1:13:14

the dev tools selects it for you. So if

1:13:16

you move your cursor over to the logo,

1:13:18

you'll see that one selected. And if you

1:13:20

move your cursor over to the main part

1:13:22

of the screen here, you can see it

1:13:23

selects the entire article. Once you're

1:13:25

on that selection, I want you to click

1:13:27

because that'll select the specific HTML

1:13:30

element here in the elements tab. And

1:13:32

don't worry about all of this. You do

1:13:35

not need to recognize the tags and

1:13:36

attributes and everything you see here.

1:13:38

What I instead want you to do is head

1:13:40

over to the right hand side where you

1:13:41

see element.style. Click there and

1:13:44

you'll be able to actually apply CSS

1:13:46

directly to this page. So you can, for

1:13:48

example, write background red and boom,

1:13:51

there we have really ruined this

1:13:53

article. Then if you select another

1:13:56

element on the page from this body

1:13:58

content element here, you can do the

1:14:00

exact same thing. Click on the element

1:14:02

style and now for example write font

1:14:04

size and 30 pixels. And there you go.

1:14:07

Now you can click on the X icon in the

1:14:09

far right corner here and then you can

1:14:11

read about these helicopter prison

1:14:13

escapes with a really bad background and

1:14:15

huge text if that's what you prefer. So

1:14:18

feel free to spend an hour in this

1:14:20

article and then I will see you in the

1:14:21

next scrim.

1:14:26

Okay, so now it's time for you to yet

1:14:28

again build the google.com homepage, but

1:14:31

this time around you're also going to

1:14:33

write the CSS so that you'll understand

1:14:36

everything that goes into building this

1:14:38

elegantly designed search engine. As you

1:14:41

can see, I've set up the basic skeleton

1:14:43

here in the HTML file for you. In the

1:14:46

body tag, we have an image which is

1:14:49

pointing to the Google.png PNG image

1:14:51

which lies in the same directory as our

1:14:54

index html folder up here. And we have

1:14:56

an input type text which is our search

1:14:59

field. And we're only going to start

1:15:00

with these two elements and then later

1:15:02

move on to the buttons. Now, as you can

1:15:04

see in the mini browser here, this looks

1:15:07

horrible. It has no styling. So the logo

1:15:10

is far too large. The input field

1:15:12

doesn't look very good. So in short,

1:15:13

there's a lot of work to do here. But

1:15:15

before we can start writing CSS, you

1:15:17

need to link to the CSS file. You can

1:15:19

see I have a style CSS here which just

1:15:22

sets the background of the body to red

1:15:24

as a way of testing whether it is

1:15:26

actually a link to the HTML. Currently,

1:15:28

it's not. You are going to have to link

1:15:30

to the CSS file on your own. And if you

1:15:33

remember a couple of scrims back, I

1:15:34

showed you how to do that. Though,

1:15:36

please don't look back at that scrim in

1:15:38

order to solve this challenge. Instead,

1:15:40

Google it because I do that almost every

1:15:42

single time I have to link from an HTML

1:15:44

file to a CSS file. So, you should not

1:15:46

be ashamed for googling such a quote

1:15:48

unquote simple thing. Instead, just do

1:15:51

that right now because it's important

1:15:52

practice and then when you come back, I

1:15:54

will show you how I would do it as well.

1:16:03

Okay, hopefully that went well. Now,

1:16:06

let's have a look at how we can solve

1:16:07

this. So, I would simply type how to

1:16:10

link to CSS into Google and click at the

1:16:13

top result. This happens to be a W3

1:16:15

schools article. Here you can see that

1:16:18

there's a few different ways you can

1:16:20

import CSS into the HTML file, but we're

1:16:23

only going to worry about the first one

1:16:24

here called external CSS. As you can

1:16:27

see, if we scroll a bit down, what we do

1:16:29

is we type link re equals stylesheet and

1:16:32

href with a pointer to the CSS file

1:16:34

itself. So we'll do link file equals

1:16:39

stylesheet

1:16:41

href equals styles.css

1:16:45

and then closing it. And if we now

1:16:47

refresh the browser, boom, there we go.

1:16:50

It is red looking horrible. So we can

1:16:53

remove that so that it looks white

1:16:55

again. But now we know that we have

1:16:57

linked the CSS and the HTML together. So

1:16:59

we are ready to move on and start

1:17:01

styling our page.

1:17:05

The first thing we want to fix in our

1:17:07

example here are the widths of the

1:17:09

elements. Because if we compare it to

1:17:11

the finished design, you can see that

1:17:13

the input field is meant to be wider

1:17:15

than the logo. However, in our example,

1:17:18

that's not the case. Quite the opposite

1:17:20

actually. The logo is much wider than

1:17:22

the input field. So, we need to shrink

1:17:24

the logo and then make the input field

1:17:27

wider. So, I'm going to start and do one

1:17:29

of these and then you will do the other.

1:17:32

I happen to know that the width we want

1:17:34

to have on this input field is 400

1:17:36

pixels. What I'm then going to do is

1:17:39

target the input field using the element

1:17:42

name and create a CSS selector just

1:17:45

writing input then open and close curly

1:17:48

bracket. Then simply write with and 400

1:17:52

px and boom there you can see suddenly

1:17:55

the input field widened quite a lot. And

1:17:58

as you might have noticed, we're using

1:17:59

this pixels value here again, which

1:18:01

we've used a couple times already,

1:18:03

actually. And if you're a little bit

1:18:04

confused as to what a pixel is, you can

1:18:07

think of it as the smallest unit of

1:18:09

space that our screens can render. So a

1:18:12

pixel is just a tiny square. So tiny

1:18:15

that we actually need 400 of them

1:18:18

stacked up besides each other in order

1:18:20

to get a width of this size. So with

1:18:23

that, I want you to fix the width of the

1:18:26

Google logo. Select the image tag and

1:18:29

set the width of the logo to 300 pixels.

1:18:33

Go ahead and do that right now and then

1:18:35

I will show you how to do it as well

1:18:37

when you return back to this scrim.

1:18:45

Okay, let's do this. I'm going to break

1:18:48

this down into a few lines so I get some

1:18:50

space above the input field and then

1:18:52

target the img element, the image

1:18:54

element. open up the curly brackets and

1:18:57

do with 300 pixels. Like that. Oo, we're

1:19:01

not quite yet at the finished design,

1:19:04

but the ratio between the logo and the

1:19:06

input field is now a lot better. Great

1:19:09

job. Let's move on.

1:19:13

Okay, I've discovered a problem with our

1:19:15

Google site, which is that if we make

1:19:17

the browser really wide, you can see

1:19:19

that suddenly the items stack up besides

1:19:22

each other on the same line. And that's

1:19:24

obviously not the kind of behavior we

1:19:26

want. We want them to always be stacked

1:19:29

on top of each other. And in order to

1:19:31

fix this, you have to learn about inline

1:19:33

elements versus block elements. And

1:19:35

that's best understood through the lens

1:19:37

of an example. So let's say that you,

1:19:39

for example, have a collection of things

1:19:41

you want to showcase. You could be like

1:19:43

George Francen, for example, and collect

1:19:45

dinosaur poo. He actually has the

1:19:47

world's largest collection of fossilized

1:19:49

feces, and naturally, he wants to

1:19:51

exhibit them in a museum. And if he were

1:19:54

to use display inline on his images,

1:19:58

they would stack up besides each other

1:20:00

like this. So kind of like in a line

1:20:02

horizontally. However, had he used

1:20:05

display block on his images, then they

1:20:07

would stack up on top of each other. So

1:20:10

rule of thumb is display block stacks on

1:20:13

top. Another way to look at this is that

1:20:15

the block level element blocks out the

1:20:18

rest of the available horizontal space

1:20:20

so that nothing else can be placed

1:20:22

there. And that is regardless of how

1:20:23

wide this image is, the content itself,

1:20:26

display block requires control over all

1:20:28

the horizontal space in its given

1:20:30

container. So when this block image is

1:20:33

placed here and you add a new image, it

1:20:35

would have to be placed underneath the

1:20:37

previous one. And if it is display block

1:20:39

as well, it'll block out the rest of the

1:20:41

available horizontal space and the next

1:20:43

image have to be placed below that one

1:20:45

again and so on. So the solution is

1:20:48

obviously to turn these elements into

1:20:50

blocks and I'm just going to give you

1:20:52

the syntax here. This is how you write

1:20:54

it. Display colon block. Go ahead and do

1:20:57

that for both of these and observe what

1:20:59

happens to the example when you make the

1:21:01

browser wide. Good luck.

1:21:05

Okay, let's do this. So I'll do display

1:21:10

block up here and the same

1:21:13

here. If we look at the browser,

1:21:15

seemingly nothing has happened. However,

1:21:17

if we now make it wide, you can see yes,

1:21:20

no matter how wide the browser is, these

1:21:22

will always stack up on top of each

1:21:24

other. So, great job. Let's move on.

1:21:30

The next thing we need to fix is the

1:21:32

lack of white space above our Google

1:21:34

logo. Because if we take a look at the

1:21:35

design here, we want quite a lot of

1:21:37

space in between the top of the browser

1:21:39

and the logo. And I'm not going to tell

1:21:41

you how to add that, but if you can

1:21:44

think back to the very first scrim in

1:21:46

this section, we added some space above

1:21:48

the text in our cookie widget. And that

1:21:51

specific space is called margin or

1:21:53

margin top to be specific. So your job

1:21:56

is to add some margin on top of our

1:21:58

image right here. You can start on line

1:22:00

seven so that our example here gets some

1:22:02

breathing room, some white space above

1:22:05

the logo and the input field. go ahead

1:22:07

and give this one a shot and then I will

1:22:09

of course show you the solution when you

1:22:10

return back to me.

1:22:16

Okay, hopefully that went well. If not,

1:22:18

no worries. I really pushed you out on

1:22:20

thin ice here. So, it's completely okay

1:22:22

if you didn't remember that the property

1:22:24

is called margin top. And what you add

1:22:27

there is a pixel value. So, for example,

1:22:30

100 px. And there we go. We've now added

1:22:33

a margin on the top of our image. And

1:22:37

while we're still quite far off from our

1:22:38

provided design here, we are getting

1:22:40

closer. Great job. Let's move on.

1:22:46

Now, while it totally works to add the

1:22:48

margin top directly on the image here,

1:22:51

you'd most likely not see professional

1:22:53

developers do this because what they do

1:22:55

instead is wrap these two elements in

1:22:58

some kind of container and then control

1:23:00

the positioning of these elements

1:23:02

indirectly via that container. And in

1:23:05

order to do this, you have to learn

1:23:06

about the div. I'm going to create an

1:23:08

opening div and then indent these two

1:23:11

and then a closing div below here. Now,

1:23:14

if we run this code, seemingly nothing

1:23:16

has happened because the div actually

1:23:18

does very little in itself. Though it is

1:23:21

indispensable for web developers. Just

1:23:23

to show you how important it is, let's

1:23:26

take a look at Facebook and my timeline.

1:23:28

Here I've opened up dev tools and

1:23:30

inspected one of the timeline items. And

1:23:33

you can see it is actually a div inside

1:23:35

of a div inside of another div inside of

1:23:37

yet another div inside of a div inside

1:23:39

of a div.

1:23:42

Divs really do rule the world. So it's

1:23:45

important that you learn about them. And

1:23:47

the way we'll use this div now is by

1:23:49

removing the margin top styling from the

1:23:52

image and then add it to the div itself.

1:23:55

And the reason this is important is

1:23:57

let's say that for example Google

1:23:59

decides to create a video here instead

1:24:01

or a interactive doodle or some kind of

1:24:03

game. They often play around with the

1:24:05

Google logo. Well, if so, it's a really

1:24:07

bad idea that it is the image itself

1:24:10

that controls the margin from the top of

1:24:13

the browser and down to the content

1:24:15

because that image might be removed. So,

1:24:17

it is a solution that will get you into

1:24:19

trouble in the future. So what we'll do

1:24:21

here is we'll simply instead target the

1:24:24

div and then remove the margin top from

1:24:28

the image and boom it has popped up. Now

1:24:30

we lost all of our white space but if we

1:24:32

add it back to our div we are back at

1:24:35

the design we started out with seemingly

1:24:37

nothing has changed but as you know we

1:24:40

have a better HTML structure. So we have

1:24:43

definitely made good progress here. So

1:24:45

with that, let's move on to the next

1:24:47

scrim.

1:24:50

The reason you need to learn about

1:24:52

classes now is because our current setup

1:24:55

where we simply have the elements like

1:24:56

this and then selecting the element

1:24:59

using the element selector in CSS will

1:25:02

give us bugs down the line because when

1:25:04

we add the two buttons beneath the input

1:25:07

field, we'll actually wrap these two in

1:25:10

a div as well. And let's see what

1:25:12

happens at this point. What I'll do now

1:25:14

is simply add the HTML for these buttons

1:25:18

down here beneath the input field. So it

1:25:21

is a div with two buttons inside of it.

1:25:24

And then you can see we are closing that

1:25:26

div, the inner div, and then we are

1:25:29

closing the outer div. Let's run this

1:25:32

code. And oh wow, what you can see is

1:25:34

that the spacing between the input field

1:25:36

and the buttons is totally off. And that

1:25:39

is because our CSS element selector here

1:25:42

selects any div it can find in the HTML

1:25:45

document and applies the margin top to

1:25:47

it. So it doesn't just select the first

1:25:49

one, but it can select thousands of

1:25:52

divs. So this is a very generic solution

1:25:54

and likely not something we want to use

1:25:56

as we want to have multiple divs with

1:25:58

different types of styling in our HTML

1:26:01

element. So let's now instead fix this

1:26:05

by doing the following. I'll write class

1:26:08

equals then for example main this here

1:26:11

is an attribute called class so it's

1:26:14

built into HTML and this here is the

1:26:16

name I'm giving my class I want to call

1:26:19

this div my main element and now the way

1:26:23

I select that in the CSS is by instead

1:26:26

of just writing the element name simply

1:26:28

doing dot main like that now if I rerun

1:26:32

this code you can see now the margin top

1:26:35

is only applied to the outer div, our

1:26:37

main class, and not to the div which

1:26:40

wraps the two buttons. So that is

1:26:43

exactly what we needed. Now I'm going to

1:26:46

remove these two buttons here because we

1:26:48

don't want to deal with them just yet.

1:26:50

And then I'm going to give you a

1:26:51

challenge.

1:26:53

First, you're going to add a class to

1:26:55

each of these two elements. That is the

1:26:57

image and the input. You have to decide

1:27:00

what you will call the two classes, but

1:27:02

make sure to give them different names.

1:27:04

And then you're going to in the CSS

1:27:08

replace the element selectors with class

1:27:11

selectors. So that is the img selector

1:27:13

here and the input selector here. And

1:27:15

obviously the CSS class selectors you're

1:27:18

going to replace them with is the ones

1:27:20

you have added to the elements right

1:27:21

here. So go ahead and do this right now.

1:27:31

Okay. Hopefully that went well. Let's

1:27:34

now do it together. So for the image

1:27:36

tag, I'm simply going to do class

1:27:39

equals. Then I'll call this logo dash

1:27:43

img. So here I'm using a convention

1:27:46

where I'm first giving my class a

1:27:48

descriptive name and then using a dash

1:27:50

and then specifying the element as well.

1:27:53

This is an img element, but it could

1:27:55

have been for example an SVG or

1:27:57

something else. Now I don't expect you

1:28:00

to have followed the same convention.

1:28:01

There are plenty of CSS conventions and

1:28:03

it doesn't matter at all what you used

1:28:05

in your example. You can call your

1:28:07

classes whatever you want. Okay, for the

1:28:10

input we'll do class equals search dash

1:28:14

input like that. Okay, let's move

1:28:16

through the CSS. Then I'll replace this

1:28:19

with dot. Now you can see it broke the

1:28:21

layout because this styling now is not

1:28:23

applied to any element. So we need to do

1:28:26

logo-ash img like that. And here do dot

1:28:31

search dash input. And there we have the

1:28:35

exact same example. Didn't change at

1:28:37

all, but we now have a more flexible

1:28:39

solution that scales better. So great

1:28:42

job solving this challenge. Let's move

1:28:44

on.

1:28:47

Okay, now it's time to take a closer

1:28:49

look at margins. And you've already

1:28:52

dipped your toes into this as you have

1:28:54

used margin top. So, you might have some

1:28:57

intuition about what margins do.

1:28:59

However, now you're going to learn it

1:29:01

properly through creating flags with CSS

1:29:05

because flags are just awesome. I mean,

1:29:08

take a look at this flag here, for

1:29:09

example, from the Republic of Venice, a

1:29:11

state which existed for over a thousand

1:29:13

years in Europe. And it contains, of

1:29:16

course, a flying lion holding a book. I

1:29:19

mean, what's more natural than that? Or

1:29:22

this one right here for the aisle of

1:29:24

man. I mean, have you ever seen a more

1:29:27

creepy creature than this three-legged

1:29:29

thing right here? Imagine having that

1:29:32

thing running after you?

1:29:34

That would not be fun. And this flag

1:29:37

would be really hard to create in CSS,

1:29:39

actually. So, we're not going to create

1:29:40

this one. We're going to start off at a

1:29:42

much easier level with just some very

1:29:44

simple shapes. So, let's have a look at

1:29:46

those. Actually, here is what we're

1:29:49

going to work with. As you can see,

1:29:50

there are simply three divs inside of

1:29:53

the body tag. And each div has a class

1:29:55

red, blue or green. If we check out the

1:29:58

styles.css, you can see that these three

1:30:01

classes apply a background color to each

1:30:03

of the elements and sets the height to

1:30:05

100 pixels. And here we have the result.

1:30:08

Three rectangular boxes that are stacked

1:30:10

on top of each other. And that tells us

1:30:12

that these are display block because

1:30:15

display block stacks on top. There's one

1:30:18

thing that bothers me here, and that is

1:30:19

that we have a little bit of white space

1:30:22

around the three items. Why is that?

1:30:25

Well, actually, it's because our browser

1:30:27

is trying to help us here. It's assuming

1:30:30

that we want a little bit of space

1:30:32

around the body tag so that these three

1:30:36

don't touch the edges of the browser. So

1:30:38

what's actually going on here in code is

1:30:41

that the browser

1:30:43

targets the body and sets a margin of 8

1:30:47

pixels. If you notice when I added this,

1:30:50

nothing changed. So if I remove this,

1:30:53

it's still the same. Meaning that this

1:30:55

style here is applied automatically. So

1:30:57

that means that margin is actually the

1:31:00

space around an element because now if

1:31:03

we change this to zero, boom, there you

1:31:06

can see suddenly our divs touch the

1:31:08

edges of the browser. Now here at the

1:31:12

bottom, they stop after 300 pixels since

1:31:14

we've told them to. So this margin zero

1:31:17

here seemingly didn't change anything at

1:31:19

the bottom because the bottom contains

1:31:21

white space anyway if we make our

1:31:22

browser tall enough. But anyway, that's

1:31:25

a digression. Let's get it back so that

1:31:27

the browser is completely filled up with

1:31:29

these three items. And now let's play a

1:31:31

little bit around with margins. So what

1:31:33

do you think will happen if I add a

1:31:35

margin top of 10 pixels on the red hair?

1:31:38

Take a guess.

1:31:42

Okay. Margin top 10 pixels. Boom. It

1:31:46

added 10 pixels on the top. What do you

1:31:48

think will happen if I add margin left

1:31:51

10 pixels as well? Let's try it.

1:31:55

Okay, so it added 10 pixels on the left

1:31:59

hand side, but it's only on the red

1:32:02

rectangle, not the blue or green

1:32:04

rectangle. Likewise, if I do margin

1:32:07

width 10 pixels, it adds 10 pixels to

1:32:10

the right hand side as well. If I do

1:32:13

100, it eats up almost a third of our

1:32:16

red rectangle. Okay, so now it's your

1:32:18

turn.

1:32:20

I want you to add 100 pixels of margin

1:32:24

on the bottom of the red box. So, go

1:32:26

ahead and give that a shot right now.

1:32:32

Okay, if you did margin bottom 100 px

1:32:37

like that, I want to congratulate you

1:32:40

because you just created the flag of

1:32:42

Monaco. Really good job creating your

1:32:44

first CSS flag. And now, let's do that

1:32:47

yet again. Here is your challenge. You

1:32:50

are going to create the flag of the

1:32:52

Gambia. And here we have that flag.

1:32:55

However, there's a catch. You can only

1:32:57

do this by applying styles to the blue

1:32:59

box. So, by adding margin to this CSS

1:33:02

rule right here. So, go ahead and give

1:33:04

that a shot right now.

1:33:10

Okay. Hopefully that went well. The way

1:33:13

to do it is by doing margin top. Let's

1:33:16

try 10 pixels and see. Actually, I think

1:33:19

we want our white space to be a little

1:33:21

bit more than 10 pixels. So, let's do 20

1:33:23

like that. And then margin bottom as

1:33:27

well. 20 pixels. And there. I think we

1:33:31

have a pretty good flag for the Gambia.

1:33:35

Now, before we move on to our Google

1:33:36

project, there's one little weird thing

1:33:39

I want to tell you about margin top and

1:33:41

bottom. Because what do you think

1:33:43

happens if I add for example margin

1:33:45

bottom of 15 to this red element here?

1:33:48

Well, according to my logic, the margin

1:33:50

right here would be 35 pixels because we

1:33:53

added 20 pixels on top of the blue. And

1:33:55

if we add 15 at the bottom of the red

1:33:57

one, that should be 35 pixels in total.

1:34:02

However, now that I added this, nothing

1:34:05

happened. And that is because margin top

1:34:07

and margin bottom will in many

1:34:09

situations collapse into each other. So

1:34:12

that as long as this margin is smaller

1:34:14

than this, this will take precedence.

1:34:16

And it's only when this one becomes

1:34:18

larger, for example, 25, that it will

1:34:21

kick in. So let's take it back to 15.

1:34:23

And to make things even worse, there's

1:34:25

actually scenarios where this doesn't

1:34:27

happen. However, digging into that is

1:34:29

outside of the scope of this lecture. I

1:34:31

just want you to be aware of it because

1:34:33

if you're suddenly in a situation where

1:34:34

your margins don't seem to add up, it is

1:34:37

probably because of so-called collapsing

1:34:39

margins. Okay, with that, let's move on.

1:34:44

Okay, we're back at our Google project.

1:34:47

I want to give you a quick challenge. I

1:34:49

want you to add some space between the

1:34:51

logo and the search field because as you

1:34:53

can see here, there's some spacing in

1:34:55

between the elements in our design.

1:34:57

However, in our project now, they are

1:34:59

crammed together. There are two ways you

1:35:02

can do this using margins and I want you

1:35:04

to think about which two ways that is

1:35:06

and choose one of them. Go ahead and do

1:35:08

this right now.

1:35:14

Okay, hopefully that went well. Let's do

1:35:16

it. So, you can either add a margin

1:35:19

bottom to the logo or you can add a

1:35:22

margin top to the search field. I'm

1:35:25

going to go with adding margin bottom to

1:35:27

the logo as I think either way is as

1:35:28

good as the other at this stage. Margin

1:35:31

bottom. And how much do we want to add?

1:35:33

Well, let's try 20 px. And yeah, as you

1:35:36

can see, we've got some spacing. The

1:35:38

bottom of the G is not touching the top

1:35:40

of the input field. And if we compare

1:35:42

that to the example, I think it looks

1:35:44

more or less the same. So, great job.

1:35:47

Let's move on.

1:35:51

Okay. Now you are going to learn about

1:35:53

centering elements in CSS and that is a

1:35:56

scary topic for a lot of developers. So

1:35:59

scary that this stack overflow question

1:36:02

about how to horizontally center an

1:36:04

element has been viewed 4.5 million

1:36:07

times. So if you think this is a little

1:36:09

bit confusing, you are in very good

1:36:12

company. So don't worry about it. So

1:36:15

with that in mind, let's move over to

1:36:17

our example. You are going to center

1:36:20

this dinosaur poo. As you can see in the

1:36:23

CSS, it has just one property set at

1:36:26

this point which is a width of 200

1:36:28

pixels. That is because the image is so

1:36:30

wide originally that if I don't set that

1:36:32

width, it'll just take up more space

1:36:34

than we have available. And setting the

1:36:37

width of it is actually an important

1:36:38

thing in order to center it because

1:36:40

there are three things that need to be

1:36:43

in place when we are to center elements

1:36:46

with the technique you are about to

1:36:47

learn aka centering with margins. And

1:36:50

these three components are first the

1:36:52

element needs to be display blocked

1:36:54

because how is an element supposed to

1:36:56

center itself if it doesn't command full

1:36:59

control over all the horizontal space.

1:37:02

If it's display inline and allows other

1:37:04

elements to stack themselves besides the

1:37:07

element, well then it won't be able to

1:37:09

center itself because that space now is

1:37:11

busy with other things. So in order to

1:37:14

center this poo, it needs to control all

1:37:17

the horizontal space.

1:37:19

So it needs this

1:37:22

block like that. Now that didn't change

1:37:25

anything, but under the hood, the poo

1:37:27

now controls the full horizontal space.

1:37:30

Okay, the second part is that it must

1:37:32

have a width

1:37:34

and that is what we've done here already

1:37:37

because how is this item supposed to be

1:37:40

centered inside the browser if it is

1:37:41

wider than the browser itself? That's

1:37:44

often what happens with either large

1:37:46

elements or with some HTML elements who

1:37:48

just naturally actually expand to take

1:37:51

up all the available space in the block.

1:37:53

So we have to make sure that our element

1:37:55

has a width. And finally we set the

1:37:58

margin on the left hand side and the

1:38:00

right hand side to the value auto. Let's

1:38:03

just do that. Margin left auto. Oh wow.

1:38:09

Now it pushed the pool all the way to

1:38:12

the right hand side because auto here

1:38:14

means take up all the available space.

1:38:17

And since this is a block element, the

1:38:20

available space is all the space that's

1:38:22

left after the pooh has taken up its 200

1:38:25

pixels. So it just ate up all of the

1:38:27

space and turned it into margin.

1:38:30

However, at this point, margin right

1:38:32

enters the party. Margin right and says

1:38:35

I want the available space as well. And

1:38:37

at that point, the margin left and

1:38:39

margin right goes into discussion and

1:38:41

decides, well, actually, since there are

1:38:43

two of us here pushing on each of the

1:38:45

side of the element, trying to get all

1:38:47

of the available white space, let's just

1:38:49

divide it evenly amongst both of us. And

1:38:52

the result, well, it is that the item is

1:38:55

centered. So, that was a long

1:38:57

explanation of centering with margins.

1:39:00

If you feel confused, don't worry about

1:39:02

it right now. All you need to do is

1:39:03

remember these three conditions and just

1:39:06

be aware of the 4.5 million other

1:39:09

developers who are in or have been in

1:39:11

the same boat as you. Let's move on to

1:39:13

the next scrim.

1:39:17

Okay, we are back at our Google project.

1:39:20

Now your challenge is to center the logo

1:39:23

and the search field using the technique

1:39:25

you just learned. So go ahead and give

1:39:27

that a shot right now and then I will of

1:39:29

course show you the solution afterwards

1:39:31

as well.

1:39:37

Okay, as you hopefully remembered, the

1:39:39

way to center an element which is

1:39:41

display block and has a width is by

1:39:44

adding margin left auto and margin right

1:39:46

auto. So let's do that. Margin

1:39:49

left auto. And as you can see, that

1:39:52

pushes the logo all the way to the right

1:39:54

hand side because the margin left is set

1:39:56

to auto and it takes up as much space as

1:39:58

it can. We do the same thing with the

1:40:00

right hand side. Do margin right auto.

1:40:05

Then the right hand side starts pushing

1:40:07

back again. And when they're both taking

1:40:09

up equally as much space, the margin

1:40:11

left and margin right kind of decides,

1:40:13

yeah, let's not argue anymore. Now we

1:40:15

have a nice balance. And woo, lo and

1:40:17

behold, our element is centered. So now

1:40:21

what we can do is be super lazy and copy

1:40:23

that code and paste it in down here. And

1:40:26

boom, our input field is centered as

1:40:29

well. And our project is starting to

1:40:31

look a little bit like our finished

1:40:32

design. So this is super cool. Let's

1:40:35

just keep up the pace and move on.

1:40:40

we need to take a little step back and

1:40:42

learn a new CSS concept which is the

1:40:46

close relative of margins called

1:40:48

padding. And we're of course going to

1:40:51

learn that through the lens of an

1:40:53

example. So here I have just a simple

1:40:56

div which contains a little bit of text

1:40:59

or specifically the two first sentences

1:41:01

in the white paper behind Bitcoin. And

1:41:04

let's say we want to turn this into a

1:41:06

nice looking card that people can read.

1:41:09

If so, we'd probably create a class call

1:41:11

it card. Then of course in the style

1:41:13

CSS, we'd select that card and apply the

1:41:16

styling. As for now, it just has one

1:41:18

property set, which is the color that

1:41:20

we've set to a shade of black that isn't

1:41:22

pure black, but a little bit softer, so

1:41:25

to speak. That is because by default,

1:41:27

the browser uses pure black as the text

1:41:30

color and pure white as the background

1:41:33

color. And as a rule of thumb, you never

1:41:35

want to have pure black on pure white.

1:41:38

That's not a pleasant experience for the

1:41:40

eyes. So instead, we went for this. But

1:41:43

that was a digression. Let's move on

1:41:44

with turning this into a nicel looking

1:41:47

card. So a card needs a background

1:41:49

color. So let's just do background light

1:41:53

gray for example, like that. And we also

1:41:55

don't want our card to be full width

1:41:57

because as you remember divs are block

1:41:59

by default and take up the full width if

1:42:02

you don't specify any width on it. So

1:42:04

we're going to do width for example 300

1:42:06

pixels like that. And then we also want

1:42:09

some space above the card. That is of

1:42:11

course margin top. Let's push it 50

1:42:14

pixels down from the top. And finally it

1:42:17

should be centered. So, let's do margin

1:42:20

left, auto, and margin right like that.

1:42:24

Okay. So, now we have something that

1:42:26

looks at least a little bit like a card.

1:42:28

But there's one problem here. You can

1:42:30

see the text is crammed all the way into

1:42:32

the edges of the div, which doesn't look

1:42:35

particularly good. And that is where

1:42:37

padding comes into play. So now I'm just

1:42:40

going to apply the padding by doing

1:42:42

padding and for example 20 pixels like

1:42:45

that. And as you can see, that created a

1:42:48

little bit of space. Basically, some

1:42:50

breathing room in between the text and

1:42:52

the edge of our div container here. And

1:42:55

if I do 50, you can see it's even more

1:42:58

breathing room. So, where's margin adds

1:43:01

space on the outside of our div, the

1:43:04

card which we've selected here, padding

1:43:07

will add space on the inside in between

1:43:10

the content and the edges of the

1:43:12

container or the div. So margin kind of

1:43:16

lives up here and down here if we are to

1:43:21

visualize this in our HTML whereas

1:43:23

padding lives on the inside of our

1:43:25

element that is here and here.

1:43:30

And now you might wonder well why did I

1:43:32

just write padding whereas for margin

1:43:34

we're specifying each of the sides. And

1:43:36

well you can do exactly that on padding

1:43:38

as well. this padding 20 pixels right

1:43:40

here is the exact same thing as writing

1:43:42

the following padding top 20, bottom 20,

1:43:46

left 20, and right 20. So with these

1:43:49

four lines, we can actually delete this

1:43:51

one up here. And then we have the same

1:43:54

convention as we're using with margins.

1:43:56

It's just that you can use padding 20

1:43:59

pixels like that if all of the values

1:44:01

are the same. It's basically a shortand.

1:44:04

And now that we have all of them written

1:44:06

out, we can play around a little bit

1:44:08

with it. perhaps add a 100 pixels on the

1:44:11

left hand side looks really weird and

1:44:13

100 pixels on the top as well. And

1:44:15

suddenly our card does not look very

1:44:17

good. But let's get it back. And now I

1:44:20

want to give you a challenge. I want you

1:44:22

to add padding to make our card look

1:44:25

like the provided design. And the

1:44:28

provided design is right here. You can

1:44:30

see it's a completely broken card as

1:44:33

we've been ruthless about our padding.

1:44:35

And I've actually removed all of the

1:44:36

padding rules from the CSS as I want you

1:44:38

to build some muscle memory writing

1:44:40

padding. So go ahead and make this card

1:44:43

look like it does in the slide. And then

1:44:45

return back to me once you've done it.

1:44:51

Okay, hopefully that went well. If not,

1:44:54

no worries. Let's do it together. As you

1:44:57

can see here, it's completely crammed

1:44:59

into the bottom left corner, which means

1:45:02

that it doesn't have any padding on the

1:45:04

left hand side or any padding on the

1:45:06

bottom, but a ton of padding on the top

1:45:09

and a ton of padding on the right. So,

1:45:12

I'm just going to do padding top 100

1:45:15

pixels, something like that. Yeah, seems

1:45:20

pretty much what we have in the design

1:45:22

as well. And then do the same padding

1:45:25

right 100 pixels like that. And to me

1:45:29

that looks actually pretty much like our

1:45:31

design. I don't need to write padding

1:45:34

bottom or padding left now. Though I

1:45:36

could do it. I could do padding bottom

1:45:39

zero pixels or just zero and padding

1:45:43

left zero as well. Though that didn't

1:45:47

change anything. So it's actually not

1:45:50

needed because by default the padding of

1:45:52

a div is zero. So however you solved

1:45:56

this, great job. Let's move on.

1:46:01

So now you've learned about controlling

1:46:03

the space on the outside of the element

1:46:06

with the margin and on the inside of the

1:46:08

element with the padding. But wouldn't

1:46:10

it be nice if we could also control the

1:46:12

border in between the margin and the

1:46:15

padding? And it turns out we can through

1:46:18

you guessed it the border property cuz

1:46:21

if I write border here and then specify

1:46:24

for example two pixels thickness solid

1:46:28

in shape and then color red you can see

1:46:32

then we get a border which is on the

1:46:34

outside of the padding but on the inside

1:46:36

of the margin. And if we change any of

1:46:39

these three values here it'll update

1:46:41

accordingly. So let's try 8 pixels width

1:46:44

instead. You can see it's much thicker

1:46:46

now. Instead of solid, we can do a like

1:46:49

that. Pretty weird. And instead of red,

1:46:52

we can do, for example, fff white in

1:46:56

hexodimal or just write white like that

1:47:00

or just blue so it's a little bit

1:47:02

clearer. Now, there are many types of

1:47:04

borders, but in 99.9% of the cases, you

1:47:08

want to use solid like that. And also,

1:47:11

very often, you'd want to soften up

1:47:13

these corners.

1:47:15

And you can do that with the border

1:47:18

radius property. And here you specify a

1:47:20

pixel value, for example, 30 pixels. And

1:47:23

boom, there you can see we have this

1:47:25

much softer corners. If we crank this up

1:47:28

to 100 or a,000, it stops at some point

1:47:31

because then the edges have simply

1:47:33

turned into half circles. So at some

1:47:35

point, there's no use going any higher.

1:47:38

Now, this looks pretty bad. So, what I

1:47:41

want you to do now is fix it up so that

1:47:43

it looks like this. And I'm not going to

1:47:46

give you any of the values I've used

1:47:48

here. Just a little hint. I took an

1:47:50

already existing color in our box and

1:47:52

used it for the border. That's a common

1:47:54

web design trick to reuse colors and not

1:47:57

have too many different colors. So, if

1:47:59

you think this is pure black, mm- you

1:48:01

are wrong. So, go ahead and change the

1:48:04

values of the border and border radius

1:48:07

so that our example here matches the

1:48:09

design. I've provided in the slide. Good

1:48:12

luck.

1:48:17

Okay. Hopefully that went well. So,

1:48:20

let's start with the border. 8 pixels

1:48:22

here. Looks a bit too thick for me. So,

1:48:24

let's try four instead. Like that. I

1:48:29

think that matches better. Yes.

1:48:32

And the color I gave you a hint was just

1:48:35

the blackish color we have for our text.

1:48:38

Like that. And the border radius is much

1:48:41

smaller. Let's try 10.

1:48:44

It's This still looks a little bit

1:48:46

rounder. So, let's try 20. Yes, there. I

1:48:50

think we got it. Great job. Now, a cool

1:48:54

thing to do in order to inspect the

1:48:56

margin, border, padding, and size of the

1:48:59

element in general is to open up the dev

1:49:03

tools, which can be done by

1:49:04

right-clicking on the navbar here and

1:49:07

then clicking inspect and then this dev

1:49:09

tools panel will open here, clicking on

1:49:12

the select icon on the left hand side

1:49:15

and then hovering over the element.

1:49:18

Finally clicking at it. There you will

1:49:20

see that we have selected the element in

1:49:23

the elements tab and under the styles

1:49:25

tab you can see the styling we have

1:49:27

applied using CSS. So here you can

1:49:30

actually modify them if you want but

1:49:32

we're not going to do that right now.

1:49:33

We're going to scroll down and verify

1:49:36

that our margin border and padding are

1:49:38

correct. So if I hover over the margin

1:49:40

here you can see up here in the mini

1:49:41

browser it is marked in orange and the

1:49:44

values are provided down in the box

1:49:46

here. If I move over to the border, we

1:49:48

can see that border is now selected in

1:49:50

the browser and it is indeed four pixels

1:49:52

as we coded up a minute ago. If I move

1:49:54

over to the padding, you can see that is

1:49:56

also indeed 20 on each side, just as we

1:49:58

want it to be. And finally, if I hover

1:50:00

over the center here, the content is

1:50:02

highlighted. And the content of this div

1:50:04

is just the text. And as you can see, it

1:50:06

is 300 pixels wide, just as we set it

1:50:09

as. So, it's working as expected. And

1:50:12

the height is dictated by how many lines

1:50:14

of text are two sentences required. So

1:50:18

using this technique of inspecting an

1:50:20

element and its sizing properties like

1:50:22

this is a really good way of debugging

1:50:24

if something for example looks wrong

1:50:26

because it gives you an ability to

1:50:28

verify if the numbers here match up with

1:50:30

what you've tried to write in your CSS.

1:50:33

So now that you've learned all of that,

1:50:34

I want to tell you the name of this and

1:50:36

it's actually called the box model. And

1:50:38

to be honest, I've never really liked

1:50:40

this word. It sounds more complex than

1:50:43

it is in my opinion. It's just spacing

1:50:45

around the element, a border, spacing on

1:50:47

the inside of an element and the content

1:50:49

itself, but in web development, we call

1:50:51

this the box model. So, you'll probably

1:50:53

hear this name come up from time to

1:50:55

time, but you shouldn't fear it. You

1:50:57

know exactly what it is, and you've used

1:50:59

all of the properties in the box model.

1:51:01

So, don't worry about it. Actually,

1:51:02

let's give you a new box model practice

1:51:04

in the next scrim. I'll see you there.

1:51:10

Okay. And now you are going to create a

1:51:12

really neat looking button, namely the

1:51:15

following button on Twitter. Let's zoom

1:51:17

in a little bit. And here you can see

1:51:18

it. This is the button you see if you

1:51:20

already are following someone. And we

1:51:21

zoom out again. This is the Scribba

1:51:24

Twitter profile. You should definitely

1:51:25

just click this image and follow us

1:51:28

because we share a ton of useful tips

1:51:30

and tricks and career advice for

1:51:32

aspiring coders here. So, it's

1:51:34

definitely worthwhile. Anyway, now you

1:51:36

are going to use the things you've

1:51:38

learned about padding, border, border

1:51:41

radius, and so forth in order to make

1:51:43

this button right here with the ugly

1:51:46

default styling look exactly like this.

1:51:50

Or not exactly, as we're not going to

1:51:52

worry about the font. It is a little bit

1:51:54

different, but other than that, you

1:51:56

should try to make it look identical.

1:51:58

I've given you some hints here. For

1:52:00

example, the border color is this hex

1:52:02

color right here. And the text color is

1:52:03

this one right here. And also, you need

1:52:05

to remember to adjust the font weight.

1:52:08

And I don't think you've done that ever

1:52:10

since the very first scrim where you

1:52:12

wrote your first lines of CSS. So, you

1:52:14

might have to look back so that you

1:52:16

figure out how to adjust the font

1:52:18

weight. Or you can Google it. Up to you.

1:52:21

Anyway, just go ahead and give this your

1:52:23

best shot. And if you at some point get

1:52:25

stuck or don't know how to do it, no

1:52:27

worries. We are going to do it together

1:52:29

afterwards as well. Good luck.

1:52:36

Okay, hopefully that went well. Let's do

1:52:39

it together. I'm going to target the

1:52:41

button just using an element selector

1:52:43

like this. And now let's pick the

1:52:45

lowhanging fruit, namely the ones we've

1:52:47

gotten here already. For example, by

1:52:49

doing color and then copying this color

1:52:53

right here. Okay, that didn't change

1:52:55

much, at least not visibly. Then let's

1:52:57

do border. And I'm going to start with

1:53:00

one pixel solid. And then the border

1:53:03

color right here. Like that. Okay. So it

1:53:07

looks a little bit different now, but

1:53:09

not quite this. One thing we can clearly

1:53:12

see is that this image has a white

1:53:14

background whereas ours is still a

1:53:16

little bit gray. So let's do that as

1:53:18

well. Background white. Okay. Yes. But

1:53:23

our button is much more crammed. There's

1:53:24

too little padding. Whereas here you can

1:53:27

see we have a little bit of padding on

1:53:29

the top and the bottom and actually

1:53:30

quite a lot of padding on the left and

1:53:32

right hand side. And that's actually a

1:53:35

little design tip right there. What

1:53:36

you'll often see is that buttons have

1:53:38

more padding on the left hand side and

1:53:40

the right hand side and they have above

1:53:42

and below. So let's try padding top five

1:53:47

pixels for example. Padding bottom five

1:53:51

pixels. And then we'll try left 10

1:53:55

pixels. and right 10 pixels as well. How

1:53:59

does that look? Not too bad. But

1:54:02

actually, it looks like this button has

1:54:04

even more. So, we've added half as much

1:54:07

on the top and bottom as we have on the

1:54:08

sides. So, let's crank up both of these

1:54:11

a little bit. I'm going to select both

1:54:13

of these and do eight top and below. And

1:54:15

select both of these and do 16 left and

1:54:18

right. Yeah, I think that's more like

1:54:20

it. Now, one thing that definitely is

1:54:22

remaining is the rounded edges here. So

1:54:25

that is the border radius and add it up

1:54:28

here with the border. Let's try 10

1:54:30

pixels. It's a little bit round now, but

1:54:32

not as round as the Twitter button. So

1:54:35

let's do 16. Yeah, more like it. Can we

1:54:40

go higher? Yeah, I think we can go to

1:54:42

18. That looks quite good to me if we

1:54:45

compare to this one. And then finally,

1:54:47

we needed to remember the font weight,

1:54:49

which I can do font weight

1:54:52

bold like that. That looks a lot better.

1:54:57

I think the final adjustment I want to

1:54:59

make is adding even a little bit more

1:55:01

padding around it because now that I

1:55:03

look at it, it feels like this is a bit

1:55:05

more spacious. So, here we are really in

1:55:08

the nitpicking area. But let's try 10 on

1:55:11

both of the top and bottom. And let's

1:55:14

try 20 on the left and right. And what's

1:55:16

interesting now is that since the box

1:55:18

now has grown in size because it's

1:55:20

affected by the padding, the border

1:55:22

radius can also be cranked up a little

1:55:24

bit. I think actually we can do 20 now.

1:55:27

Yes, because the bigger a box is, the

1:55:30

more pixels you need to add in order to

1:55:32

get this fully soft looking button which

1:55:34

essentially has two half circles on each

1:55:36

of its sides. So looking at the example

1:55:40

and comparing it with ours, I think we

1:55:41

have reached our goal. And if your

1:55:44

values are different than mine, that

1:55:46

does not matter at all. You're actually

1:55:48

creating the button of a huge public

1:55:50

company here. You are just learning

1:55:52

basic CSS. So, it's totally not expected

1:55:54

that you create buttons as neatly as

1:55:57

Twitter does, as they probably have a

1:55:59

team of developers and designers working

1:56:01

just on this profile page. So, however

1:56:04

it went, be proud of yourself and get

1:56:06

ready to move on with our Google

1:56:08

project. I'll see you in the next

1:56:10

scrimm.

1:56:13

Okay, we are back at our Google project

1:56:16

and now you are going to fix the design

1:56:18

of our search field and you're actually

1:56:19

going to get a design spec and a proper

1:56:22

walkthrough of how I want it to look. So

1:56:24

here I've opened up the dev tools

1:56:27

actually on the right hand side as I

1:56:29

want to inspect the box model of this

1:56:31

element with you. And if you wonder how

1:56:34

I managed to stick the dev tools to the

1:56:36

right hand side here, just click these

1:56:38

three icons if you're in Chrome. Then

1:56:40

you can choose the doc side. So let's

1:56:42

move on down here to the box model of

1:56:45

the input field. And if I hover over the

1:56:47

content in the box model here, you can

1:56:50

see that it says 400 pixels * 24 pixels.

1:56:53

And you can see the content is marked in

1:56:56

blue in the mini browser here. So that

1:56:59

means that our width is 400 pixels. We

1:57:02

know that because we set it ourselves

1:57:04

here. And the height of the content

1:57:06

should be 24 pixels. Okay, let's move on

1:57:09

to the padding. If I hover over that,

1:57:11

you can see it is green and it's

1:57:13

highlighted in green in the mini

1:57:14

browser. The padding at the top and the

1:57:16

bottom are 10 pixels as you can see down

1:57:20

here. And the left hand side and right

1:57:22

hand side have 30 pixels each. And then

1:57:24

if we move over to the border, you can

1:57:26

see that it's simply one pixel all

1:57:29

around. So here is your design spec

1:57:32

given to you by your hipster designer

1:57:34

down in the bottom right corner here.

1:57:37

Height of content 24 pixels. But do

1:57:39

remember that that is actually the

1:57:41

height of the inner box here not the

1:57:44

height of the total input field as that

1:57:46

also contains the padding and the

1:57:48

border. But the height property should

1:57:50

be 24 pixels. The padding above and

1:57:52

beyond as said 10 pixels right and left

1:57:55

hand side 30 pixels. Thickness of border

1:57:58

1 pixel. The color of border is this.

1:58:00

And then finally also the border radius

1:58:03

is also a value that our designer has

1:58:05

been kind enough to give to you. So take

1:58:08

this design spec and implement it using

1:58:10

CSS.

1:58:16

Okay. Hopefully that went well. If not,

1:58:18

no worries. We'll do this together right

1:58:20

now. So starting with the height of 24

1:58:23

there. I'm going to just write height 24

1:58:27

pixels like that. Okay. So it became a

1:58:29

little bit taller. Now next step is the

1:58:31

padding top and bottom was 10 pixels. So

1:58:34

padding top 10 px

1:58:37

bottom was also mpx like that. Okay. The

1:58:41

padding left and right hand side were 30

1:58:43

pixels according to the spec. So let's

1:58:45

implement that like that. And then we'll

1:58:48

move on to the border. One pixel and

1:58:51

this hex code right here. So I'll do

1:58:53

border and here we have to provide it

1:58:55

with three values. So one pixel it is

1:58:58

going to be solid and the color is d15

1:59:03

like that. Looking pretty good. The

1:59:07

final thing then is the border radius.

1:59:09

And that should be 24 pixels according

1:59:11

to the design. And look at this. It is

1:59:14

starting to look really professional. So

1:59:16

really good job if you did this

1:59:18

challenge. And if you did a couple of

1:59:19

mistakes, no worries at all. Actually, I

1:59:22

also did a little mistake here according

1:59:24

to best practices when setting heights

1:59:26

for input fields. Because actually, I

1:59:28

want to show you that this height of 24

1:59:30

pixels here is actually not the way we

1:59:32

want to do it. Because if I Google set

1:59:35

height of input field CSS and then click

1:59:37

the first link, that is a Stack Overflow

1:59:40

question. And here you can see someone

1:59:42

who's been having problems with this.

1:59:43

So, they've asked a question about it.

1:59:45

If we scroll a little bit down, you can

1:59:47

see that people are saying try with

1:59:49

padding and line height. Hm. Line

1:59:52

height. That's not something we've used.

1:59:54

If we scroll a little bit down, you can

1:59:55

see that some browsers will honor a CSS

1:59:58

height rule, some not. So, it seems to

2:00:00

be a little bit difficult to use height

2:00:02

for the input field. And this person as

2:00:05

well suggests line height. And likewise

2:00:07

with this third person here. So, I'm

2:00:09

going to trust the wisdom of the crowds

2:00:10

here and use line height instead.

2:00:14

like that. It didn't change anything,

2:00:16

but we are using a property that more

2:00:18

browsers apparently will honor. And line

2:00:21

height is actually just the height of

2:00:23

one line of text. And since that is

2:00:26

everything we have inside of an input

2:00:27

field, it's just one line of text.

2:00:30

That'll be the exact same thing as

2:00:32

setting the height of the inner content

2:00:34

of the input field. So, if that was a

2:00:36

little bit confusing and you prefer to

2:00:38

just use height, that's totally fine as

2:00:40

well. It's more important that you are

2:00:41

using what you are comfortable with than

2:00:43

that you are doing it the 100% correct

2:00:45

way according to conventions. So just

2:00:47

use whatever you want. I just wanted you

2:00:49

to be aware of the fact that this is the

2:00:52

recommended way according to Stack

2:00:54

Overflow. With that, let's move on.

2:00:59

Okay, now we're going to add the first

2:01:01

button to our Google project. So, I'm

2:01:04

going to head over to the HTML and here

2:01:06

beneath the input field, I'm just going

2:01:07

to type button like that. And this will

2:01:11

be the Google search button. So, there

2:01:14

we have it. Doesn't exactly look good,

2:01:17

but don't worry about that. Now, I want

2:01:19

to give this a class as well. And a

2:01:21

class name you'll often see used for

2:01:23

buttons is simply btn. Like that. Okay.

2:01:27

Now that we have that, I want you to

2:01:29

center the button and add some space

2:01:32

above it. So go ahead and use the class

2:01:34

selector to select this button and solve

2:01:37

this challenge. Good luck.

2:01:43

Okay. So what I'll do is do btn to

2:01:47

select the button here. You might have

2:01:49

been tempted to simply do margin left

2:01:52

auto and then margin right auto.

2:01:56

However, that doesn't seem to do

2:01:58

anything. Why is that? Well, if you

2:02:00

remember the criteria you needed in

2:02:02

order to use this technique to center

2:02:04

elements, one of them was that you need

2:02:07

your element to be display block.

2:02:09

Whereas buttons are actually display

2:02:12

inline by default. So if we do display

2:02:16

block, boom, there we go. The button is

2:02:19

centered. And now you might ask, well,

2:02:21

what about the width? We also set the

2:02:23

width on the input field and the logo.

2:02:26

Well, we could do that as well with this

2:02:28

one. Let's do width 200 pixels for

2:02:31

example. However, it's not needed

2:02:33

because if we remove the width, you can

2:02:35

see that it still has a width which is

2:02:37

certainly not full width across the

2:02:39

entire page. So, it kind of has an

2:02:41

implicit width without us setting the

2:02:43

width. So, even though it is a criteria

2:02:46

that your element needs a width in order

2:02:48

to use this technique here in order to

2:02:51

center it, you don't necessarily have to

2:02:53

set the width yourself if the element

2:02:55

already has some kind of width. So it

2:02:58

works perfectly fine just doing display

2:03:00

block and margin left right auto in this

2:03:02

example.

2:03:04

Finally we are going to add some space

2:03:05

above it. So let's do that. I'll do

2:03:08

margin top and do for example 30 pixels.

2:03:11

Yeah looking pretty good. Great job

2:03:13

solving this challenge. Let's move on.

2:03:18

Now we are going to style the button in

2:03:21

our Google project because as you can

2:03:23

see this is how our button currently

2:03:25

looks. But this is how we want it to

2:03:28

look. So, we got to do a bunch of

2:03:30

changes. However, there's one thing I

2:03:32

want to change actually on this

2:03:34

google.com homepage because notice how

2:03:37

low the contrast is between the

2:03:39

background color of the button and the

2:03:41

background color of the entire website.

2:03:44

It's hardly possible to see that there's

2:03:46

any difference. And that's not good

2:03:48

because it reduces the accessibility of

2:03:50

the site and makes it hard for people

2:03:52

who are visually impaired to use it. And

2:03:54

actually to prove this, let's take these

2:03:56

two colors, the light gray here and the

2:03:59

white, and put them into a contrast

2:04:01

checker online. For example, this one

2:04:03

right here on userway.org.

2:04:06

They have this nice little contrast

2:04:07

checker where you can paste in the

2:04:09

foreground color and the background

2:04:10

color and then get a contrast ratio. And

2:04:13

this F8 F9 F8 hex color is the one that

2:04:18

Google is using. And if we scroll a bit

2:04:20

down, you'll see that Google indeed

2:04:22

fails miserably on this test. Complete

2:04:25

failure. The ratio is 1.05, though it

2:04:29

should have been 4.5 or more. So, not

2:04:33

good Google. So, what we will do instead

2:04:35

is change the background from this to

2:04:38

something like this. Here you can see

2:04:40

it's much easier to see that it is

2:04:42

indeed a button. So even though the real

2:04:45

background color is this one right here,

2:04:47

we are going to use this one right here.

2:04:50

So with that in mind, I want you to

2:04:52

style the button according to the

2:04:54

provided design you now have. And the

2:04:56

only hint I'll give you is that these

2:04:58

are the properties you are going to use.

2:05:00

However, I'm not giving you the values

2:05:02

of any of them because I want you to

2:05:03

practice looking at an example and

2:05:05

making your best guess as to what the

2:05:07

values for the CSS properties should be

2:05:09

as that's how you'll work out in the

2:05:11

real world when a designer, for example,

2:05:13

gives you a design file. So, go ahead

2:05:15

and do this right now and then I will

2:05:17

show you the solution afterwards as

2:05:18

well.

2:05:24

Okay, let's do this. I'm going to bring

2:05:26

up the example here. Have it on the side

2:05:28

so that we can see how it develops and

2:05:31

then start with the background color as

2:05:33

we have the value for that one down

2:05:35

here.

2:05:37

Round like that. Okay. Next, I would try

2:05:41

to see what is the most apparent

2:05:42

difference between this button and this

2:05:45

one right here. Well, the border is

2:05:47

certainly different. This button does

2:05:49

not have a border at all, whereas this

2:05:51

one has got has a border. So, let's just

2:05:54

remove it. Border none. Like that. Okay,

2:05:58

good. Now, we can see that the text is

2:06:01

much more crammed into this box than it

2:06:03

is on this one right here. So, that is

2:06:05

the padding. And also, you can notice

2:06:07

that there's more padding on the left

2:06:08

and right hand side than on the top and

2:06:10

bottom. So, I'm going to try to add, for

2:06:13

example, padding top five pixels.

2:06:18

Uh, it actually looks like this one here

2:06:20

has more than five pixels because this

2:06:22

space is still pretty crammed. So, I'm

2:06:24

going to do, for example, eight.

2:06:27

Yeah, I think that is more like it. I'm

2:06:31

going to give that on the bottom as

2:06:32

well.

2:06:34

Like that. On the sides, I'm just going

2:06:37

to try the double padding left 16

2:06:40

pixels. Padding right 16 pixels. And you

2:06:44

know what? I think that button and our

2:06:47

button looks pretty similar in size.

2:06:50

So, next up is the border radius because

2:06:52

you can see this one is totally

2:06:54

rectangular whereas this one has softer

2:06:57

corners. So, I'm going to do border

2:07:00

radius something like 4 pixels. So, that

2:07:04

is pretty good. The final minor

2:07:07

adjustments I'm going to make is reduce

2:07:09

the font size ever so little from what

2:07:11

it is here down to what it is here. I

2:07:13

mean, it's almost identical, but I

2:07:15

happen to know that this one is indeed

2:07:17

14 pixels. So, I'm going to do font size

2:07:21

14 pixels like that. And there we

2:07:24

actually have the buttons, this one and

2:07:26

this one identical. Now, if you chose

2:07:30

any other values than the ones I've

2:07:32

chosen, don't worry about it at all. The

2:07:34

point was not for you to reach the exact

2:07:36

same values as me, but just in the same

2:07:38

range, basically. So regardless of how

2:07:41

your example ended up, good job reaching

2:07:43

this far. Let's just keep up the pace

2:07:45

and move on.

2:07:48

Now we are going to add the second

2:07:50

button to our Google project. This I'm

2:07:53

feeling lucky button right here. And I

2:07:56

want you to do that on your own first.

2:07:59

So that's your challenge. Add the next

2:08:01

button. And do remember to give that

2:08:03

button a btn class so that it's styled

2:08:06

as our search button. And once you've

2:08:08

done that and executed the code, I want

2:08:10

you to take a look in the mini browser

2:08:12

and ask yourself, why aren't our buttons

2:08:15

behaving as we want them to? Because, as

2:08:18

you'll see, there's something wrong with

2:08:20

the layout, at least when comparing it

2:08:22

to this layout right here. So, go ahead

2:08:24

and do that right now and try to think

2:08:26

of why our layout is wrong. And then I

2:08:29

will do it as well when you return back

2:08:31

to me and explain what's going on.

2:08:38

Okay, let's do this. So, I'm lazy, so

2:08:40

I'm just going to copy this one like

2:08:43

that and write um feeling lucky. Run the

2:08:49

code. And as you can see,

2:08:51

the buttons are now stacked on top of

2:08:54

each other. Hm. What we can do in order

2:08:57

to figure out what's going on here is

2:08:59

actually use the built-in dev tools in

2:09:01

the browser, which you've seen a few

2:09:03

times now. So, let me show you this

2:09:04

debug session using slides. I'm going to

2:09:07

rightclick in the navbar and then choose

2:09:09

inspect. Open up the elements tab and

2:09:12

then click on the selector icon here so

2:09:15

that I can select this button by

2:09:17

hovering over it and then down in the

2:09:20

styles tab, I can scroll down until I

2:09:23

see the box model for our button. And

2:09:26

what you'll notice is that our button is

2:09:28

taking up all the available space on the

2:09:30

left hand side and the right hand side.

2:09:32

And if we move down to the second

2:09:34

button, you can see that that button is

2:09:36

also doing that. That is because they

2:09:39

are display block.

2:09:41

Exactly this line right here. If you

2:09:44

remember from previous lectures, display

2:09:46

block kind of takes up all of the

2:09:48

available space on the horizontal axis.

2:09:51

So as we said earlier, display block

2:09:53

stacks on top. We aren't able to get the

2:09:56

layout we want if our buttons are

2:09:57

display block. And then you might be

2:09:59

tempted to do well let's just remove the

2:10:01

display block. However, if we do they

2:10:05

will be on the same line. Yes, they are

2:10:06

now inline elements but they will just

2:10:08

be crammed all the way to the left hand

2:10:10

side because margin left right auto

2:10:14

doesn't work. If you remember from the

2:10:16

lecture about centering, you learned

2:10:18

that display block and margin left right

2:10:21

auto works together in order to center

2:10:23

something. You can't have just one of

2:10:25

them. Which means that in order to go

2:10:28

from this layout to this layout, we have

2:10:31

to use a different technique for

2:10:33

centering the elements. And there's

2:10:34

actually two ways we could do this.

2:10:36

There's the simple and inflexible way

2:10:39

using text align. And then there's the

2:10:41

slightly harder but super flexible way

2:10:44

using flexbox. And since you're going to

2:10:46

use flexbox several times throughout

2:10:48

this course, I want you to get familiar

2:10:50

with it right away. So in the next

2:10:52

scrim, we're going to talk about

2:10:54

flexbox. But before we do that, I just

2:10:56

want to show you the simple way as well

2:10:57

so that you've seen it. Because as you

2:10:59

might remember from one of the very

2:11:01

first scrims in this section, we used

2:11:03

something called text align in order to

2:11:06

align our text either to the left,

2:11:08

right, or center. Now the text align

2:11:10

property actually works on all inline

2:11:14

elements, not just on text. So what we

2:11:16

can do is remove the display block from

2:11:20

our buttons. As you know that turns them

2:11:23

into inline elements and they are

2:11:25

crammed to the left and as inline

2:11:28

elements only take up the available

2:11:30

space they need according to their

2:11:32

content. There is no available margin to

2:11:34

use. So auto here which basically means

2:11:37

take up whatever available margin there

2:11:39

is serves no purpose. So we can remove

2:11:42

both of these two as well. As you can

2:11:44

see it made no difference. And then we

2:11:46

can move up to the main the parent. So

2:11:48

we'll do text align

2:11:51

center like that and boom both buttons

2:11:54

are now centered. So here we have told

2:11:57

the container the main element all

2:12:00

inline elements inside of it should

2:12:02

align to the center. So that was the

2:12:05

easy but inflexible way of doing this.

2:12:08

Let's instead of using this technique

2:12:10

move on to do it how the pros do it

2:12:12

using flexbox.

2:12:16

Flexbox is everywhere. Let's just have a

2:12:19

look at Twitter for example. Here the

2:12:21

menu on the lefth hand side is created

2:12:23

with flexbox as with the tweet options

2:12:26

menu and the timeline itself. And guess

2:12:28

what these trends for you and who to

2:12:30

follow is created with? You guessed it,

2:12:32

flexbox. So this is something you need

2:12:34

to learn. Let's imagine then that you

2:12:37

have a e-commerce website which you can

2:12:39

see here that sells shoes, hoodies, and

2:12:42

t-shirts. Well, then you'd probably have

2:12:44

a navigation menu like this one where

2:12:46

users can click and then probably open

2:12:48

up a submen or something like that. As

2:12:50

you can see, the items stack on top of

2:12:52

each other. That is to be expected as

2:12:54

these are divs and divs are display

2:12:57

block. They want to take up all the

2:12:58

available space in the width. And if

2:13:00

you're wondering how I styled these, we

2:13:03

can head over to the styles.css and just

2:13:05

have a quick look at that. You can see

2:13:06

I've aligned the text to the center

2:13:08

inside of all the items. Hadn't I done

2:13:10

that, it would have been aligned to the

2:13:12

left. Also, there's a border. As you can

2:13:14

see, there's some padding on the inside,

2:13:16

and there's some margin in between the

2:13:18

elements. Now, the question is, what if

2:13:22

I instead of this vertical layout wanted

2:13:24

a horizontal layout, which is more

2:13:26

common for so-called navigation bars?

2:13:29

So, something that looks like this.

2:13:31

Well, this is where flexbox comes to the

2:13:34

rescue. And in order to turn this into a

2:13:36

flexbox layout, I would first have to

2:13:38

wrap these three items in a container

2:13:40

because a flexbox layout always consists

2:13:42

of a container and its direct children.

2:13:46

So let's wrap it in a div and give this

2:13:50

a class of for example nav dash wrapper

2:13:54

like that. If I run this now, nothing

2:13:57

happens because divs as you know are

2:13:59

invisible unless you give them any

2:14:00

styling or content. So let's head over

2:14:03

to the styles.css

2:14:05

and now target the nav wrapper like that

2:14:08

in order to turn this into a flexbox

2:14:10

container. All I have to do is write

2:14:12

display flex and boom. Suddenly we have

2:14:16

forced our three divs into one row. Now

2:14:19

this layout flows from left to right

2:14:21

along the horizontal axis and that is

2:14:23

pretty significant given that these

2:14:25

items were display block by default. But

2:14:28

flexbox, as powerful as it is, overrides

2:14:30

that and forces them onto one line.

2:14:33

However, we haven't got quite the layout

2:14:35

we want yet. As you can see, it's

2:14:37

centered and there's also some space in

2:14:38

between the items. Now, let's start with

2:14:41

the centering because flexbox now has

2:14:44

control over these items and can decide

2:14:47

where along the main axis they should be

2:14:49

positioned. So, we can do justify

2:14:51

content. That is a little bit of a weird

2:14:53

name for a property, but that's just how

2:14:55

it is. and then set that to center. Like

2:14:59

that. Now all of the items are centered.

2:15:01

And the final step is just to get some

2:15:03

spacing in between these items. And that

2:15:05

is done with our good old friend margin.

2:15:07

So we'll do margin left. Let's do 10

2:15:10

pixels. And let's add the same thing on

2:15:12

the margin right

2:15:15

like that. And there we have the layout

2:15:18

we wanted. Now a final cool thing I want

2:15:21

to show you is that we can do for

2:15:23

example end here as well. That'll push

2:15:25

it all the way to the right hand side or

2:15:27

start at the beginning or alternatively

2:15:30

do space dash around. That's pretty

2:15:33

cool. Now we've distributed all the

2:15:35

white space around each of the items.

2:15:38

And another one is space between. Now

2:15:40

all of the available space is between

2:15:42

the items. So they're spread out like

2:15:44

this. Now we are getting ahead of

2:15:47

ourselves here. I just wanted to

2:15:48

demonstrate this to show how powerful

2:15:49

flexbox is. What you are going to work

2:15:51

with is the center here. So with that,

2:15:54

let's return back to our Google clone.

2:15:59

Okay, we are back at our Google project.

2:16:02

And now your job is to center these two

2:16:04

buttons besides each other. Meaning

2:16:07

getting to this layout right here. And

2:16:10

the way to do that is of course using

2:16:12

flexbox. So you'll wrap the two buttons

2:16:14

in a flexbox div and then center them.

2:16:18

And then also I want you to give the div

2:16:20

a class of btn-wrapper.

2:16:23

So you'll need to modify both the HTML

2:16:25

and the CSS here. Now before you start,

2:16:28

I'm going to remove these three lines

2:16:31

here because they are solely there in

2:16:33

order to center our buttons using this

2:16:36

display block and margin left right auto

2:16:38

technique. However, now we're going to

2:16:40

use the flexbox technique. And we don't

2:16:42

want to use both techniques at the same

2:16:44

time because that'll just be confusing

2:16:46

as they will affect each other. So I

2:16:50

will remove these lines. And now you're

2:16:52

left with this left aligned layout here.

2:16:56

So please take over here, do this

2:16:58

challenge, and then return back to me

2:17:00

when you've done it or when you feel you

2:17:02

need some guidance. Good luck.

2:17:09

Okay, hopefully that went well. If not,

2:17:11

no worries. We'll do it now together. So

2:17:14

I'm going to start with this flexbox div

2:17:16

that we want in our HTML. It should wrap

2:17:19

our buttons and only our buttons. So we

2:17:22

want to start it up here. If class of

2:17:25

btn dash wrapper at I'm going to indent

2:17:30

my buttons and then end the div down

2:17:33

here. So now it is simply wrapping our

2:17:36

two buttons. If I run this code,

2:17:39

seemingly nothing has happened. But

2:17:41

under the hood, we have the button

2:17:43

wrapper which we can target using

2:17:46

btn-wrapper

2:17:48

like that. And then we can do display

2:17:51

flex. That's turned our div into a

2:17:53

flexbox. And now we can use the justify

2:17:57

content and do center like that. There

2:18:01

you can see both our buttons are

2:18:03

centered. However, they are totally

2:18:06

crammed into each other now. There's no

2:18:07

margin in between them. So, in order to

2:18:10

fix that, we want to add a little bit of

2:18:12

margin left and right to these buttons.

2:18:14

So, I'm going to do margin left, perhaps

2:18:18

four pixels, and margin right four

2:18:22

pixels as well. Like that.

2:18:25

That's looking pretty good to me. So, if

2:18:29

you didn't do this, no worries at all.

2:18:31

And also, if you are a little bit

2:18:32

confused about flexbox, that is totally

2:18:35

okay as well. We're going to work with

2:18:36

that several times throughout this

2:18:38

course, so you'll get more opportunities

2:18:40

to practice this. Just feel proud that

2:18:42

you've at least dipped your toes into

2:18:44

Flexbox as that is a super important

2:18:47

tool for any front-end developer. So,

2:18:50

great job. Let's move on.

2:18:54

Now, there's one final thing I want you

2:18:57

to know, and that is that you are

2:18:59

amazing because you have taken your very

2:19:02

first step into the world of CSS, and

2:19:05

that is more than most people ever do.

2:19:07

So, take this moment to feel great about

2:19:10

yourself. And also, let's take this

2:19:12

moment to recap what you've learned.

2:19:14

Starting out, you learned about the CSS

2:19:16

syntax. That is how you select elements

2:19:19

and also use properties and values. And

2:19:21

then you learned the key concept about

2:19:23

inline elements versus block elements.

2:19:26

So block elements stacking on top of

2:19:28

each other like these two and inline

2:19:30

elements standing kind of in a

2:19:32

horizontal line like the buttons here.

2:19:34

Moving on, you learned about margins,

2:19:36

which is how you create white space

2:19:38

outside of elements, for example, above

2:19:40

the Google logo here. And you learned

2:19:41

about its close cousin, the padding,

2:19:44

which is how you create space on the

2:19:45

inside of elements, for example, in

2:19:47

between the text and the edges of these

2:19:49

buttons. Also borders is what is between

2:19:52

padding and margin and we use that on

2:19:55

the input field here. We decided its

2:19:57

thickness, its type and color and also

2:19:59

the radius of the corners. So we didn't

2:20:01

want sharp edges but rather soft

2:20:04

circular edges which we achieved with

2:20:06

this border radius property. What we

2:20:08

also did was take a closer look at the

2:20:10

div tag which you saw briefly in the

2:20:12

HTML section. This time around though

2:20:14

you actually created two divs. one to

2:20:17

wrap the entire project and another to

2:20:19

wrap the buttons. And we had to separate

2:20:22

those from each other. So you had to

2:20:24

learn about classes. That is the

2:20:26

attribute you set like this. And you

2:20:28

select by using the dot notation in the

2:20:31

CSS. Also a big thing is centering in

2:20:34

CSS. You learned three different ways of

2:20:37

doing this. And the final way you

2:20:39

centered elements was through the use of

2:20:41

flexbox. a super powerful tool that all

2:20:44

front-end developers need to be

2:20:46

comfortable with. So, you have learned a

2:20:49

lot. Now, I think you should take a

2:20:51

little break. You have to digest these

2:20:53

things, recharge, and then I will see

2:20:55

you back here when you are ready in the

2:20:57

next section.

2:21:01

Welcome to the second CSS section of

2:21:04

this course where you are going to build

2:21:06

a business card for yourself. And it's

2:21:08

going to look more or less like this.

2:21:10

Though you're going to personalize it,

2:21:12

make it your own, not only with your own

2:21:14

information, but also with a beautiful

2:21:15

color palette of your choice and a font

2:21:18

that you like. So you are going to level

2:21:20

up your design skills as well as your

2:21:23

CSS skills, meaning that this is going

2:21:25

to be a lot of fun. So let's just get

2:21:28

started with it right away.

2:21:32

Okay, let's start out by having a quick

2:21:34

look at the basic skeleton for our app.

2:21:37

As you can see in the file system here,

2:21:39

we have an index html file, also a

2:21:41

styles.css file, and finally we have an

2:21:44

images folder which contains my avatar.

2:21:46

It's a png file called pair.png.

2:21:50

Now, starting with the HTML, it's just a

2:21:52

very simple setup with the HTML tag and

2:21:55

then the head tag which links to the

2:21:57

styles.css.

2:21:58

As for the body, it has one direct child

2:22:01

which is a div which will work like kind

2:22:03

of the container for our business card.

2:22:05

And inside of that div, we have an image

2:22:07

tag. We have an H3 with my name. We have

2:22:10

a paragraph with the title and an H4

2:22:13

with the location.

2:22:15

Moving over to the CSS, we only have one

2:22:18

rule here. We're setting the margin to

2:22:20

20 pixels on the body. And if you

2:22:22

remember how this works, when we're not

2:22:24

specifying either margin top, margin

2:22:26

bottom, left, or right, just setting the

2:22:29

margin in general, these 20 pixels will

2:22:32

be added on all four sides. on the top,

2:22:34

on the left, bottom, and right. And

2:22:36

that's simply because I want to avoid

2:22:38

that these elements touch the edges of

2:22:40

the mini browser. So, there's a problem

2:22:43

though. As you can see, the image isn't

2:22:45

rendering properly. It's just an icon.

2:22:48

That is, as far as I can remember, not

2:22:50

how my face looks like. And the problem

2:22:52

is in the image tag. So, I want you to

2:22:55

try to fix that. And I'm not going to

2:22:56

give you any more hints. Rather than if

2:22:58

you are stuck, try to Google HTML file

2:23:01

paths. That should help you. So go ahead

2:23:03

and give this one a shot and then I will

2:23:05

show you how to solve it as well when

2:23:06

you return back to me.

2:23:12

Okay, let's do this. Let's take this

2:23:15

string right here and paste it into

2:23:16

Google. There you can see that the top

2:23:18

result is a W3 schools article. Let's

2:23:21

head into that one. Here you can see

2:23:23

file path examples. Let's zoom in on

2:23:25

this one. And if we have image source

2:23:27

equals picture.jpeg, JPEG, which will be

2:23:30

the same as we have here, although our

2:23:31

image is called pair.png. That means

2:23:34

that the file is located in the same

2:23:36

folder as the current page. Well, is

2:23:39

that the case? Now, looking at our

2:23:41

current page, index.html, you can see

2:23:44

that the image is not located in the

2:23:46

same folder as the index html because

2:23:48

the image lives inside of the images

2:23:51

folder. So, what we then might need is

2:23:53

something like this where we do images

2:23:55

slash and then the picture name. here.

2:23:58

It means that the picture is located in

2:24:00

the images folder in the current folder.

2:24:03

And that looks correct. The images

2:24:05

folder is in the same folder as

2:24:07

index.html. And the headshot of me is

2:24:10

located inside of that images folder.

2:24:13

That means that we can try to do images

2:24:15

like that. Slash run the code. Oh, there

2:24:18

we go. We have my avatar imported and

2:24:22

are ready to move on to the next trim.

2:24:24

I'll see you there.

2:24:28

Hi there, my name is Bob Zroll. I'm

2:24:30

another teacher here at Scribba and I

2:24:32

wanted to expound a little bit on the

2:24:34

lesson that you just learned with pair.

2:24:35

This is a very similar example to what

2:24:37

you just saw with the Google homepage.

2:24:39

In this example, we have an image that

2:24:41

is referencing cat.jpeg, but as it turns

2:24:44

out, relative to where our index.html

2:24:47

file is, that cat.jpeg file is only

2:24:50

inside of the images folder. So, as you

2:24:53

just saw in the example with pair, I

2:24:55

will need to prefix this with images

2:24:57

slash. When I begin my string this way,

2:25:00

it's saying look in the directory that

2:25:02

the current file or the index.html file

2:25:05

is in for another directory called

2:25:07

images. The directory that the

2:25:09

index.html file is in is called the

2:25:11

project root folder. And that's

2:25:13

everything that you see here under this

2:25:15

explorer title here in Scribba. And by

2:25:18

correctly referencing the path to where

2:25:20

this cat.jpeg JPEG image is found. I can

2:25:22

hit save and our image of this cat is

2:25:25

giant because our CSS file is commented

2:25:28

out, but we'll fix that in just a

2:25:29

minute. Okay, so this is simple enough

2:25:31

to understand, but there are some other

2:25:33

points of syntax that I think are really

2:25:35

helpful to know. First of all, and

2:25:37

probably the easiest one to understand

2:25:39

is that if you prefix the path with a

2:25:41

dot slash, it's a way to tell in your

2:25:44

code that you are going to be starting

2:25:45

from the current directory. That's

2:25:47

exactly what we're doing here already.

2:25:49

So adding a dot slash does exactly the

2:25:52

same thing. As far as I know, there's

2:25:53

functionally no difference. Now on its

2:25:56

face, it might seem like it's just

2:25:57

extraneous information. However,

2:25:59

personally, I do prefer to include the

2:26:01

dot slash at the beginning. I think it's

2:26:03

a little bit more explicit and kind of a

2:26:06

visual reminder that I'm referencing a

2:26:08

local file inside of my project. But

2:26:10

that's going to change from one person

2:26:12

to the next and one team to the next. So

2:26:14

I mostly wanted to include it here so

2:26:16

that when you saw it, it wasn't

2:26:18

confusing. We can see I can hit save and

2:26:20

we're still getting our cat image

2:26:22

showing up correctly. This leads us into

2:26:24

another way that you can use relative

2:26:26

path syntax to reference other files in

2:26:28

your tree and that's by prefixing your

2:26:30

path with a dot dot slash. Using the two

2:26:33

dots is a way to start looking at the

2:26:35

parent directory first. Okay, when would

2:26:38

this be useful? Well, let's go into our

2:26:40

source directory and then inside of our

2:26:42

CSS directory and open up our index.css.

2:26:46

And here you'll notice that we're

2:26:47

selecting an image div class and giving

2:26:50

it a background image with this URL.

2:26:52

This URL has a relative path that goes

2:26:55

up two directories first before going

2:26:57

down into the images directory. Because

2:27:00

our index.css CSS file lives inside of

2:27:02

the CSS folder, which is inside of this

2:27:05

source folder, which is a sibling, I

2:27:07

guess you could say, folder to the

2:27:09

images folder. We need to go up two

2:27:11

levels from CSS to source and from

2:27:14

source to the project route before we

2:27:16

can then drill back down into the images

2:27:19

directory. Now, why isn't this dog.jpeg

2:27:22

showing up in our mini browser over

2:27:24

here? That's because in our index.html,

2:27:26

HTML. We commented out this stylesheet

2:27:29

and we don't have the correct href here.

2:27:31

So, take a quick second as a mini

2:27:33

challenge. Pause now and fix this href

2:27:35

so that first of all, our cat image will

2:27:37

be more reasonably sized and second of

2:27:39

all, the dog image will show up. Pause

2:27:41

now and see if you can get that to work.

2:27:49

To do this, we can start with a dot

2:27:51

slash if we want. go into the source

2:27:54

folder, then into the CSS folder, and

2:27:56

then into index.css.

2:27:59

We'll hit save. And there we go.

2:28:01

Everything is working. Really quickly,

2:28:03

we can also see an example of this dot

2:28:05

dot slash. If I were to move my

2:28:07

index.html inside of, let's say, my

2:28:10

source folder, I'll need to make a quick

2:28:12

change to the mini browser here to begin

2:28:14

it with /source.index.html.

2:28:17

But you can see that my sleeping cat is

2:28:19

broken and so is the link to my CSS

2:28:21

page. Because my index.html page is now

2:28:24

nested inside of my source folder, I'll

2:28:27

need to make a change both to my link

2:28:29

here and to my image here. And by I'll

2:28:32

need to make that change, I mean you

2:28:34

need to make that change. Let's make

2:28:35

this into a quick challenge. Pause now

2:28:37

and fix both of these paths so that

2:28:39

everything goes back to the way it was.

2:28:47

Okay. Well, relative to the index page,

2:28:49

which is now inside of the source

2:28:51

directory, I no longer need to reference

2:28:54

/source. Instead, I can just simply go

2:28:56

into the CSS directory because the

2:28:59

current directory is the source

2:29:00

directory. With our cat image, I need to

2:29:02

go up a directory first in order to get

2:29:05

to the project route where I can then

2:29:07

drill down into the images directory.

2:29:09

So, I'll hit save. And sure enough,

2:29:11

everything's working the way it was. not

2:29:13

feeling great about putting the index

2:29:15

page inside of my source directory. So,

2:29:17

I'm going to move that out. I'm gonna

2:29:19

change these back and fix my mini

2:29:21

browser so that it's not looking at the

2:29:23

source anymore. Okay, perfect. The last

2:29:25

syntax that I'll talk about is just

2:29:27

using a slash at the beginning. Having a

2:29:30

slash as the very first character of

2:29:32

your relative path is a way to start

2:29:34

directly from the project's root

2:29:36

directory. For example, if I didn't want

2:29:38

to do this whole thing where I'm going

2:29:41

up two directories before then going

2:29:43

down to my images directory, it's a

2:29:45

little bit more concise for me to begin

2:29:47

this with a slash that says just start

2:29:49

at the top root directory of this

2:29:51

project rather than worrying about going

2:29:53

up so many levels and then back down so

2:29:55

many levels. So that's what the slash at

2:29:58

the beginning of your path does. Now, I

2:30:00

have one more challenge for you and

2:30:01

that's to fix our script source. We

2:30:04

haven't talked too much about

2:30:05

JavaScript, so don't be too concerned

2:30:07

about anything dealing with JavaScript.

2:30:09

All we need to do is make sure that the

2:30:10

source to the JavaScript file is

2:30:13

correct. And when it is correct, you

2:30:14

should see a message pop up in the

2:30:16

console. That's all I'm going to say

2:30:18

about that for now. I want you to figure

2:30:19

out the rest. So, pause here and fix the

2:30:21

source for our script.

2:30:28

Our index.html is at the root of our

2:30:31

project. So, I have a bunch of different

2:30:33

ways that I could do this. I could just

2:30:35

start with a slash to indicate start

2:30:37

from the root. Then I would go into

2:30:39

source scripts. Let's open this up.

2:30:42

Scripts and then main.js. So,

2:30:44

slashmain.js.

2:30:46

We'll hit save. And we get that I'm the

2:30:49

main.js file console log just like we

2:30:51

would expect when it's working. Because

2:30:52

this file is at the root, I don't

2:30:54

necessarily need to specify a slash at

2:30:56

the beginning. I could just say src or

2:30:59

as I mentioned my preference would be to

2:31:00

start with a dot / src and hitting save

2:31:03

shows that log coming up again and

2:31:05

everything also working that way. I know

2:31:07

this is a really simple topic but I'm

2:31:09

hoping this can eliminate any confusion

2:31:11

that you might have as you're looking at

2:31:13

other people's code other code here on

2:31:14

Scribba or maybe help you avoid a really

2:31:17

tricky bug sometime about having a path

2:31:19

that's incorrect somewhere. Okay, thanks

2:31:21

for letting me talk about relative paths

2:31:23

for just a little bit. I'm going to pass

2:31:24

you on back to P.

2:31:28

Okay, now we're going to do a little bit

2:31:30

of housekeeping here because this image

2:31:33

element actually has a serious flaw

2:31:36

because it lacks an important ingredient

2:31:38

that all image tags should have which is

2:31:41

called the alt text or the alternative

2:31:44

text and that is simply an attribute

2:31:47

that is written like this alt equals and

2:31:50

then inside of quotes you are to write a

2:31:53

description of the image. So here it

2:31:56

could be for example Pier Borggan

2:31:58

smiling like that. However, if we run

2:32:01

this code now, you can see that

2:32:02

seemingly nothing has changed. So why do

2:32:05

we at all write these old texts? Well,

2:32:08

first of all, it makes your site

2:32:09

accessible because imagine that a person

2:32:12

who is visually impaired or who is blind

2:32:14

is trying to visit your website. In that

2:32:17

case, they would use a screen reader

2:32:19

which goes through the HTML and reads it

2:32:22

out loud to the user. And as for the H3

2:32:26

tag, it would be simple for the screen

2:32:27

reader to read out loud what that says

2:32:30

because that is text. However, for an

2:32:32

image like this one, you need to add an

2:32:35

alt tag to describe the image so that

2:32:37

the screen reader has something to read

2:32:39

out loud. And secondly, this also works

2:32:41

as a fallback if your image doesn't

2:32:43

render properly cuz let's say you have a

2:32:46

spelling mistake in the sorts attribute,

2:32:49

for example, an extra R. Well, in that

2:32:51

case, the image won't render, but the

2:32:53

alt tag provides as a backup so that the

2:32:56

user seeing this can kind of understand

2:32:58

what was at least supposed to be there.

2:33:00

And finally, writing alt text will help

2:33:03

your site rank higher on Google, meaning

2:33:05

you get more search traffic. And that is

2:33:08

because the alt tag most likely provide

2:33:10

important metadata about the image so

2:33:12

that Google knows how to use it in a

2:33:14

search results page. And if your site is

2:33:16

not accessible, it might be punished in

2:33:18

the form of ranking lower. So with that

2:33:21

in mind, let's look at how to write

2:33:22

these alt texts. And the first thing you

2:33:25

need to know is that you should not

2:33:26

include for example image of because

2:33:28

that's simply not necessary. The screen

2:33:30

reader knows that it is an image because

2:33:32

it is an image tag.

2:33:34

Secondly, should be concise meaning less

2:33:37

than 125 characters because a lot of

2:33:40

screen readers will cut off after this

2:33:42

limit has been reached. And finally, a

2:33:44

trick you should use in order to come up

2:33:45

with a good old text is imagine that you

2:33:48

are describing this image to a person

2:33:50

over the phone. So let's try to do that

2:33:53

with an example. Here we have an iconic

2:33:55

image of Muhammad Ali in a boxing match.

2:33:58

And one way to write an old text for

2:34:00

this could be just a boxing match, but

2:34:03

it would actually be a pretty poor way

2:34:05

of describing it because there's so much

2:34:06

more going on here. You have plenty more

2:34:08

characters you can use in order to

2:34:10

describe it. So, a better one would be

2:34:12

two boxers in the ring, one lying down

2:34:14

and the other standing up. That's a good

2:34:17

factual explanation, but we're not quite

2:34:19

there yet because it isn't actually

2:34:21

describing this iconic moment when

2:34:24

Muhammad Ali knocked out Sunonny Listen.

2:34:26

So, if you were to describe this over

2:34:28

the phone, you would probably understand

2:34:30

that this description is pretty shallow.

2:34:33

So what I would rather write as an old

2:34:35

text for this image would be Muhammad

2:34:37

Ali in the boxing ring screaming at

2:34:39

Sunonni listen after knocking him out.

2:34:41

That in my opinion properly describes

2:34:44

the intent of this image. What the

2:34:46

person who has decided to show this

2:34:48

image on a website is trying to convey.

2:34:51

So with that example in mind, I want you

2:34:54

to write what you think is an

2:34:57

appropriate alt text for this image. go

2:35:00

ahead and do that right now and then I

2:35:02

will show you what I would write when

2:35:04

you return back to me.

2:35:10

Okay, let's do this. We'll do alt equals

2:35:13

quotes and here I would use my name pair

2:35:16

Harold Borggan. And you can see I'm

2:35:19

smiling and I'm looking at the camera. I

2:35:21

think that's important. So I'd write

2:35:23

smiling at the camera. Finally, the

2:35:27

background is really playful and

2:35:29

colorful.

2:35:31

So, I want to include, for example, with

2:35:33

a colorful

2:35:35

background like that. So, if yours was a

2:35:38

bit simpler or shorter, don't worry

2:35:40

about it. The most important thing is

2:35:42

that you add an alt text and do as best

2:35:44

as you can. And actually, plenty of

2:35:46

developers never add this. So, just by

2:35:48

adding it, you are actually separating

2:35:50

yourself from most other beginners. So,

2:35:52

with that, let's just move on.

2:35:56

The next thing we're going to do is

2:35:59

shrink this image to a suitable size for

2:36:02

our business card because as it is now

2:36:04

it is far too big. So I want you to head

2:36:07

over to the styles.css and solve this

2:36:09

challenge. You are to set the width of

2:36:11

the image to 150 pixels and you need to

2:36:14

use a class to select the image element.

2:36:18

So go ahead and give this a shot right

2:36:19

now.

2:36:25

Okay, hopefully that went well. Let's

2:36:27

now do it together. So, first we need to

2:36:29

actually create the class that we are

2:36:31

going to select from the CSS. So, let's

2:36:34

head over to the HTML file here. We'll

2:36:36

just do class equals. And I'm going to

2:36:39

call this one an avatar like that.

2:36:42

Actually, now that we have three of

2:36:44

these on the image element, I think for

2:36:47

readability purposes, it works well to

2:36:50

break them into three lines.

2:36:52

I think this is a little bit easier to

2:36:54

read. Then I'll head over to the

2:36:55

styles.css and target the class avatar

2:37:00

and just set the width to 150 pixels.

2:37:04

Now rerun the code. There we go. So

2:37:07

great job solving this challenge. Let's

2:37:09

move on.

2:37:13

Okay, now you're soon going to start

2:37:15

building the layout of this card.

2:37:17

However, right now the card kind of

2:37:20

blends into the background. There's no

2:37:22

separation between the card and the

2:37:24

background. So, I want to add a little

2:37:26

helper style in order for us to more

2:37:28

clearly separate the card from the

2:37:30

background. And for that, we need to

2:37:32

grab hold of the outer element of the

2:37:35

card. And can you take a guess what kind

2:37:37

of HTML element do you think should wrap

2:37:40

the entire card?

2:37:43

If you guessed a div, that is correct.

2:37:46

And heading over to the HTML, you can

2:37:48

see we are actually already wrapping the

2:37:50

entire thing in a div. So here we have

2:37:53

our container div or card div or

2:37:56

whatever we want to call it. So what I

2:37:59

want you to do now is to first give that

2:38:01

div a class and actually I think you

2:38:03

should call it card and then I want you

2:38:05

to select the card class in CSS and give

2:38:08

it a dotted blue border. This is our

2:38:10

helper styles. It'll give us a little

2:38:13

blue border around the element so that

2:38:15

we can see how our card div kind of

2:38:17

behaves. And also, as you can see from

2:38:20

the design here, none of the elements

2:38:23

touch the edge of the border. So, it

2:38:25

seems like there's some padding in play

2:38:27

here. Let's just add 20 pixels of

2:38:29

padding on all sides of the card as

2:38:31

well. So, go ahead, solve these three

2:38:33

challenges, and then I'll of course show

2:38:35

you the solution as well.

2:38:41

Okay, let's do this. So, first we need

2:38:44

to give the card div a class.

2:38:48

I'll head over here and do class equals

2:38:51

card.

2:38:53

I'll run this code so that we have this

2:38:55

class in the DOM.

2:38:57

The next step is to select the class by

2:39:01

doing card

2:39:02

and then adding a border. If you

2:39:04

remember from previously that is done

2:39:05

through the border property which takes

2:39:08

three values. The first one being the

2:39:11

thickness of the border. I'm just going

2:39:12

to set it to one pixel. The second being

2:39:14

the quality for example solid or dotted

2:39:16

or dashed or a few others. We're going

2:39:19

to use the dotted one and the color will

2:39:21

be blue. And there you can see boom we

2:39:25

have a border around our entire card.

2:39:28

And this will make it a lot easier for

2:39:30

us to work with the card now that we can

2:39:32

see it clearly on the page. Finally, we

2:39:35

want to add 20 pixels of padding because

2:39:37

as you can see here, the elements touch

2:39:39

the border on these sides and we don't

2:39:41

want that. We want some space. So, we'll

2:39:43

do padding

2:39:45

20 pixels like that. And there we go. We

2:39:49

have solved the challenge. With this in

2:39:51

place, I think we're ready to start

2:39:53

moving on with fixing the layout. And as

2:39:56

you can see on the finished design here,

2:39:58

there's a big difference between this

2:40:00

one and our current one. And that is

2:40:03

that the current one is vertical whereas

2:40:05

this one is more horizontal. So they

2:40:08

stack up differently. We want the image

2:40:10

on the left hand side and the text on

2:40:12

the right hand side, not everything on

2:40:13

top of each other. So basically we want

2:40:15

two columns, one for the image and one

2:40:18

for the text. And as you might remember

2:40:20

from previously, flexbox helps us create

2:40:23

columns. So let's now just experiment by

2:40:25

adding display flex to the card and

2:40:28

let's see what happens. Oh wow. Okay. So

2:40:31

what happened there? It actually turned

2:40:34

every single element into a column in

2:40:36

itself. That's not exactly what we want

2:40:39

here. So display flex isn't the entire

2:40:43

solution. So, what we're going to do now

2:40:45

is go out on a tangent, learn a little

2:40:47

bit more about this flexbox concept in

2:40:50

CSS, and then return back to this

2:40:52

business card project once we're ready

2:40:54

to build a layout like this. So, let's

2:40:57

move on and learn more about flexbox.

2:41:02

Okay, so let's say that you've built

2:41:04

some kind of software as a service and

2:41:06

now you want to sell it. Then you might

2:41:08

have a page like this where people can

2:41:11

upgrade to pro and they can choose the

2:41:13

individual plan which gives them 1 GB

2:41:15

and no support or the enterprise plan

2:41:18

which gives them 10 GB and priority

2:41:20

support. Now I've purposely not given

2:41:22

any design to this example as I wanted

2:41:25

to make it as easy as possible to grasp.

2:41:27

But hopefully if you are to create a

2:41:29

pricing page you make it look a lot

2:41:31

better than what we have here. So you

2:41:33

can see the HTML right here for the

2:41:36

entire pricing layout. I've wrapped it

2:41:38

in a div and I'm using an H2 unordered

2:41:41

list, a button and so on. Now let's say

2:41:44

that you instead of having this one

2:41:46

column layout here where everything

2:41:48

stacks on top of each other, you want

2:41:50

this two column layout where you have

2:41:52

the individual plan at the left hand

2:41:54

side and the enterprise plan at the

2:41:55

right hand side. Well, if so, we know

2:41:58

that flexbox will help us create

2:42:00

columns. But if we try turning our

2:42:03

container is the div with a class of

2:42:05

pricing into a flexbox,

2:42:08

you'll see that

2:42:12

it'll break the layout just as we saw in

2:42:14

our business card example. Because

2:42:16

what's going on here is that flexbox

2:42:19

takes every single item that is every

2:42:22

single direct child and turns it into a

2:42:25

column in itself. So we get a column for

2:42:28

the H2, for the unordered list, for the

2:42:31

buy button, for the H2 again, and so on.

2:42:34

And this is obviously not what we want.

2:42:36

It's far from this two column layout

2:42:38

right here. However, there's one hint to

2:42:41

be drawn from this example. And that is

2:42:44

that if you check out the unordered list

2:42:46

here, you see that it has two children

2:42:48

of itself, LII elements. And those two

2:42:52

are not their own columns. they are in

2:42:54

the same column stacking on top of each

2:42:56

other. So it seems as if flexbox only

2:42:59

turns the direct children into their own

2:43:02

columns. So the direct children are the

2:43:05

h2 here, the ul, the button, but not the

2:43:09

list items. And once we know that, we

2:43:11

can use that knowledge in order to get

2:43:14

to this layout. Because this layout has

2:43:16

two columns, that means that our flexbox

2:43:18

container should have two direct

2:43:20

children, not six as it has now. And how

2:43:23

can we achieve that? Well, we want this

2:43:26

group to be inside of a direct child of

2:43:29

this container. And we want this group

2:43:32

of HTML elements to also be inside of

2:43:35

another direct child of the flexbox

2:43:37

container. So what we'll simply do is

2:43:39

we'll wrap both of these inside of a div

2:43:43

like that. And we'll indent it for

2:43:46

readability purposes. Let's try to run

2:43:48

this code having wrapped one of the two

2:43:50

groups into its own div. And there you

2:43:53

can see the four individuals plan now

2:43:56

stacks up just how we want it. But the

2:44:00

rest of the layout is still broken. So

2:44:01

we need to do the same thing down here

2:44:06

like that. Run the code and there we go.

2:44:09

Now our flexbox container actually only

2:44:12

contains two items. this div and this

2:44:15

div as it doesn't care about what's

2:44:17

inside of both of those children. It

2:44:19

only cares about its direct children.

2:44:22

And the result is that we get the layout

2:44:24

we wanted here, at least in terms of

2:44:26

having two columns. There's still a

2:44:29

problem with lacking space in between

2:44:31

these two children, but we're not going

2:44:33

to deal about that right now. For now,

2:44:35

I'm going to send you back to the

2:44:36

business card example so that you can

2:44:38

use this to improve our layout.

2:44:43

Okay, we are back at our business card

2:44:45

example and now I want you to use what

2:44:47

you've just learned in order to fix our

2:44:49

cards broken column layout cuz you are

2:44:52

going to make this card into a two

2:44:54

column instead of a four column which it

2:44:56

is now it has the image name title and

2:45:00

location at four different columns but

2:45:03

instead we want two columns one for the

2:45:05

image and another one for the text

2:45:07

elements. So this challenge is solved in

2:45:10

the HTML. As you know, we already have a

2:45:13

display flex on the card and the only

2:45:15

thing you need to do is one change

2:45:17

inside of our flexbox. So hopefully

2:45:19

you're able to do that. Go give it a

2:45:21

shot and then I will show you the

2:45:22

solution as well.

2:45:28

Okay, hopefully that went well. Let's do

2:45:30

it together. So the problem is that

2:45:34

flexbox treats each of these elements as

2:45:38

a single child and thus each of them get

2:45:40

its own column. However, we only want

2:45:43

two columns. So we want these three to

2:45:45

be governed by one flex child. So we

2:45:49

need to wrap them inside of a div. We'll

2:45:52

do like this. Open the div and then

2:45:55

close the div down here. And we'll

2:45:57

indent these so that we get some better

2:45:59

readability. Now you can see the flexbox

2:46:02

only has two direct children. This one

2:46:04

and this one. That means that we should

2:46:06

get two columns in our layout. And yes,

2:46:09

we do. Brilliant. Of course, there's

2:46:12

still a long way from this design to

2:46:14

this design. But we are making great

2:46:16

progress here. So, let's just keep up

2:46:18

the pace and move on to the next scrim.

2:46:23

Okay. I think looking at this example

2:46:25

now, I got to admit that I'm pretty

2:46:28

pleased with this border, one pixel

2:46:30

dotted blue here, I think it serves a

2:46:32

very nice purpose, which is to highlight

2:46:34

for us how our card is being laid out on

2:46:36

the page. So, wouldn't it be nice if we

2:46:38

could use that exact technique on other

2:46:41

elements on the page as well? For

2:46:42

example, the children of the flexbox

2:46:44

container, that is this image right here

2:46:46

and the div tag. That would have been

2:46:48

really neat. And we can do that by for

2:46:51

example just copying this one and adding

2:46:53

it for example to the avatar. See there

2:46:55

the avatar is got that blue border as

2:46:58

well. However, wouldn't it be neat if we

2:47:01

in our HTML could just quickly apply a

2:47:04

class to any element for example this

2:47:06

one and it would get the same thing as

2:47:08

well. So basically the argument I'm

2:47:10

making is that we should create a

2:47:11

dedicated class for this blue border.

2:47:15

And what that is is a utility class, aka

2:47:18

a class that only sets a single CSS

2:47:21

property. So let me show you how this

2:47:23

would work. Let's say that we for

2:47:25

example want a class to make our text

2:47:27

italic. Then we'll simply do class

2:47:30

equals itallic like that. If we run this

2:47:33

code, nothing has happened because the

2:47:35

class hasn't been created yet. But here

2:47:37

we can create the italic class and do

2:47:41

font style italic like that. And now you

2:47:45

can see the name is in italic. Now if we

2:47:48

want to reuse this, we can just do class

2:47:52

italic here as well. Run the code and

2:47:55

the location is also italic. And if we

2:47:57

want the entire card itallic, we can

2:47:59

even add the class here up on the

2:48:01

container element itself. Run the code.

2:48:03

And now this has been inherited down to

2:48:06

all of these elements. And if you're a

2:48:08

bit confused about what I'm doing here,

2:48:10

it is simply adding two CSS classes to a

2:48:12

single element. Do that simply by adding

2:48:15

a space in between the two classes.

2:48:17

Okay, let's get rid of these like that

2:48:22

and delete this one as well. Now, what I

2:48:24

want you to do is create a utility class

2:48:28

for the dotted blue border. This is the

2:48:30

styling we have here. And then give the

2:48:32

class to both flexbox children in the

2:48:35

HTML. that is the flexbox items you can

2:48:37

see here and here. And also I think you

2:48:41

should give the same class to the card

2:48:42

as well so that you can remove this line

2:48:44

10 here. So go ahead and give this one a

2:48:46

shot and then I will show you how to do

2:48:48

it afterwards as well.

2:48:54

Okay, hopefully that went well. Let's

2:48:56

start out by creating the class. I'll

2:48:59

write border blue here.

2:49:02

And then inside of it, I'll just cut

2:49:04

this away and paste it in here instead.

2:49:07

Now we have a utility class for blue

2:49:09

borders. I'll copy it and add it to this

2:49:13

flex item. And as a second class to the

2:49:17

image element, we run this code. You can

2:49:19

see now both of these have the blue

2:49:22

border around them. Let's also add the

2:49:24

border blue class to the flexbox

2:49:26

container. run the code and boom, there

2:49:28

we go. Now we have an even better

2:49:30

overview over how our elements are laid

2:49:32

out.

2:49:35

Okay, with these blue borders around the

2:49:37

flexbox children, it's pretty easy to

2:49:39

see that our layout is pretty far from

2:49:42

how we want it to be. Cuz here you can

2:49:44

see in the card that there's some space

2:49:47

in between the two elements. Whereas in

2:49:49

our example, they're completely crammed

2:49:51

together and also pushed all the way to

2:49:54

the left hand side. Whereas here they're

2:49:56

kind of spaced out. There's some space

2:49:58

on the left hand side in between the

2:50:00

element and also some space on the right

2:50:03

hand side. So they're kind of spaced out

2:50:05

in a nice way. And now I want you to add

2:50:07

that horizontal space around the flex

2:50:10

children. There's a flexbox property

2:50:12

that does this. And you've seen that

2:50:13

property before. However, you might have

2:50:15

forgotten it. If so, then Google justify

2:50:18

content and you might find the answer.

2:50:20

I'm not going to give you any more hints

2:50:22

than that because if you have forgotten

2:50:23

about it, it is a great practice to

2:50:25

Google it. Then once you figure out the

2:50:28

answer, go ahead and add the horizontal

2:50:29

space so that our example becomes a

2:50:31

little bit more like this layout. And

2:50:33

just so you know, you only need to add

2:50:35

one property for this, not multiple. So

2:50:38

give it your best shot and then I will

2:50:40

show you the solution afterwards as

2:50:42

well.

2:50:47

Okay, let's do this. So the property is

2:50:50

called justify content. A little bit of

2:50:53

a weird name, I agree, but that's how it

2:50:55

is. And here we can use a range of

2:50:58

different values. And the one we're

2:50:59

looking for is called space around like

2:51:02

that. And now you can see both elements

2:51:05

now have some space around them. And

2:51:07

also we could do space between then all

2:51:11

of the available space will be between

2:51:13

the two items. Or we could even do

2:51:16

center as you've seen before. then

2:51:18

there's no space in between them but

2:51:20

both of them are centered and end pushes

2:51:23

it all the way to the end and start

2:51:26

keeps it at the start. So this is a

2:51:29

super powerful property and we want the

2:51:32

space round value for it. As you can see

2:51:35

it's at least getting closer to the

2:51:37

layout we have in our finished design.

2:51:40

So great job. Let's move on.

2:51:45

Okay, time for a new challenge. You are

2:51:47

going to set a fixed width on the card

2:51:50

and then center it on the page because

2:51:52

its behavior is a little bit weird right

2:51:54

now. As you can see, if we enlarge the

2:51:56

screen, the card gets enlarged as well

2:51:59

and that makes the spacing between the

2:52:01

elements look super weird. The aspect

2:52:03

ratio becomes very different from a

2:52:05

business card. So, we don't want that.

2:52:07

Instead, we want the width to be 400

2:52:09

pixels. So, it should be a fixed width.

2:52:12

And then we also want the card to be

2:52:14

centered on the page. Now, one thing I

2:52:16

want you to notice when I enlarge this

2:52:19

is that the card is a display block even

2:52:23

though we've set it to display flex. So

2:52:26

that means that flexbox containers by

2:52:28

default are display block. And hopefully

2:52:31

you remember from previously that

2:52:32

display block takes up all the available

2:52:34

space in the horizontal axis. And it is

2:52:37

also one of the three ingredients you

2:52:39

need in order to center an element using

2:52:42

margins. So hopefully you remember from

2:52:45

the Google project how to center block

2:52:47

elements. So go ahead and give this one

2:52:49

your best shot and then I will show you

2:52:51

the solution as well when you return

2:52:52

back to me.

2:52:58

Okay, let's do this. I'll start by

2:53:00

setting the width to 400 pixels like

2:53:03

that. Now you can see if we enlarge the

2:53:05

screen, the card is stuck to the left

2:53:07

hand side of the website. So, in order

2:53:10

to fix that and instead center it, we'll

2:53:12

use margins. And hopefully you remember

2:53:14

that we'll do margin left and set that

2:53:18

to auto. That pushes it all the way to

2:53:20

the right hand side because all of the

2:53:22

margin is now on the left hand side. But

2:53:24

then in order to even it out and center

2:53:26

it, we'll do margin right as well and

2:53:29

set that to auto. And the result of

2:53:33

having an equal margin on the left hand

2:53:34

side and the right hand side is that the

2:53:37

card is centered. So, great job on

2:53:39

solving this challenge. Let's move on.

2:53:44

>> All right, let's take a minute to talk

2:53:46

about CSS inheritance. And you're

2:53:48

probably thinking, wait a minute, this

2:53:49

isn't the singongy Nordic accent of

2:53:51

Perorgan. And you'd be right. My name is

2:53:53

Bob Zurroll. I'm another teacher here at

2:53:55

Scribba. And I'm interjecting myself

2:53:57

here to make a small accessibility

2:53:59

update just in the way that the HTML was

2:54:01

written in the original version of the

2:54:03

screencast, but also as a way to

2:54:05

introduce myself. If you're here as part

2:54:07

of the front-end career path, you will

2:54:09

be taking another one of my courses,

2:54:10

either the APIs and asynchronous

2:54:12

JavaScript course or the React course

2:54:14

that's later on in the path. Okay, back

2:54:16

to the topic at hand. Let's learn about

2:54:18

inheritance and why it's important to

2:54:20

learn about inheritance in the first

2:54:22

place. First of all, it will help you

2:54:24

write, you could say, drier code. Dry

2:54:26

stands for don't repeat yourself. In

2:54:28

other words, you can take advantage of

2:54:30

this concept of CSS inheritance so that

2:54:32

you don't have to keep writing the same

2:54:34

CSS code over and over, but instead can

2:54:37

define it in one place and have that

2:54:38

change cascade throughout the rest of

2:54:41

your CSS. Inheritance is also something

2:54:43

that can help you avoid bugs in your

2:54:45

code and generally be more efficient. To

2:54:48

demonstrate this, we've pulled in an

2:54:50

article from Wikipedia here about the

2:54:52

dancing plague of 1518. This is a really

2:54:55

strange phenomenon that happened in

2:54:57

modern-day France where somewhere

2:54:59

between 50 and up to 400 people

2:55:02

inexplicably took to the streets and

2:55:03

started dancing as it would appear

2:55:05

against their will. It's a fascinating

2:55:07

story. Feel free to read through the

2:55:09

events. There's even an illustration

2:55:11

here. I have no idea what could cause

2:55:13

this, but there's some pretty good

2:55:14

theories here that include food

2:55:16

poisoning and so forth. So, feel free to

2:55:18

look through this article, but that's

2:55:19

just for fun. Let's not go too far down

2:55:21

this rabbit hole. Instead, let's talk

2:55:23

about inheritance in the context of this

2:55:25

article. Since we've pulled this into

2:55:27

our own page, maybe we've decided that

2:55:29

we would like to center all of the text

2:55:31

on this page. And so, I could go to my

2:55:33

styles.css and start centering each one

2:55:36

of these elements by itself. For

2:55:39

example, we have an H1, a paragraph, an

2:55:41

H2, more paragraphs. So, sure, I could

2:55:44

start by saying I want to select the H1

2:55:47

and do text align center. Okay, I've

2:55:50

centered my text there for the H1. Now,

2:55:53

let's go to our H2 and do the exact same

2:55:56

thing. So, we'll go ahead and center the

2:55:59

H2. Great. We're partway there. Then, we

2:56:01

have to also select the paragraphs. And

2:56:03

hopefully, you can see the point I'm

2:56:04

trying to make here. In this case, we

2:56:06

would not consider our code very dry

2:56:08

because we are repeating oursel instead

2:56:11

of following DRY. Don't repeat yourself.

2:56:14

So, what does this have to do with

2:56:15

inheritance? Well, let's look at our

2:56:17

HTML and we can see that our entire

2:56:19

article is conveniently placed inside of

2:56:22

an article element. The idea of an

2:56:24

article element in HTML is

2:56:26

self-contained content that if you were

2:56:28

to remove it and put it somewhere else,

2:56:30

it would still make sense. Of course,

2:56:32

the dancing plague of 1518 is hard to

2:56:34

make any sense of, but I think you get

2:56:36

my gist. In this case, if we really do

2:56:38

want everything in our article to be

2:56:40

text align center, we can take advantage

2:56:42

of CSS inheritance by instead of

2:56:45

repeating all of our rules here, we can

2:56:47

say everything inside of the article

2:56:50

should be text align center. And as you

2:56:52

can see, this single rule has been

2:56:54

inherited by all of its children

2:56:56

elements where text align center makes

2:56:58

sense. Now, I could have chosen to put

2:57:00

text align center up on the body

2:57:03

instead. And you can see we get the same

2:57:05

effect. Essentially, we can know that

2:57:07

this inheritance doesn't just happen

2:57:08

with the direct children of the element

2:57:11

that we're selecting in CSS, but will

2:57:13

work any number of layers down the

2:57:15

descendant tree of the element that

2:57:16

we're selecting. I personally prefer to

2:57:18

have it on the article because maybe

2:57:20

there's other elements that we don't

2:57:22

want to have text align center that are

2:57:24

outside of the article tag. So, let's

2:57:26

leave it here on our article. Now to

2:57:28

refine our understanding of inheritance,

2:57:30

it's important to know that text align

2:57:32

is an example of a CSS property that

2:57:34

does get inherited down the tree.

2:57:36

However, not all CSS properties will get

2:57:39

inherited. I have found that it's pretty

2:57:41

intuitive which ones will and which ones

2:57:42

won't. But like we should do anytime we

2:57:44

have a question as we're learning

2:57:45

something new, we can Google it. Here

2:57:47

you can see we've Googled which CSS

2:57:49

properties are inherited. And there's a

2:57:51

Stack Overflow question exactly about

2:57:52

this. If we click into it, we can see

2:57:55

down here somebody has answered it and

2:57:56

begun a list. If we scroll down, we get

2:57:58

all the way down to 41 different CSS

2:58:01

properties that are inherited. Now, let

2:58:03

me be honest, most of these are not CSS

2:58:06

properties that you're going to really

2:58:07

have to care too much about. In fact,

2:58:09

when I was looking at this, I think

2:58:11

probably over 50% of these properties

2:58:13

I've never even heard of before. Some of

2:58:15

them, however, like the text align that

2:58:16

we just used and some of these other

2:58:18

font related ones, like font family,

2:58:20

font size, font style, and so forth, are

2:58:22

really good ones to know. All right,

2:58:23

let's get your hands on the keyboard

2:58:25

with a challenge. I want you to navigate

2:58:28

to this Stack Overflow question to pick

2:58:30

a few of the inherited properties on

2:58:32

this list. You can just click the

2:58:34

screenshot here to go directly to the

2:58:35

article and try applying them directly

2:58:37

to the article element that we've

2:58:39

selected here and just see this working

2:58:41

in practice. I know it might seem a

2:58:43

little bit frivolous, but this kind of

2:58:44

hands-on work is what really will engage

2:58:46

your brain and help you remember the

2:58:48

stuff that we're learning. Now, as a

2:58:49

fair warning, some of these properties

2:58:51

are going to affect things like screen

2:58:53

readers more than anything you might see

2:58:55

visually. Properties like volume or

2:58:57

speech rate, but other ones should be

2:58:59

readily apparent in the visible output

2:59:01

that you see here. Then, once you're

2:59:03

done, I'm going to hand you back to pair

2:59:04

to continue on with the next scrim.

2:59:10

Okay. Now it's time for a challenge in

2:59:13

the business card project because you

2:59:15

are going to center the text inside of

2:59:17

the paragraph and the H4 elements and

2:59:20

that is the paragraph right here which

2:59:23

says frontend developer and the H4 right

2:59:25

here. Because as you can see, both of

2:59:28

those elements are now crammed all the

2:59:30

way to the left hand side. Whereas in

2:59:32

our finished design, they are aligned at

2:59:35

the center of this flex children

2:59:38

directly underneath the name Pier Harold

2:59:41

Borgen. And if you're wondering why

2:59:43

we're not caring about centering this

2:59:44

one, it's because it takes up the full

2:59:46

width of the container. So you can't

2:59:49

center or left or right align it because

2:59:51

it takes up the full width anyway. it is

2:59:53

the element that actually decides how

2:59:55

wide this container should be. So you

2:59:58

will only see the paragraph and the age

3:00:01

for change when you fix this. And the

3:00:03

way you should do it is by only adding

3:00:05

one property and then have inheritance

3:00:08

take care of applying that property to

3:00:11

both elements. So you're only going to

3:00:12

write one line of code. And I'm not

3:00:14

going to tell you where you should add

3:00:16

that line of code. You have to figure

3:00:18

that out on your own. And I'm also not

3:00:20

going to tell you what the property is

3:00:21

called or the value you'll give it, but

3:00:23

you have seen it before. So hopefully

3:00:25

it's not that foreign to you. So jump

3:00:27

into the code and try to solve this

3:00:29

challenge now. Then of course revert

3:00:31

back to me when you want to see my

3:00:33

solution.

3:00:38

Okay, hopefully that went well. Now

3:00:41

we're going to use the text align

3:00:43

property and set it to center. But

3:00:46

before we do that, we need to decide

3:00:48

which element we should target with that

3:00:50

property. Should we add it to the entire

3:00:52

body, for example? If so, it'll inherit

3:00:54

down from the body into the card and

3:00:58

then into our flex children right here.

3:01:01

And then finally to these elements as

3:01:03

well. That works perfectly fine. We can

3:01:05

actually try it. Text align center. And

3:01:09

boom. These two are now centered.

3:01:11

However, imagine that this card is a

3:01:13

part of a bigger website. If so, we've

3:01:15

now centered all text inside of the

3:01:18

body,

3:01:19

which is where all of the HTML, both now

3:01:22

and in the future, will live. Though,

3:01:24

this might have second order

3:01:25

consequences. Perhaps we want to have a

3:01:27

navbar with a title that isn't text

3:01:29

align center, but rather text aligned

3:01:30

right or left. So, actually, I think

3:01:33

it's better to scope this to, for

3:01:35

example, our card. We at least know now

3:01:37

that all of the text we currently have

3:01:38

in our card should be aligned to the

3:01:40

center. So, let's do that instead. Let's

3:01:43

just remove it from the body and paste

3:01:45

it in here. And now we're not causing

3:01:46

any unwanted second order effects

3:01:49

outside of the card. So this is in my

3:01:51

opinion a better solution. But if you

3:01:53

added it to the body, that is a

3:01:54

perfectly valid solution as well. So

3:01:56

don't feel that you did a mistake. In

3:01:58

coding, there's always plenty of ways to

3:01:59

solve things. And there's rarely one

3:02:01

right answer. There's just consequences

3:02:04

for whatever choice you make. So really

3:02:06

good job doing this. Let's move on.

3:02:11

All right. Now, the fun stuff remains,

3:02:13

which is adding colors according to the

3:02:16

specified design here. So, this is a

3:02:18

really rewarding little challenge

3:02:19

that'll make a ton of difference as

3:02:21

you'll go from this boring white layout

3:02:23

here to a nice colorful layout. So,

3:02:26

you're going to add these three colors.

3:02:28

As you can see, I've added the hexadimal

3:02:31

values for each of the colors, the

3:02:33

black, the blue, and the purple. The

3:02:35

purple is the border at the bottom here.

3:02:38

The blue is the background color, of

3:02:39

course. And then finally, you might

3:02:41

wonder, well, what's the black? Well,

3:02:42

that is actually the text color, as the

3:02:45

text here isn't pure black, as it uses

3:02:48

this shade of black instead. Now, you

3:02:51

might wonder, well, how do I create this

3:02:54

border at the bottom here? I've only

3:02:55

learned how to create borders around an

3:02:57

entire element previously. Well, the way

3:02:59

to solve any problem when coding is to

3:03:02

Google it. So, let's just write border

3:03:04

bottom CSS in Google. There you can see

3:03:07

a W3 schools article. Click in on it.

3:03:09

And here it has some code examples which

3:03:11

we can zoom in on set the style of the

3:03:14

bottom border for different elements.

3:03:16

And here it shows us how to set the

3:03:18

border bottom. So we do border

3:03:20

dashbottom and then for example 5px

3:03:23

solid red. Well that's exactly how we'd

3:03:26

set the border itself except that we

3:03:28

would omit this dashbottom in the

3:03:31

property name. So you'll use the exact

3:03:33

same technique you've used for the

3:03:34

entire border just with this extra word

3:03:37

added to the end. So hopefully you'll be

3:03:39

able to do that. So here is the design.

3:03:42

And a final thing I'm going to do before

3:03:44

I'll leave it to you is to remove these

3:03:47

blue borders here because we don't need

3:03:49

them anymore. So let's head into the

3:03:51

HTML. I'm going to mark the border blue

3:03:54

utility class we've added. Do command

3:03:57

plus D. That enables you to select

3:03:59

multiple instances of whatever you've

3:04:01

highlighted. And then boom. I'm going to

3:04:04

remove it like that. Then also we don't

3:04:07

need any class in the div for this flex

3:04:10

children anymore. The code our borders

3:04:13

are gone. I'll leave this for now in

3:04:16

case you want to add it back again. But

3:04:18

now it's your turn. Go ahead and try to

3:04:20

solve this challenge and then of course

3:04:22

I will show you the solution when you

3:04:23

return back to me.

3:04:29

Okay, hopefully that went well. Let's

3:04:31

now do it together. I'm going to start

3:04:33

with the blue background as that'll make

3:04:36

the biggest difference. So I'll do

3:04:38

background then copy this hex value like

3:04:41

that. Very good. Then I'll do the text

3:04:44

color that is color and copy the one

3:04:48

right here. Yes, not as visible as the

3:04:51

previous change, but something surely

3:04:53

happened. We're now using that shade of

3:04:55

black for the text. And finally, the

3:04:57

purple border bottom will be added by

3:04:59

doing border dash bottom. And then let's

3:05:03

try two pixels. And we want to use solid

3:05:06

than the purple color. Okay, we can see

3:05:09

a thin border at the bottom. Let's have

3:05:11

a look at the design. It looks like it

3:05:13

is definitely thicker here. So, let's

3:05:15

crank it up a little bit. For example, 6

3:05:17

pixels. Yes, that looks pretty good to

3:05:21

me, actually. So, really good job

3:05:24

reaching this far. You are very close to

3:05:26

the end right now. So, let's just keep

3:05:28

up this great pace and finish up this

3:05:30

project over the next few scrims.

3:05:35

Okay, now I want to talk a little bit

3:05:37

about fonts because fonts are actually

3:05:39

really important. Let's say that you for

3:05:41

example have created a computer

3:05:43

specialists company called Click Lovers.

3:05:45

Well, you might want to think about

3:05:46

which font you choose in that case. Or

3:05:48

if you're the owner of the Megaflex

3:05:50

shop, you should also think carefully

3:05:52

about which font you choose. Finally, if

3:05:54

you are the head of the wig and pen

3:05:56

association, make sure that your font

3:05:58

spaces out words correctly. Now, these

3:06:01

are of course extreme cases and they're

3:06:03

all on prints. You'll rarely see cases

3:06:05

as bad as this on the web, but fonts

3:06:08

really matter online as well. Let's take

3:06:10

Wikipedia for example. Here is a random

3:06:12

article about people who have died from

3:06:14

laughter. As you can see, Wikipedia has

3:06:15

this very serious nice font. But if we

3:06:18

change that to something like Comic

3:06:19

Sandance, you can see the text gives a

3:06:21

whole different type of association. It

3:06:23

went from being very serious like this

3:06:25

to being more like a comic book. So when

3:06:27

you are building projects, it is

3:06:28

important that you choose a font that

3:06:31

kind of suits your project. So let's

3:06:33

move on to look at how it works

3:06:35

technically under the hood. Because when

3:06:37

you visit a website, for example,

3:06:39

scribble.com, you visit it via a client.

3:06:42

That could be your mobile, tablet,

3:06:43

desktop, or whatever. What happens is

3:06:46

that when you type www.scrimble.com

3:06:48

scrimba.com into the URL bar. It sends

3:06:50

off a request to Scribba's server and

3:06:52

then the server says, "Yeah, okay. You

3:06:54

want to visit our website? Yeah, of

3:06:56

course. Here you go." And it takes

3:06:58

everything you need in order to run the

3:06:59

Scribby in the browser. That is the

3:07:01

HTML, the CSS, the JavaScript, the

3:07:04

assets, which can be images and videos

3:07:06

and so forth. Then also the recipe for

3:07:08

the font and then it sends that back to

3:07:10

the client. However, for some websites,

3:07:13

they won't send you the recipe for the

3:07:16

font over the network because they will

3:07:18

instead on their website use a font that

3:07:20

most likely is already pre-installed in

3:07:24

your client. That is also called a web

3:07:26

safe font, meaning that the recipe for

3:07:29

rendering that font exists in most

3:07:32

clients. Now, of course, there might be

3:07:34

some clients that don't have that

3:07:35

specific font, but in almost all cases,

3:07:38

it's safe to use one of the web fonts

3:07:40

without sending the recipe for it over

3:07:42

the network. So, what are these websafe

3:07:45

fonts? Well, here is an article on V3

3:07:48

schools where you can see all of the web

3:07:50

fonts for HTML and CSS. So, when you're

3:07:52

using these, you don't have to send the

3:07:55

recipe for the font over the network.

3:07:58

Now, for our digital business card,

3:08:00

we're only going to use Web Safe fonts,

3:08:02

but later down the line, you'll also

3:08:03

learn how to pull in external fonts so

3:08:05

that you can go outside of these 10

3:08:07

fonts as they don't really give you a

3:08:09

lot of flexibility. So, with that in

3:08:12

place, let's look at how you actually

3:08:14

use a font in CSS. So, in order to set a

3:08:17

font, you first target normally the body

3:08:19

and then type out font family and then

3:08:21

the name of the font. And here you can

3:08:23

see we've typed V and that triggers VS

3:08:26

Code which is the editor powering

3:08:28

Scribba to come up with suggestions for

3:08:30

you. You can see it doesn't only suggest

3:08:32

Verdonna which is the font we want. It

3:08:34

also adds a bunch of other fonts after

3:08:36

it all separated by a comma. So if we

3:08:40

hit enter now, boom, then we've added

3:08:42

what's called a font stack. And what

3:08:44

this means is that if the browser finds

3:08:47

the Verdonna font installed, it finds

3:08:49

the recipe for that font, well then it

3:08:51

will use it. However, if it can't find

3:08:53

it, if Verdonna isn't installed in the

3:08:55

client's computer, then it'll try to

3:08:57

find Geneva, which is a pretty similar

3:08:59

font. If it can't find Geneva, it'll

3:09:01

jump on and try to. And if it can't even

3:09:03

find Tacoma, it says, well, give me any

3:09:06

Sans serif font. And sans serif is a

3:09:09

category of fonts. So, here it's just

3:09:11

saying, give me any font from this

3:09:13

category. And there are mainly two

3:09:15

categories, sans serif and serif. Here

3:09:17

you can see an example of both of them.

3:09:19

Serif fonts contain these decorative

3:09:22

strokes at the end of the letters. You

3:09:24

can see it here, here, here. Whereas

3:09:28

sans serif is without those decorative

3:09:31

endings. So sans then means without or

3:09:34

not or something like that. You get the

3:09:36

point. Okay, that was a lot of theory.

3:09:40

Now it is your turn. You are going to

3:09:42

set the font here to Verdonna. And also

3:09:44

make sure to remember to get the entire

3:09:46

font stack so that we have backups in

3:09:48

case the client doesn't include the

3:09:50

Verdonna font. So go ahead and do that

3:09:53

right now.

3:09:58

Okay. Hopefully that went well. What

3:10:00

you'd want to do is font family colon

3:10:04

start typing and then the editor

3:10:06

suggests the entire font stack. Though

3:10:08

you won't see that now because the

3:10:10

scrimbot DOM recorder doesn't record it.

3:10:12

However, I can see it. So, I'm just

3:10:14

going to hit enter and boom, the editor

3:10:16

suggested this entire font stack with

3:10:18

me. We have changed the font. Let's

3:10:20

verify that by removing it. Boom. Yeah,

3:10:22

that's different from this. So, really

3:10:26

good job. We've actually now completed

3:10:27

the design for our business card.

3:10:30

However, there's a little issue with our

3:10:32

code because this is how noobs write

3:10:34

their margins. And I want to teach you

3:10:36

how the pros do it. So, let's move on to

3:10:39

the next scrim where you'll learn

3:10:41

exactly that.

3:10:45

Okay, now it's time to learn about the

3:10:47

shorthands for margin and padding. And

3:10:50

you've actually been exposed to one of

3:10:51

them already, which is that if you have

3:10:53

the same value on the margin top, right,

3:10:56

bottom, and left, you can reduce those

3:10:58

four lines into one margin 10px. Then

3:11:01

the browser will take this 10px and

3:11:04

apply them to all sides. So these four

3:11:06

lines are identical to this one down

3:11:08

here. Now the question becomes what

3:11:10

happens when you have four different

3:11:12

values for example 10 px 20 px 30 and

3:11:15

40. Well if so you have to do like this

3:11:18

margin and then 10 px 20 30 40. So the

3:11:21

first one is margin top the second one

3:11:23

is right the third one is bottom and the

3:11:25

fourth one is left. So now you're

3:11:26

probably thinking well how can I

3:11:28

possibly remember this order? And the

3:11:31

trick is to think of the clock. It

3:11:33

starts at the top then goes to the right

3:11:35

then goes to the bottom and then goes to

3:11:37

the left. So with that in mind, I want

3:11:39

you to improve this code here which

3:11:42

creates the Japanese flag in CSS because

3:11:45

as you can see this red circle here

3:11:47

which is a div has a few styles applied

3:11:51

up here but down here we've used the

3:11:54

nonshorthand way to set the margins.

3:11:57

Setting some margin on the top so that

3:11:58

the circle is pushed down. nothing on

3:12:01

the right and the bottom but 100 pixels

3:12:02

on the left so that it's pushed to more

3:12:05

or less the center of a screen given

3:12:07

that the screen is as wide as it is

3:12:09

right now. So I want you to translate

3:12:12

this into using the margin shortand

3:12:14

instead. Go ahead and do that right now.

3:12:22

Okay, hopefully that went well. I'm

3:12:24

going to actually comment these lines

3:12:26

out. Now you can see the red circle is

3:12:28

up in the left corner. And then I'm

3:12:30

going to do margin starting at the top

3:12:33

should be 40 pixels. Then the right side

3:12:35

0 pixels. Then the bottom should also

3:12:38

have zero pixels. And then the left side

3:12:41

which should have 100 pixels. And there

3:12:43

we go. We are back at the exact same

3:12:45

layout. So great job if you manage to

3:12:47

solve this. Now there's another scenario

3:12:50

I want to teach you about as well which

3:12:52

is if we have top and bottom as one

3:12:55

value and right and left as another

3:12:58

value. If so you can actually reduce it

3:13:01

to margin and then only two values. Here

3:13:04

you do 10px and auto because 10px is top

3:13:08

and bottom. Auto is left and right. So

3:13:10

the way to think about this is that the

3:13:12

first value controls the vertical line,

3:13:16

the yaxis, and the second value controls

3:13:19

the horizontal line, also known as the

3:13:21

x-axis. So with that in mind, let me

3:13:24

change this a little bit. I'm going to

3:13:25

go back to the funky way of writing

3:13:27

this. And I'm actually going to improve

3:13:28

it a little bit because if we want to

3:13:30

center the circle, we shouldn't hardcode

3:13:33

a margin left because that'll only work

3:13:35

on this screen size. When we do like

3:13:37

this, it's not centered anymore. So

3:13:38

let's instead use the better technique

3:13:40

of using auto on the left hand side and

3:13:43

the right hand side. And also just to

3:13:46

make sure that no elements are allowed

3:13:47

to appear directly underneath our

3:13:50

circle, I want to add 40 pixels to the

3:13:53

margin bottom. So now I'll make it a

3:13:55

little bit easier for you and separate

3:13:57

these two. With this in mind, can you

3:14:01

reduce these four lines into two? Go

3:14:04

ahead and give that a shot right now.

3:14:10

Okay, let's do this. I'll comment out

3:14:13

these. And if you wondered what shortcut

3:14:15

I used for that, I'm using command + K +

3:14:19

C, but that is on a Mac keyboard. I'll

3:14:21

comment this out. Then I'll do margin

3:14:24

first. We'll set the vertical axis. I

3:14:26

should have 40 pixels at the top and the

3:14:28

bottom. So that is 40 px. And then we'll

3:14:30

set the horizontal axis, which is auto

3:14:33

like that. And boom, there we go. We

3:14:35

have it centered. at least horizontally

3:14:38

regardless of how wide the screen is and

3:14:40

we have reduced four lines into one. So

3:14:43

great job. Let's move on.

3:14:47

Okay. Now you're going to take what

3:14:49

you've learned about the margin

3:14:50

shortorthhand and use that in order to

3:14:53

reduce these two lines into one. So

3:14:56

you're going to replace the two margin

3:14:58

properties with a single margin

3:15:00

shortand. And of course after you've

3:15:02

done that the card should still be

3:15:04

centered as it is now. So go ahead and

3:15:07

give this one your best shot.

3:15:13

Okay, let's do this. So I'm going to

3:15:16

start by removing both of these. Now you

3:15:19

can see the card is aligned on the left

3:15:20

side. So in order to fix this, we'll do

3:15:23

margin. And then the first property

3:15:26

we'll set will be the vertical line,

3:15:28

meaning margin top and margin bottom

3:15:31

because we're only going to set two

3:15:32

values. And when we do that, each of the

3:15:34

value dictates two sides either top

3:15:37

bottom or left right. So we'll set zero

3:15:39

as the first value. That means margin

3:15:42

top zero and margin bottom zero. And

3:15:44

then for the second value which dictates

3:15:47

the horizontal margin meaning left hand

3:15:49

side and right hand side we'll set of

3:15:51

course auto. And there you see now the

3:15:55

card is still centered and we have

3:15:57

reduced two lines into one. So great job

3:15:59

solving this challenge.

3:16:04

You have reached the final step of the

3:16:06

business card project. That is

3:16:08

phenomenally well done. Give yourself a

3:16:10

pat on the back. And now only the fun

3:16:13

stuff remains because now you're going

3:16:15

to personalize this card. So first I

3:16:18

want you to add your own information to

3:16:20

this card. As for the image, you can

3:16:22

just drag and drop an image over the

3:16:25

file system here and then link to it

3:16:27

from the source. And once you've done

3:16:29

that, head over to the CSS because here

3:16:31

you're going to do a few cool

3:16:33

challenges. First off, I want you to

3:16:36

find a color palette you like on

3:16:38

coolers.co. And this is coolers. It's a

3:16:40

super neat site for finding nicel

3:16:42

lookinging colors and color

3:16:43

combinations. So what you can do is

3:16:45

simply click this explore trending

3:16:47

palettes. Then you'll come to this

3:16:49

overview which has a ton of different

3:16:50

palettes. And you can also search up in

3:16:52

the right corner here. Let's say you're

3:16:54

a big fan of roses. Well, then you can

3:16:56

write that and then boom, you'll find a

3:16:58

ton of pallets with rose looking colors.

3:17:01

And when you hover over one of the

3:17:03

colors, you'll see the hex value of that

3:17:05

color. And also, if you have an account

3:17:07

on coolers, you can click on these three

3:17:09

dots here and then choose save palette.

3:17:12

Then you can give it a name and save it.

3:17:15

When you then later visit your profile,

3:17:17

which you can do by clicking up here in

3:17:18

the top right corner, then you'll see

3:17:21

all of your saved pallets. So go ahead

3:17:24

and find a palette you like on coolers

3:17:26

and then change these values here so

3:17:29

that your business card becomes

3:17:30

completely unique. Also once that's done

3:17:33

I want you to find a web save font you

3:17:35

like and add it to your card as well

3:17:37

because you shouldn't use Verdana. You

3:17:38

should pick one of the other web fonts

3:17:40

and if you have to Google a little bit

3:17:42

to find the web save fonts well that is

3:17:43

just important practice as well. And

3:17:45

then if you want to go above and beyond

3:17:48

go crazy I've created some stretch goals

3:17:50

for you here. I want you to simply find

3:17:52

other ways to personalize the design of

3:17:54

your business card. For example, you can

3:17:56

change the border or borders. You can

3:17:58

add a border radius. You can also

3:18:01

shuffle the layout like should the image

3:18:03

be here or maybe centered at the top or

3:18:06

at the right hand side or just in a

3:18:08

corner. I don't know. And if you want to

3:18:09

do something mind-blowing, you can add

3:18:11

shadows. For example, I've not taught

3:18:13

you anything about shadows, so that's

3:18:14

far outside the scope of this course. Or

3:18:17

if you want to go even more crazy,

3:18:19

double mind blown, create some hover

3:18:21

effects so that when you hover with a

3:18:22

cursor over some of the elements, they

3:18:24

change. That is business card 2.0 in my

3:18:27

opinion. And if you want to go triple

3:18:30

mind blown, create some CSS animations.

3:18:33

Now, please don't stress about doing any

3:18:36

of these. It is not expected that you do

3:18:38

any of them. I just wanted to add it

3:18:40

there for those of you who can't help

3:18:42

going above and beyond. Now, once you're

3:18:44

done personalizing your business card, I

3:18:47

have one more task for you, and that is

3:18:49

to download the code to your local

3:18:52

computer and then place it in a folder

3:18:55

called business card because we're going

3:18:57

to use this folder when we deploy your

3:18:59

business card in the next scrim. So, go

3:19:02

ahead and do all of this and I will see

3:19:04

you when you're done.

3:19:08

Last time we deployed a project, we

3:19:11

first added our code to Netlfy, which

3:19:13

then again took care of deploying our

3:19:15

project to the web. Now, while this

3:19:17

works perfectly fine, the way the pros

3:19:20

do it is to go via an intermediate

3:19:22

service and step called GitHub and then

3:19:24

let GitHub take care of sending off the

3:19:27

code to Netlifi so that it's deployed to

3:19:29

the web. And the reason you want this

3:19:31

kind of architecture is because GitHub

3:19:33

allows you to collaborate on your code

3:19:35

with other developers. So now we are

3:19:38

going to deploy your business card using

3:19:40

this technique. The first thing you need

3:19:42

to do is head over to GitHub. If you're

3:19:44

watching this course on Scribba, you can

3:19:46

just click on this slide right here. But

3:19:48

if you're following us on YouTube, just

3:19:50

head over to github.com and you'll get

3:19:52

to the exact same page. Once you're

3:19:54

there, I want you to click at the sign

3:19:56

up button. That'll open up a form where

3:19:58

you have to add your email, create a

3:20:00

password, and also choose a username.

3:20:03

Once you've done all of that, click the

3:20:04

continue button, which then sends you to

3:20:06

this onboarding screen where you can add

3:20:08

a little bit of information about

3:20:09

yourself or just click on the skip

3:20:11

personalization option if you are

3:20:13

impatient. Once you've done this, you'll

3:20:15

see a dashboard. Yours is probably not

3:20:18

as filled with information as mine,

3:20:20

though that doesn't matter. What we're

3:20:21

going to do now is click on the plus

3:20:23

icon in the top right corner. There it

3:20:25

opens up a menu where you are to choose

3:20:27

new repository. The repository is the

3:20:30

backbone of any software project. This

3:20:32

is where you'll find all the project

3:20:34

files and GitHub along with the git

3:20:36

protocol takes care of tracking all the

3:20:39

changes that has been done to the

3:20:41

repository from its birth. Though we're

3:20:43

getting ahead of ourselves right now. We

3:20:45

are just going to give it a name which

3:20:46

you type in here in the repository name

3:20:48

field like that. I'm going to call it

3:20:50

business card. And then I'm not going to

3:20:52

touch any of the options here. I'm just

3:20:54

going to scroll down and click create

3:20:56

repository. And there we go. Now, we

3:20:58

have to upload our files. We can do that

3:21:00

in many different ways. Right now, we're

3:21:03

just going to do the very simplest one.

3:21:05

So, what I want you to do is click on

3:21:06

the uploading an existing file link

3:21:09

right here as that'll take you to a drag

3:21:11

and drop field quite similar to what we

3:21:13

saw at Netlefi earlier. Here, I want you

3:21:15

to open up the business card folder

3:21:18

which you created on your local computer

3:21:20

in the previous scrim. Mark all of the

3:21:22

files and then just drag and drop them

3:21:25

into the rectangle at GitHub. Once

3:21:27

you've done that, you'll see all of your

3:21:28

files listed. Just scroll a little bit

3:21:30

down and then we have to do something

3:21:32

called commit changes, which might seem

3:21:34

a little bit weird and complicated, but

3:21:36

don't worry about that right now. I'm

3:21:38

just going to go with the recommended

3:21:40

text, add files via upload, and then hit

3:21:43

commit changes. And boom, there we go.

3:21:46

We have a repository on GitHub which

3:21:49

includes all the code we need for our

3:21:51

business card. Now, if you were to

3:21:53

collaborate with other developers on

3:21:55

this project, they would push their code

3:21:57

up to this specific repository. And you

3:21:59

would also probably create issues for

3:22:01

tasks you want to do and work with

3:22:03

something called pull requests, which is

3:22:05

when you want to merge someone's changes

3:22:07

into the codebase. And there's also a

3:22:09

ton of other things you can do here, but

3:22:11

we're not going to worry about any of

3:22:12

that right now because the only thing we

3:22:14

want to use this repository for right

3:22:16

now is as an intermediate step before

3:22:18

our deployment. So let's head over to

3:22:21

Netlefi and make sure you're logged in

3:22:23

so that you see the previous project we

3:22:25

deployed. And right besides it, you can

3:22:27

see this button called add new site.

3:22:29

Click on it and choose import an

3:22:31

existing project. Here you're able to

3:22:33

choose GitHub. Click on that and it'll

3:22:35

open this pop-up menu where GitHub asks

3:22:38

where you want to install Netlefi

3:22:39

because that's what you're doing now.

3:22:41

We're installing Netlefi on our GitHub

3:22:43

profile. Click on your GitHub username.

3:22:45

In my case, Pier Borgan. And here I'm

3:22:47

just going to leave all the settings as

3:22:49

they are. Scroll down and hit install.

3:22:51

And there we go. Now you can see that

3:22:53

Netlefi has pulled in your GitHub

3:22:56

profile and has your repositories

3:22:58

listed. I have a bunch of repositories,

3:23:00

so I'll have to search for the business

3:23:01

card. I'll write business. And there we

3:23:03

can see it. When I click on this

3:23:05

repository, it is imported into Netlefi.

3:23:07

And here I can adjust some settings, but

3:23:09

I'm not going to do any of that as

3:23:11

usual. Just scroll down to the bottom

3:23:13

and hit deploy site. And there we go.

3:23:16

The deployment is now in progress. So

3:23:17

we'll have to wait a little bit. And

3:23:19

then once this image turns into a

3:23:21

screenshot of your site, it is deployed.

3:23:24

So clicking on this link will open up

3:23:26

our business card. Really good job

3:23:29

though. I hope your business card looks

3:23:31

a lot cooler than this as you were to

3:23:33

personalize it in the previous scrim.

3:23:36

Actually, to prove to me that you did

3:23:38

personalize this, I want you to head

3:23:40

over to Twitter and share your deployed

3:23:42

business card. Do as Michael the Rocket

3:23:44

does here and mention me if you want to

3:23:46

alongside a link to your project and

3:23:48

perhaps even a screenshot of it. That

3:23:50

would be super cool. So, go ahead and do

3:23:52

that right now and then I'll see you in

3:23:54

the next scrimm.

3:23:58

Hi there, my name is Bob Zerroll and I'm

3:24:00

another teacher here at Scribba. You

3:24:02

just learned a little bit about how to

3:24:04

use GitHub to deploy your project to

3:24:06

Netlefi. I thought this might be a good

3:24:08

opportunity for us to dive a little bit

3:24:10

deeper into the differences between Git

3:24:12

and GitHub. This is going to be a little

3:24:15

bit more surface level just so that we

3:24:17

have a solid understanding of the

3:24:18

difference between the two. So, we're

3:24:20

not going to be really diving into the

3:24:21

weeds with either of these things quite

3:24:23

yet. To better understand them, let's

3:24:25

look at the differences between the two.

3:24:27

First, we'll start with Git. Git is

3:24:29

what's called a version control system.

3:24:31

We'll talk pretty soon about what

3:24:32

exactly that means, but it's important

3:24:34

to know that Git is something that runs

3:24:36

locally on your own machine. If your

3:24:38

machine didn't come with Git already

3:24:40

pre-installed, then it is something that

3:24:42

you would have to download and install

3:24:44

on your machine in order to use. And its

3:24:46

main task is to help us keep a history

3:24:48

of the changes that we've made to our

3:24:50

projects. In contrast, GitHub is an

3:24:53

online platform that stores something

3:24:55

called Git repositories. The term

3:24:58

repository is just kind of a fancy way

3:25:00

to say a folder of your code that you

3:25:02

have been tracking the changes of in

3:25:04

Git. In contrast with Git, which runs

3:25:07

locally on your own machine, GitHub runs

3:25:09

online in the cloud. And where Git's

3:25:12

main task is to keep track of a history

3:25:14

of the changes you've made to your

3:25:15

project, GitHub is a way for one to

3:25:17

share your code and that history of the

3:25:20

changes from Git with other people.

3:25:22

Maybe an imperfect but illustrative

3:25:24

analogy is Git is kind of like taking

3:25:27

photos on your phone or your camera,

3:25:29

which happens locally on your own

3:25:30

device. And GitHub is kind of like an

3:25:32

online photo sharing platform like

3:25:34

Instagram. It's not a perfect example,

3:25:37

but it does highlight some of the main

3:25:38

differences between Git and GitHub.

3:25:41

Okay, we talked about version control.

3:25:43

So, what exactly is version control? The

3:25:45

main thing that version control provides

3:25:47

for us is a way for us to create save

3:25:49

points, which in Git are called commits

3:25:51

of your code so that you can revert back

3:25:53

to them if needed. These save points or

3:25:55

commits aren't something that actually

3:25:57

alters the content of your code itself.

3:25:59

This information is saved in kind of a

3:26:01

separate hidden folder inside of your

3:26:03

project that is using git, but it

3:26:05

provides you a way that if let's say you

3:26:07

were to write some kind of bug into your

3:26:09

code or accidentally delete everything

3:26:11

and then close your editor that you

3:26:13

couldn't just undo those changes with a

3:26:15

git commit, we can revert back to that

3:26:17

commit and have everything restored the

3:26:19

way that it was at that save point. This

3:26:22

reminds me of the most difficult level

3:26:24

of any video game I've ever played in my

3:26:26

life. If you know, you know. And I

3:26:28

probably would have enjoyed this game a

3:26:30

lot more if I had the ability to create

3:26:32

safe points along the way that I could

3:26:33

go to every time I died or failed.

3:26:36

Another major benefit of version control

3:26:38

is that it manages changes made by other

3:26:40

people that are also working on the same

3:26:42

codebase by giving us a means to merge

3:26:44

multiple different versions of the same

3:26:46

codebase together and fix any of the

3:26:48

resulting conflicts. If you've ever

3:26:50

worked on a group paper and well, you're

3:26:53

old enough, you might be familiar with

3:26:55

this phenomenon. As different people are

3:26:57

working on their own parts of the paper,

3:26:59

you would end up emailing the paper back

3:27:01

and forth and you had to come up with

3:27:03

unique names. And then you'd have to

3:27:04

have someone in the group who was an

3:27:06

editor and could take all of these

3:27:08

different versions and merge them

3:27:09

together into one version that became

3:27:11

the final paper the group would turn in.

3:27:13

In the end, it just becomes a huge pain.

3:27:15

And this is something that version

3:27:17

control helps us mitigate. Now, this

3:27:19

isn't to say that you won't have two

3:27:21

people that make, let's say, a change to

3:27:23

the same line of code, but in different

3:27:25

ways, but rather git as a version

3:27:27

control system gives us a way to

3:27:29

highlight those changes and decide which

3:27:31

one of those changes we want to include

3:27:33

in the final codebase. In the end,

3:27:35

version control generally allows us to

3:27:37

be less worried about making any

3:27:39

mistakes or having our code conflict

3:27:41

with other people that are working on

3:27:42

our same project. Okay, so this is

3:27:44

version control with Git. Let's now

3:27:46

switch over and start talking about

3:27:48

GitHub. GitHub is a cloud-based SAS

3:27:51

product. As a SAS product, a few years

3:27:53

ago, it was purchased by Microsoft. And

3:27:55

its main feature is that it gives us a

3:27:57

way to share our code and the changes

3:27:59

that were made to our code with those

3:28:01

commits in Git with other people. As the

3:28:03

name would imply, it assumes that we're

3:28:05

using Git as our version control system.

3:28:08

As a side note, there are other version

3:28:10

control systems, but you'll see Git used

3:28:12

far far more commonly than any other

3:28:14

version control system out there. As a

3:28:16

feature of GitHub, they have integrated

3:28:18

a number of Git-based capabilities right

3:28:20

into the website. Things like

3:28:22

committing, merging, branching, and so

3:28:24

forth. You don't need to know what those

3:28:25

operations are per se, but it does

3:28:27

contribute a little bit to the blurring

3:28:29

of lines between Git, the version

3:28:31

control system, and GitHub, the

3:28:32

cloud-based SAS product, which contains

3:28:34

Git repositories. Personally, I think

3:28:37

it's really important for beginners to

3:28:39

become familiar with and start using Git

3:28:41

and GitHub from an early point in their

3:28:43

learning. But I do think there is a more

3:28:45

approachable way to do this and that's

3:28:46

by using a product from GitHub called

3:28:49

GitHub Desktop. This is a native desktop

3:28:51

application that you can download from

3:28:53

the GitHub website and it allows you to

3:28:55

perform git operations on Git

3:28:58

repositories on your local machine and

3:29:00

in a pretty seamless way push those

3:29:02

changes up to GitHub where they can be

3:29:04

shared with other people. If you're

3:29:06

interested in learning more now about

3:29:07

GitHub Desktop, you can click the

3:29:09

screenshot you see here. That will take

3:29:11

you to another scrim that's in a future

3:29:13

module here on Scribba, which is taught

3:29:15

by Treasure. Using GitHub Desktop might

3:29:17

not be as hardcore as a senior developer

3:29:20

who's using Git from the command line.

3:29:22

But with how powerful and therefore

3:29:24

complex Git is, the learning curve can

3:29:26

be a little bit steep. And I think

3:29:27

GitHub Desktop is a great approachable

3:29:30

way to begin using and understanding

3:29:32

Git. Either way, congratulations on

3:29:34

deploying your business card. That

3:29:35

really is a huge feat and as P said,

3:29:38

it's something that should be shared

3:29:39

with the world. All right, that's it

3:29:40

from me for now, but I'm sure we'll run

3:29:42

into each other in another lesson here

3:29:44

on Scribba. Bye for now.

3:29:49

No matter how much you ended up

3:29:50

personalizing your business card, I want

3:29:52

to say well done. You reached the end of

3:29:55

this section, so give yourself a pat on

3:29:57

the back. You deserve it. And let's now

3:30:00

have a look at what you learned at the

3:30:02

beginning of this section. You learned

3:30:03

about alt text on images, which is

3:30:06

really important for accessibility. And

3:30:08

then you learned about child containers

3:30:10

in flexbox because we created this card

3:30:13

as a flexbox container and made sure

3:30:15

that it only had two direct childrens.

3:30:18

So that these two got their own columns

3:30:21

and then inside of the second column you

3:30:23

could add things on rows again, which is

3:30:25

what we did here. That concept of only

3:30:28

the direct children being the flex items

3:30:30

and then turning these children into

3:30:32

containers again is a critical thing to

3:30:34

understand in order to create

3:30:36

sophisticated flexbox layouts. Moving

3:30:38

on, you learned more about inheritance.

3:30:41

This is something you had been exposed

3:30:42

to before. But hopefully you have a more

3:30:44

conscious relationship to this right now

3:30:46

as you understand how setting the text

3:30:48

align on the card div that is this one

3:30:51

right here makes that property applied

3:30:53

to these elements as well as they

3:30:56

inherited the text align center from the

3:30:58

grandparent that is the div up here. You

3:31:01

also learned about shorthands and more

3:31:03

specifically the margin and padding

3:31:05

shorthands. Here we're setting the

3:31:07

margin to zero at the top and bottom and

3:31:10

auto at left rightight. And it is a lot

3:31:12

more compact than writing out margin

3:31:13

top, left, right, and bottom all on

3:31:16

their own lines. Another thing you

3:31:17

learned about was web safe fonts, which

3:31:19

we used up here in the body where we

3:31:21

used Verdonna, which is one of those

3:31:23

fonts you can use without worrying about

3:31:25

whether or not it's installed on your

3:31:27

users computers because most likely it

3:31:30

is. And then a really important concept

3:31:32

in web design is color palettes. We took

3:31:35

a look at that and hopefully you found

3:31:36

your own palette so that you

3:31:38

personalized your business card because

3:31:40

colors really do make or break a design.

3:31:43

So that was quite a lot of concepts. You

3:31:46

should be really proud of yourself

3:31:47

reaching this far. Now it's time for you

3:31:49

to take a break so that these concepts

3:31:51

mature in your mind and do whatever you

3:31:53

need to recharge your batteries and then

3:31:55

I'll see you back here in the next

3:31:57

section.

3:32:01

Welcome to the section where you are

3:32:03

going to build a space exploration site.

3:32:06

Here is the example you're going to

3:32:07

build. As you can see, it has this super

3:32:09

neat background image that animates and

3:32:12

that really breathes life into the site.

3:32:14

We're also using Google Fonts to pull in

3:32:16

this custom spaceish font right here.

3:32:19

And we're doing a lot of interesting

3:32:20

things with some subtle text shadows,

3:32:23

this underline, and more. So, there will

3:32:25

be plenty of new things to learn in

3:32:27

addition to reinforcing HTML and CSS

3:32:30

concepts you've previously learned. So,

3:32:33

let's launch into this section.

3:32:38

Okay, let's get started building our

3:32:39

space exploration site. As you can see,

3:32:42

I've set up a basic HTML structure for

3:32:44

you here. It is very simple as the body

3:32:47

simply contains an H1 title and a

3:32:49

button. As for the CSS, there is no as

3:32:51

we are going to add that now. So, the

3:32:53

first thing we're going to do is fix the

3:32:55

background here because we don't want

3:32:57

the white background. We want to have an

3:32:59

image of the universe in the background.

3:33:01

Later down the line, we're going to

3:33:02

change that to an animated image so that

3:33:04

it looks like a video playing in the

3:33:06

background, which is even cooler. But,

3:33:08

as for now, we're just going to do a

3:33:10

standard background image as we're going

3:33:12

to work on this for a while and I don't

3:33:13

want to have an animated image looping

3:33:15

in the background as we work as I think

3:33:17

that's a little bit annoying. So, let's

3:33:19

start out with just a static background

3:33:21

image. And just so you know, background

3:33:23

images is something different than how

3:33:25

you've used the images up until now

3:33:27

where you've done img, src, some kind of

3:33:30

JPEG like that. Instead, background

3:33:33

images are not in the HTML. They are

3:33:36

added in the CSS file. Enough talk about

3:33:38

that. Let's just find a cool background

3:33:40

image and then deal with how to

3:33:42

implement it into our app. And the

3:33:44

service I prefer to use for finding cool

3:33:46

images for your web design is Unsplash

3:33:49

because the quality of images here are

3:33:51

really good. So they will take your web

3:33:54

design to new heights and you can use

3:33:56

them freely however you want. So if I

3:33:59

search here for universe, we'll get a

3:34:02

ton of nice images. Let's scroll a bit

3:34:04

down. As you can see, there's plenty of

3:34:05

good candidates here, but I think this

3:34:07

one is particularly nice. So I'm going

3:34:09

to click in on it. It is created by

3:34:11

Gilmo Furla and you can see it's really

3:34:13

popular have over 12 million views

3:34:15

already. Now if we want to download this

3:34:17

you can click on the icon up here and

3:34:20

download it range of different sizes and

3:34:22

I've actually done that and placed it

3:34:24

here in the images folder. So here you

3:34:26

can see universe.jpeg.

3:34:28

So let's see how we can add this to our

3:34:30

app. What I'm going to do is target the

3:34:33

body because we want the image to span

3:34:35

across the entirety of our page. So we

3:34:37

need to add the background image to the

3:34:39

body. We'll use the background image

3:34:42

property. And here we'll utilize

3:34:44

something called a CSS function. Don't

3:34:46

worry about why it's called a CSS

3:34:48

function. Just remember that the way to

3:34:50

do it is by writing URL open parenthesis

3:34:53

and then inside of the parenthesis you

3:34:55

refer to the image source just as you do

3:34:58

in the image with the img tag. It is

3:35:01

using quotes. So inside of the quotes,

3:35:04

we'll write the path to this exact

3:35:06

image. And the way we do that is first

3:35:08

by navigating to the images folder. So

3:35:11

images then slash going into the folder

3:35:13

choosing the universe

3:35:17

JPEG. And boom, there we go. Suddenly

3:35:19

our background changed. However, there's

3:35:21

a couple of problems here. Our H1 is now

3:35:24

almost invisible since by default the

3:35:26

text is black and the background is very

3:35:28

black as well. So I'm going to change

3:35:30

the color to white. Like that. Much

3:35:34

better. Also, this image is thousands of

3:35:37

pixels wide, whereas our browser is not

3:35:40

that wide. So, notice that if we make it

3:35:42

super wide, we still only see the edge

3:35:44

of the galaxy more or less the center of

3:35:46

the image. So, what we need to do is

3:35:50

shrink our browser down to like a couple

3:35:52

of hundred pixels wide, which is what we

3:35:53

want. And then make our background image

3:35:57

shrink so that it's squeezed into the

3:35:59

width of this browser. The way we do

3:36:02

that is background size

3:36:05

and the value cover. Boom. There we go.

3:36:09

Now the width of the background image is

3:36:12

exactly as the width of its container

3:36:15

which again is exactly as wide as the

3:36:17

browser itself. Meaning that the browser

3:36:20

and the background image has the exact

3:36:22

same width. And it looks pretty good.

3:36:24

I'm not going to give you a challenge on

3:36:26

how to do this right now as you'll get

3:36:28

plenty of practice using background

3:36:30

images later in this course. So, with

3:36:32

that, let's just move on to the next

3:36:34

scrim.

3:36:38

Okay. In this two-part challenge, you're

3:36:40

going to improve the design of our app.

3:36:42

First, I want you to center the text and

3:36:44

button and then style the button

3:36:47

according to the provided design. And

3:36:49

that is found here in the slide. As you

3:36:51

can see, the button is slightly

3:36:53

different from how it is right now. Not

3:36:56

too different, but certainly it has some

3:36:58

CSS properties applied. And I'm not

3:37:01

going to tell you which because this is

3:37:02

a good way for you to train your design

3:37:04

eye. When you design the button, I want

3:37:06

you to use a class in order to select

3:37:08

it. So, not just using an element

3:37:10

selector like we do here. So, go ahead

3:37:13

and give this a shot and then I will

3:37:14

show you the solution as well when you

3:37:16

return back to me.

3:37:24

Okay, let's do this. First, we got to

3:37:26

center the text on the button. And here

3:37:28

you can use a range of different

3:37:30

options, either using margins or flexbox

3:37:33

or text align. You've learned plenty of

3:37:36

ways to center elements. Now I'm going

3:37:38

to choose the easiest one which is to

3:37:40

apply a text align center in the body

3:37:43

element because as you know this centers

3:37:46

not only the H1 but also buttons. Okay,

3:37:50

with that out of the way, let's move on

3:37:51

to the button. First I want to give it a

3:37:54

class and I think btn is a good class

3:37:56

name. So let's add it to the HTML as

3:37:59

well like that and run the code. So we

3:38:01

have it applied in the DOM. Now let's

3:38:04

have a look at this design. The first

3:38:06

thing that is apparent to me is that

3:38:08

this button has more space around the

3:38:11

text. As you can see here, it's a bit

3:38:13

more crammed. So that is the padding

3:38:15

property.

3:38:17

Let's try 10 pixels just on all four

3:38:20

sides of the padding. Having a look at

3:38:22

this button right now, you can see that

3:38:26

this one is a bit more rectangular

3:38:28

whereas this one is a bit more squared.

3:38:30

Now, cuz in this design here, there's

3:38:33

more space on the left and right hand

3:38:35

side than the top and bottom. And if you

3:38:38

remember the short hand, we can do this

3:38:40

by, for example, starting with five

3:38:42

pixels on the top and bottom and 10

3:38:45

pixels on the left and right. And that

3:38:48

looks much better. Maybe it's a little

3:38:51

bit higher. So, let's do six and 12.

3:38:55

That looks pretty good to me. Now, the

3:38:58

next thing I want to change is the

3:39:00

background color. It's not totally

3:39:02

apparent, but actually, this one has a

3:39:04

white background color, whereas this one

3:39:07

has the default button background color,

3:39:09

which is a bit grayer. It's not that

3:39:11

easy to see because of the background

3:39:13

here. It looks pretty white compared to

3:39:15

the black background, but it is actually

3:39:17

not entirely white. something you'd know

3:39:19

if you've worked with buttons in HTML

3:39:21

for a while as they always have a

3:39:23

default grayish background color

3:39:26

background white like that. Okay, now it

3:39:31

suddenly became apparent that it also

3:39:33

has a border in this default styling

3:39:35

whereas that's not the case in our

3:39:37

provided design. So let's do border. We

3:39:41

can do none like that. And with that, it

3:39:44

looks like we have completed our design

3:39:46

as these two look identical as far as I

3:39:48

can see. So, really good job. Let's move

3:39:51

on.

3:39:55

Okay. Now, you're going to get a new

3:39:57

superpower in your tool belt called

3:40:00

Google Fonts. And that is a service that

3:40:02

gives you access to over a thousand

3:40:04

different highquality fonts that you can

3:40:07

use in your projects. And the reason you

3:40:09

need to learn about this now is because

3:40:11

the font we have here isn't good enough

3:40:13

in my opinion. It is a little bit boring

3:40:16

for a space project. What we want

3:40:18

instead is something like this, which

3:40:20

looks a lot more sci-fiish. However,

3:40:23

this font isn't one of the so-called

3:40:25

websafe fonts you learned about earlier,

3:40:27

which is already installed in most

3:40:29

operating systems. This is a very custom

3:40:31

font. So, we have to use Google fonts in

3:40:34

order to bring it into our project. And

3:40:37

here you can see the Google fonts

3:40:38

interface. It's located at

3:40:39

fonts.google.com.

3:40:42

And if we scroll a bit down, you can see

3:40:43

it contains a range of very different

3:40:45

fonts. Now, it has a search feature up

3:40:48

in the top left corner, but it's

3:40:50

actually not that good to be honest.

3:40:52

It's better to just use regular Google

3:40:54

search when searching for Google fonts.

3:40:57

So, let's do that instead. The way I

3:40:59

found the font we're going to use now is

3:41:01

just by googling sci-fi and then Google

3:41:03

font. And then Google suggested this

3:41:05

Orbitron font. So if we click into it,

3:41:08

you can see here it is. If we scroll a

3:41:10

bit down, you can see we have to choose

3:41:12

specifically which styles we want. So

3:41:15

I'm going to choose this 400 regular

3:41:17

style by clicking on select this style

3:41:20

like that. And you can see the panel on

3:41:22

the right hand side. And it is clear

3:41:24

that we have chosen the orbitron font

3:41:26

and the regular 400 font weight. Also,

3:41:30

let's click on this extra bold in case

3:41:32

we want to bold some text on our site.

3:41:34

And there we have that one as well. Now,

3:41:36

if we want to use this on the web, we

3:41:38

can embed it by simply copying a piece

3:41:41

of code into the head of our HTML. And

3:41:43

that is the code you want to copy and

3:41:46

then paste it in exactly here. Next up,

3:41:50

we also have to specify it in our CSS.

3:41:52

That's done by pasting this line into

3:41:56

our CSS, for example, in the body tag.

3:41:59

I'm not going to do this for you,

3:42:00

though. Scribba is all about you doing

3:42:03

things on your own, getting your hands

3:42:05

on the keyboard. So, now I want you to

3:42:07

head over to Google Fonts, fetch the

3:42:09

Orbitron font in these two styles, and

3:42:12

then do whatever you need to do in order

3:42:14

to make the Orbitron font render

3:42:15

properly on our site. I'm going to leave

3:42:18

you here with this screenshot because

3:42:20

make sure to compare this design with

3:42:24

what you get in the mini browser because

3:42:26

there might be something you need to do

3:42:28

down in the btn selector. And hopefully

3:42:30

you're able to spot that. If not, no

3:42:32

worries cuz I'll be here showing you the

3:42:34

solution when you return back to me.

3:42:36

Good luck.

3:42:44

Okay, let's do this. So, first we're

3:42:48

going to take this snippet of code right

3:42:49

here and then paste it into our HTML

3:42:52

like that. Then need to run the code so

3:42:55

that it is imported into our project.

3:42:58

And then next up, it is the styles which

3:43:00

we're going to set here. Let's copy that

3:43:03

line of code. And then simply paste it

3:43:05

in right here. And boom. Join the

3:43:08

exploration now looks like our project

3:43:11

right here. However, this one also has

3:43:14

the Orbitron font applied to the button,

3:43:17

but we don't have that. We still use

3:43:19

that boring old font that we had

3:43:20

previously. Why is that? Well, that's

3:43:23

actually because buttons don't inherit

3:43:26

font families. So, here the H1 has

3:43:29

inherited the font property from body,

3:43:31

but the button has not. So, what we need

3:43:34

to do here is specifically tell the

3:43:36

button to have this font family. And we

3:43:39

can do that in two ways. One way is

3:43:42

through using a CSS value you haven't

3:43:44

learned yet, and that is the inherit

3:43:47

keyword. As you can see, now it does

3:43:50

inherit from the body, but only because

3:43:52

we've specifically told the button to do

3:43:54

exactly that. What I'm assuming you did

3:43:56

instead, which works perfectly fine as

3:43:58

well, is simply to paste in the font

3:44:00

family orbitron on the btn class. As you

3:44:03

can see, that also works well. So,

3:44:06

hopefully you were able to spot this. If

3:44:08

not, no worries. It was just a little

3:44:10

gotcha I left here. Let's move on to the

3:44:12

next scrim.

3:44:16

Before we move on from the subject of

3:44:18

fonts, there's one more technique I want

3:44:20

to teach you. Because in some cases,

3:44:22

Google fonts might actually not be

3:44:24

enough. And that's typically the case if

3:44:26

you want very specific fonts. For

3:44:28

example, let's say that you are building

3:44:30

a Godfather website in honor of the

3:44:32

classic film. Well, in that case, you'd

3:44:34

probably want to get a hold of the real

3:44:36

Godfather font. though Google Fonts

3:44:39

doesn't host that one because it is

3:44:41

simply too specific for them to care

3:44:43

about. So you'd most likely have to find

3:44:46

this font somewhere on the worldwide

3:44:48

web. And there are great services for

3:44:50

this. For example, a 101font.com

3:44:53

there. If you search for Godfather, they

3:44:55

actually have it. So you can click into

3:44:57

it, scroll a little bit down and click

3:44:59

download. So what you then did is kind

3:45:01

of downloaded the recipe for the font.

3:45:04

And if you open up the folder you got,

3:45:05

you'll see a TTF file. That's a file

3:45:08

format for fonts. What you then can do

3:45:11

is simply drag and drop that file into

3:45:14

your file system like I have done right

3:45:16

here. You can see I have the

3:45:17

cordoneion.ttf

3:45:19

file. Now what I can do is use the at

3:45:21

font face rule in CSS. So simply writing

3:45:24

an at and then font-face and then open

3:45:27

up the curly brackets and write two

3:45:29

properties. The source which should use

3:45:31

the URL technique pointing to the TTF

3:45:34

file which I'm doing right here. And

3:45:36

also I need to tell CSS what name I want

3:45:39

to give this font in my stylesheets. And

3:45:41

I'm just going to choose Corleona for

3:45:43

now. But I could have chosen whatever

3:45:44

name I wanted. Now I'm able to target

3:45:47

the H1 and use this font family. So I'll

3:45:50

do font family

3:45:53

or Leona. And there you can see I have

3:45:55

the Godfather font. So I'm off to a

3:45:57

great start on my tribute page. So now

3:45:59

what I think you should do is actually

3:46:01

try and do this yourself. Find a random

3:46:03

font online, download it so that you get

3:46:05

a hold of the TTF file, drag and drop

3:46:08

that TTF file into the file system here

3:46:10

on Scribba and use the add font face

3:46:12

property to make that font available in

3:46:14

your stylesheets. Once you've done that,

3:46:16

I will see you in the next scrim.

3:46:21

Now you are going to learn about the

3:46:23

span tag because in the next scrim you

3:46:25

are going to create an underline under

3:46:27

the exploration word and in order to

3:46:29

achieve that you need the span tag. So

3:46:32

let's take a little step back from our

3:46:34

space exploration site and learn all

3:46:36

about this awesome tag. The example

3:46:39

we're going to use in order to learn the

3:46:40

span tag is of banner ads. You've

3:46:43

probably seen these before. You've

3:46:45

browsed the web, for example, on news

3:46:47

sites. And many of these are actually

3:46:49

so-called HTML 5 ads where they are

3:46:51

built using HTML and CSS. And it's

3:46:55

actually a little bit sad how many

3:46:56

clever developers in this world who are

3:46:59

spending all of their time in their best

3:47:01

years and getting more people to click

3:47:02

on these ads through making them more

3:47:05

invasive, more eye-catching, and more

3:47:07

targeted. But that's the name of the

3:47:10

game. So, we just have to accept it. And

3:47:12

you are now going to do exactly that.

3:47:14

you are going to make this ad more

3:47:16

eye-catching so that hopefully more

3:47:18

people click on it and visit our scammy

3:47:20

casino. So, how do we do this? Well,

3:47:23

looking at the HTML, you can see the div

3:47:26

wrapper has a class of ad which sets the

3:47:28

background color, border, and the text

3:47:30

alignment inside of this green

3:47:32

rectangle. And there are two elements

3:47:34

inside of the ad. It is the H1 and the

3:47:36

H3. And it says click here. So, what we

3:47:40

want to do is make this hair word pop

3:47:43

out more. So how do we do that? We can't

3:47:45

target the H3 itself because that'll

3:47:47

style the entire sentence. We only want

3:47:50

to style this word. And this is where

3:47:52

spans come in. Here we can write span

3:47:55

like that. Open the tag before the word

3:47:57

and close it directly afterward. If we

3:48:00

now run this code, seemingly nothing has

3:48:02

happened because spans are invisible

3:48:04

unless you give them styling. So they're

3:48:07

kind of like the div as divs neither

3:48:09

provide any styling unless you give it

3:48:11

to it specifically. Although the

3:48:13

difference is that spans are in line

3:48:15

whereas divs are block based. So to

3:48:18

demonstrate that if we change this to a

3:48:20

div. What would happen if we run the

3:48:23

code is that it would break the hairword

3:48:25

onto a new line because divs are display

3:48:28

block. They take up all the available

3:48:30

space in the width. Where spans do not

3:48:33

do that. Only take up the space they

3:48:35

need in order to make room for this

3:48:37

content. What we now can do is give this

3:48:40

span a class. I'm going to call it CTA.

3:48:44

That's short for call to action as

3:48:46

that's normally what these kinds of

3:48:47

elements are called. And in the CSS,

3:48:50

we'll do CTA. Let's just see that it

3:48:53

works by doing color red. Yes, there we

3:48:57

can see we have now only targeted the

3:48:59

here word. This doesn't look

3:49:00

particularly good though. So, let's

3:49:02

instead do something that makes it look

3:49:04

a bit more like a button. For that, we'd

3:49:07

need a border in my opinion. For

3:49:08

example, 2 pixels. And we want it to be

3:49:10

solid. And here, let's steal the color

3:49:13

from the border around the ad so that we

3:49:16

reuse it a little bit. I think that can

3:49:18

look nice. Yeah. Okay. Here you can see

3:49:20

that it it's added a border around the

3:49:22

word. It is very crammed on the left and

3:49:25

right hand side. So, let's try to add

3:49:26

some padding. Let's just do five pixels

3:49:29

or something. Actually, I think we can

3:49:31

do five pixels on the top and 10 pixels

3:49:34

on the left and right. Yeah, that looks

3:49:36

much better. and then to make it pop out

3:49:38

even more so that it doesn't blend into

3:49:41

the overall background we have on the ad

3:49:43

itself. So I'm going to do background.

3:49:46

Now I happen to have a nice brown color

3:49:48

here which I think looks decent with the

3:49:51

other colors here. So now it is a lot

3:49:55

more easier to see that you are going to

3:49:56

click here on this thing that looks like

3:49:58

a button as it stands out more. And

3:50:00

hopefully we have increased the

3:50:02

click-through rate with 0.02% 02% and

3:50:05

thus made our boss really happy. So,

3:50:08

great job. Now that you've learned this,

3:50:10

let's return back to the space

3:50:12

exploration site and put your new skills

3:50:14

to the test.

3:50:18

Okay, now you're going to create this

3:50:20

neat little underline under the

3:50:22

expiration word. And I want you to do

3:50:25

that using a span and a class. as for

3:50:29

the specific design of the underline and

3:50:32

what kind of CSS property you are to

3:50:33

use, that is something you'll have to

3:50:35

figure out on your own. So, go ahead and

3:50:37

give this a shot. Good luck and I'll see

3:50:39

you on the other side.

3:50:44

Okay, hopefully that went well. Let's do

3:50:47

it. I'm going to start with adding this

3:50:49

span to the HTML. It should wrap the

3:50:52

exploration word. So, span like that.

3:50:56

And then I'm going to give it a class.

3:50:58

I'm going to call this class underline

3:51:00

because it'll only have one job and that

3:51:02

is to give the expiration word the

3:51:04

underline. So this class is something

3:51:05

we've talked about earlier. It's a

3:51:07

utility class. It only has one job and

3:51:09

that is setting a single CSS property.

3:51:12

So if we run the code now, nothing has

3:51:14

seemingly happened. But we do have this

3:51:16

in our DOM, meaning we can select it in

3:51:19

the CSS. We'll do dot underline like

3:51:23

that. Let's just try and set the color

3:51:25

to red to see that it works. And yes, it

3:51:27

does indeed work. But that's not the

3:51:30

effect we want. We want to set the

3:51:32

underline. And what is this underline?

3:51:35

Well, it's actually just a border

3:51:37

bottom. We do border bottom like that. 2

3:51:41

pixels solid

3:51:45

white. You can see yes, we indeed get a

3:51:47

border under it. However, this border

3:51:51

looks a little bit thicker. So, I don't

3:51:52

think 2 pixels is the correct thickness.

3:51:54

I think we want to have something like

3:51:56

four. Yes, that looks pretty good to me.

3:52:00

So, we have solved this challenge and we

3:52:03

are ready to move on.

3:52:07

Okay, now we are going to add this

3:52:09

SpaceX logo at the top here. And while

3:52:12

you're adding it, you're going to learn

3:52:13

a whole new concept in HTML and CSS,

3:52:17

namely a close cousin of the class

3:52:19

attribute, which is called the ID

3:52:22

attribute. And the way to use it is

3:52:25

simply by writing ID instead of class.

3:52:27

But now you're probably wondering why

3:52:29

would we use this ID? If we now try to

3:52:32

rerun this code, you can see that our

3:52:35

underline is gone. And that is because

3:52:38

when you are using an ID like this, you

3:52:41

have to refer to it in the CSS not by

3:52:44

using a dot but instead by using a

3:52:46

hashtag. There you can see now our

3:52:48

border bottom is again applied to our

3:52:51

example. So now you're probably

3:52:52

wondering, well, why would we want to

3:52:54

use this? It just further complicates

3:52:56

things by having both ids and classes to

3:52:59

worry about. And the thing is they serve

3:53:01

two different scenarios. You should use

3:53:03

an ID if you know that your element is

3:53:06

unique and you'll only use it once. So

3:53:09

ID of underline should only be be

3:53:11

applied once in this entire document.

3:53:14

Whereas class is something you can reuse

3:53:16

again and again. It's meant for reusage.

3:53:19

So if you for example wanted a button

3:53:21

here that also said for example FAQ's

3:53:26

then a class is what you use in order to

3:53:28

make sure that this button has the same

3:53:30

styling as this button. But if you did

3:53:32

that with IDs and turned the btn here

3:53:35

into an ID, this would be invalid HTML.

3:53:39

Browsers are very forgiving. So it

3:53:41

probably would work technically. The

3:53:43

styling would be applied but you just

3:53:45

shouldn't do it. Now, as for this idea

3:53:48

of underline here, I actually don't

3:53:50

think it makes sense to use an ID

3:53:52

because this underline here could

3:53:54

perfectly fine be a part of our design

3:53:56

system and also be applied at multiple

3:53:59

other sections and paragraphs throughout

3:54:01

our entire page as we build out this

3:54:03

space exploration site. So, I want to

3:54:05

have the freedom to be able to reuse

3:54:07

this later as well, even though I'm only

3:54:10

using it once now. So, I'm going to turn

3:54:12

this into a class again. Rerun the

3:54:14

example. Now, it's not applied.

3:54:17

and then go from the ID selector to the

3:54:19

class selector in CSS by replacing the

3:54:21

hashtag with a dot. And there it is

3:54:23

applied.

3:54:24

So that was a long intro. The reason for

3:54:27

that was that I want you to render this

3:54:29

SpaceX logo. You can see I've added the

3:54:31

SpaceX.png

3:54:33

image file up here. And then I want you

3:54:36

to give it ID because this SpaceX logo

3:54:39

at the top here is most likely unique.

3:54:41

We probably don't want to have multiple

3:54:43

centered SpaceX logos at this size. So

3:54:46

this is kind of our main logo and you

3:54:48

can give it that ID main logo.

3:54:52

Then in the CSS you need to select the

3:54:54

logo using whatever ID you have given

3:54:56

it. Then as you'll see you'll have to

3:54:58

reduce its size. That's why you need

3:55:00

this CSS rule right here because it is

3:55:02

far too big this image. Finally I'm

3:55:05

going to remove this FAQ button so that

3:55:07

we're back to our original design. Now

3:55:09

it's your turn. Take over and try to

3:55:11

solve this challenge.

3:55:18

Okay, hopefully that went well. Let's do

3:55:21

it. We're going to render it using an

3:55:23

img tag and the source will be first

3:55:28

images and then slash

3:55:31

spacex.png

3:55:34

like that. If we run this, you can see,

3:55:36

oh wow,

3:55:38

that is not exactly what we were looking

3:55:40

for. It's far too big this image. So we

3:55:43

have to reduce its size. And to target

3:55:46

it, we're going to use an ID. And I'm

3:55:48

going to call this main logo like that.

3:55:51

Now if we head to the styles.css,

3:55:54

we'll do hashtag main- logo. And here we

3:55:58

have to reduce its width. So let's try

3:56:00

with for example

3:56:03

h perhaps this is 200 pixels. I don't

3:56:06

know. Let's try 200 px like that. That

3:56:10

was a bit too large in my opinion. So,

3:56:14

let's reduce it further to 100 pixels.

3:56:17

And yes, that is much more like our

3:56:21

design in my opinion. Looking pretty

3:56:24

good. So, with that, we have solved the

3:56:26

challenge. Great job.

3:56:31

Now, we're going to breathe some more

3:56:32

life into our example here because it

3:56:36

works fine with this static JPEG as the

3:56:38

background image, but wouldn't it be a

3:56:40

lot cooler if it was animated? So, you

3:56:42

could see the stars flying around. And

3:56:45

in our images folder, we now just happen

3:56:47

to have a file called galaxy.webp.

3:56:51

Hm. What's that? Let's just try to

3:56:54

replace this universe JPEG here with the

3:56:57

galaxy webp file.

3:57:00

So I'll do galaxy.

3:57:03

Webp and boom. The galaxy webp is an

3:57:06

animated image in which you see a bunch

3:57:09

of stars around the galaxy. And to me

3:57:12

this looks a lot cooler than what we

3:57:14

just had.

3:57:16

Now you might wonder what this web p

3:57:18

here is. And that is just an image

3:57:20

format pretty similar to so-called GIFs,

3:57:23

GIF. And GIF is what you recognize from

3:57:25

all over the web in animated images like

3:57:28

this one right here, which you've

3:57:29

probably seen before. So WEBP is used

3:57:32

exactly as GIFs are on the web. However,

3:57:34

it has a better compression. So it's

3:57:36

more compact and doesn't use as much

3:57:39

data as GIFs use when they're sent from

3:57:41

a server to a client. So we want to use

3:57:44

WEBP where we can. And now you might

3:57:47

wonder, well, where did you find this

3:57:49

galaxy.p image? That is on a site called

3:57:53

Gy. Giphy. That is a search engine for

3:57:56

GIFs. So, I just navigated to it,

3:57:59

searched for galaxy, scrolled a little

3:58:01

bit down, and found this neat looking

3:58:03

galaxy GIF here, created by the European

3:58:05

Space Agency. Now, this is a slideshow,

3:58:08

so you can't see that this GIF is now

3:58:11

being animated, but it actually is

3:58:13

because I just saved this image to my

3:58:15

local computer and then uploaded it to

3:58:18

the images folder right here. Now, if

3:58:20

you want, you can also click on the

3:58:21

share button here and click copy GIF

3:58:23

link. And then you can simply paste that

3:58:26

link into this URL. And then that'll

3:58:29

give, as you see, the exact same result.

3:58:32

But I prefer to rather use the version

3:58:34

which we've imported into our project

3:58:36

right here in case the gy file might

3:58:38

change at some point or something.

3:58:40

However, for experimentation purposes, I

3:58:42

think you should head over to GY, search

3:58:44

for a few images, and just paste them in

3:58:47

right here and see how that affects our

3:58:49

example. Just so you've got familiar

3:58:51

with using gy and pasting external URLs

3:58:54

into the background image property in

3:58:56

CSS. So, go ahead and do that and then I

3:58:59

will see you in the next scrim.

3:59:04

One thing I like to do when working with

3:59:06

images as backgrounds is to fetch colors

3:59:09

from the image and use it in the design

3:59:11

because that can often look pretty cool.

3:59:14

So, let me show you exactly how to do

3:59:16

that. We can use coolers, the service

3:59:18

you're already familiar with because if

3:59:20

you click on the more option in the

3:59:22

navbar, you can choose pick plet from

3:59:24

photo. That'll take you to this image

3:59:26

picker where you can choose an image by

3:59:28

clicking on the browse an image and

3:59:30

either upload the image or paste a URL

3:59:32

to it. Once you've done that, you're

3:59:35

taken to this nice tool where you can

3:59:38

either drag and drop this picker around

3:59:40

on the image until you find a color you

3:59:42

like or you can use this range input

3:59:45

here as that'll automatically try to

3:59:47

find interesting colors in the image for

3:59:49

you. And then it generates a palette as

3:59:51

you can see right here. Now let's say we

3:59:53

like this pette. Then we'll click export

3:59:56

and save PLET. And we have it in our

3:59:58

dashboard. Now, it only has three

4:00:00

colors, but that doesn't matter. I'm

4:00:02

only going to use one of these. That is

4:00:04

the blue one cuz I think it would be

4:00:06

cool to use this blue color as the text

4:00:09

color on our site. So, I want the H1 and

4:00:12

the button text to have that bluish

4:00:14

color. And the way I'm going to do that

4:00:16

is change the color of the body here

4:00:18

because that is where the H1 gets its

4:00:20

color from. It is the only element

4:00:22

inheriting from the body at this point.

4:00:24

So I'm going to do like that. This is

4:00:26

the hexodimal value I got from coolers.

4:00:29

And as you can see, I think it looks

4:00:30

pretty cool. And also let's keep the

4:00:33

underline white because I think it makes

4:00:35

sense to have that in a different color.

4:00:37

Now moving on to the button. We'll do

4:00:39

color

4:00:41

and paste it in again. And there we go.

4:00:43

Now here I think actually this apply

4:00:46

text could be a bit clearer because the

4:00:48

contrast with the background is just

4:00:50

okay at this point because with this

4:00:52

blue color I think the thin letters

4:00:55

became a bit too thin. Now a final thing

4:00:58

I want to do with this apply text here

4:01:01

is make it a little bit bolder make it

4:01:03

stand out a bit more. And luckily we

4:01:06

imported not only the regular font

4:01:09

weight with the Orbitron font family but

4:01:11

also the 800 font weight the extra bold.

4:01:15

So what we can do now is actually do

4:01:19

font weight

4:01:22

and then just bold. And there you can

4:01:23

see it actually bolded the text. Or we

4:01:26

could use the value directly which is

4:01:29

800. that'll give us the exact same

4:01:31

result as the font weight property can

4:01:34

both take numerical values and named

4:01:36

values. So the numerical values range

4:01:38

from 100, 200, 300, 400 and so forth up

4:01:41

until 900. And the named values are for

4:01:44

example normal, bold and so on. So we

4:01:47

imported 800. So let's just write 800

4:01:50

here. With that I think our example

4:01:52

looks pretty good. So let's move on.

4:01:57

Going to space is definitely a risky

4:02:00

affair. So, I want to add this terms and

4:02:02

conditions apply text underneath the

4:02:05

main section of our site. However, I

4:02:08

don't want to add this. This is Scrimba,

4:02:09

so you're going to do it, of course.

4:02:11

But, I'm going to give you a set of

4:02:12

detailed instructions so that you know

4:02:14

how to go about doing this. So, you're

4:02:17

going to start with wrapping the hero

4:02:19

section in a div. And the hero section

4:02:22

is the one you can see on top here. It's

4:02:24

very often called a hero section in web

4:02:26

design and it's probably called that

4:02:28

because kind of serves as the user's

4:02:30

first glimpse of the company and the

4:02:32

offering and has this kind of prominent

4:02:34

place towards the top and it usually

4:02:36

extends full width. So it is kind of the

4:02:38

hero of the website. So in our case it

4:02:40

is these three elements right here the

4:02:43

logo title and the call to action button

4:02:46

and those should all be wrapped inside

4:02:48

of a div. And then I want you to move

4:02:49

the background image that is the

4:02:51

animated galaxy image from the body and

4:02:55

over into this div. Now as you do that

4:02:58

you'll notice that you'll have to add

4:02:59

some padding to this hero div as it'll

4:03:02

look really crammed if you don't add

4:03:04

that. Then I want you to add the terms

4:03:06

and conditions apply in an H3 below the

4:03:09

hero section. And then finally, a

4:03:11

problem you'll probably come across is

4:03:13

that the body tag has some default

4:03:16

margins, which right now doesn't bother

4:03:18

us, but which will become apparent once

4:03:20

you change this layout. So, go ahead and

4:03:23

give this one your best shot, and when

4:03:24

you return back to me, I'll show you how

4:03:26

to do it as well.

4:03:33

Okay, let's go. I'm going to start with

4:03:35

the hero section div. I'm going to add

4:03:37

it right here. I'll give it an ID of

4:03:40

hero because it is unique. So it's okay

4:03:42

to use ID

4:03:45

and then I'm going to indent this in and

4:03:48

run the code. And seemingly nothing has

4:03:50

happened because as you remember from

4:03:52

previously divs don't have any default

4:03:54

styling to them. So what we need to do

4:03:57

is target the hero and then move the

4:04:02

background properties from the body to

4:04:04

the hero. And there we go. And as you

4:04:07

can see, it doesn't look particularly

4:04:09

good. Now, as I said, we will be forced

4:04:11

to deal with the padding in the hero

4:04:13

because you can see here the logo is

4:04:15

really crammed all the way up to the top

4:04:17

and there's no space underneath the

4:04:19

button. So, let's add padding. And on

4:04:22

the top, maybe we want 10 pixels like

4:04:25

that. Yes. On the right hand side, we

4:04:28

don't need anything for now. But on the

4:04:30

bottom, we want a lot of padding. Maybe

4:04:32

we'll do 40 pixels like that. Then on

4:04:35

the left hand side, don't need anything

4:04:37

either. So here we have the padding.

4:04:40

Now let's add the terms and conditions.

4:04:42

Apply H3 below the hero. That's just

4:04:46

like this. Adding an H3. Terms and

4:04:50

conditions. Apply like that. Run the

4:04:53

code. And there we go. It has already

4:04:56

the color we want since we have set the

4:04:59

blue color as the text color on the

4:05:01

body. So, it inherits the color property

4:05:03

from the body. However, as you can see,

4:05:05

are still not quite done because

4:05:07

something has happened with the margins

4:05:08

on the site or or at least the margins

4:05:10

of the body has become more apparent

4:05:12

because now the entire body isn't filled

4:05:15

with the background image anymore. So,

4:05:17

we're suddenly noticing that the body

4:05:19

has some default margins on all sides.

4:05:22

We don't want that. So, we're going to

4:05:24

neutralize that by doing margin zero.

4:05:27

And boom, there we go. We have completed

4:05:30

the challenge. Now there is one more

4:05:32

thing which is a little bit problematic

4:05:34

which is that if you watch this on a

4:05:36

mobile for example so that the

4:05:37

exploration word is located directly

4:05:40

over the galaxy the readability sinks

4:05:42

quite a bit because the text color

4:05:44

blends in with the background and the

4:05:46

way we'll fix that is by using a shadow

4:05:48

technique on this text. So now you are

4:05:51

going to learn exactly that.

4:05:55

Text shadow is a really nice tool to

4:05:57

have in your web design toolkit as it

4:06:00

can make your designs much better. So

4:06:03

here I've created a very simple

4:06:05

imitation of the Netflix logo with the

4:06:07

red background and white text. As you

4:06:10

can see, I've pulled in a font which

4:06:12

kind of looks like the Netflix font.

4:06:14

It's not really the same, but it's close

4:06:16

enough. And it is an H1, and I've set

4:06:19

the font size to 80 pixels. Now, what if

4:06:22

I want to have a black shadow like this?

4:06:24

as that makes it look even more like the

4:06:26

classical Netflix logo. I can achieve

4:06:29

that by on the H1 which is the element

4:06:32

that includes the Netflix text as you

4:06:35

can see here. I can add a property

4:06:37

called text dash shadow which must

4:06:41

contain three values. So just bear with

4:06:43

me here as I'll write all three of them

4:06:45

out and then I'll explain it. I'll do 0

4:06:48

pixels 0 pixels black and seemingly

4:06:52

nothing happened. That's because I first

4:06:54

wanted to show you the third value here,

4:06:56

black. That's pretty simple. That's just

4:06:58

the color of the shadow. And as you can

4:07:00

see here, it is black. The two other

4:07:03

values dictate the offset of the shadow

4:07:06

on the horizontal line and the vertical

4:07:09

line. So if I add, for example, 5px

4:07:11

here, you can see that now the shadow

4:07:13

appeared. It's as if it's sticking out

4:07:16

to the right of the letters 5 pixels. If

4:07:19

I do the opposite, minus 5 pixels, it'll

4:07:22

stick out five pixels on the left hand

4:07:24

side. As you can see, there's no shadow

4:07:27

below and above because that's dictated

4:07:30

by the second value. So, if I turn this

4:07:32

back to five and on the vertical one, do

4:07:36

for example 30, then you can see that

4:07:38

the shadow got pushed far too much

4:07:40

downwards. If I do minus 30, it's pushed

4:07:43

upwards. If I do five pixels, it's

4:07:46

pushed only five pixels downwards, which

4:07:49

looks pretty good actually. It is indeed

4:07:52

the design we were looking for. So

4:07:54

summarize here, the first value is how

4:07:57

many pixels you want to push the shadow

4:07:59

to the right. The second value is how

4:08:02

many pixels you want to push the shadow

4:08:04

downwards. And the third is the color.

4:08:07

So what I want you to do now is try to

4:08:10

make the shadow look like this. As you

4:08:13

can see, now it's on the left hand side

4:08:15

and below like as if the sun is shining

4:08:18

from the top right corner. So take a

4:08:21

guess at how you need to change this

4:08:23

line 11 here in order to get that

4:08:25

effect. Go ahead and do that right now.

4:08:33

Okay, hopefully that went well. What you

4:08:35

need to do is basically put a minus in

4:08:39

front of the first value like that. That

4:08:41

shifted the shadow from being on the

4:08:43

right hand side of the letters to the

4:08:46

left hand side. Okay, changing it back

4:08:48

again. Now I want to teach you about a

4:08:51

fourth value you can add to the text

4:08:54

shadow property and that is the third

4:08:56

pixel value. So here you can also write

4:08:59

for example 5 px. And what happened now?

4:09:03

If we compare what we have here right

4:09:05

now with how it was before we added that

4:09:07

value, you can see that previously the

4:09:09

edges of the shadow were sharp. There

4:09:11

was no blur. Whereas here, they're kind

4:09:14

of fading over into the red color behind

4:09:17

it. And this is called blur. And if we

4:09:19

reduce this one to zero again, the edge

4:09:21

is sharp again. Now, if we do something

4:09:23

crazy like 50, you can see that it is so

4:09:27

blurry that it just looks a little bit

4:09:29

like background is a little bit dirty.

4:09:31

So, let's get it back to zero again

4:09:33

here. What I want you to do now is try

4:09:37

to achieve this shadow. Go ahead and

4:09:39

give that a shot right now.

4:09:45

Okay, hopefully that went well. Let's

4:09:47

have a look. You can see the shadow is

4:09:49

above and to the right of the letters.

4:09:51

Let's fix that first. To have it on the

4:09:54

right of the letters, we need plus value

4:09:56

on the first one. We want to push it to

4:09:58

the right and we want to have it above.

4:10:00

We don't want to push it downwards as

4:10:01

we're doing with this value. So we want

4:10:03

to minus it pushing it upwards like

4:10:06

that. Now the only difference is that

4:10:09

this is a lot more blurry whereas this

4:10:12

is completely sharp. So let's try five

4:10:14

pixels here as well. And boom, there we

4:10:17

go. That looks pretty correct to me. So

4:10:21

great job doing this challenge. Before

4:10:24

we move on, I have just a final trick I

4:10:26

want to show you, which is a little bit

4:10:27

of a hack, but super useful because

4:10:30

let's say that, for example, the

4:10:31

background here was white smoke instead

4:10:34

of the red color. And white smoke is a

4:10:36

very white color with just a little bit

4:10:38

of gray in it. As you can see, it looks

4:10:40

really bad. Now, we can hardly see the

4:10:42

letters, but we can clearly see the

4:10:44

shadows. If we now set zero pixels on

4:10:47

the two first values, but keep the blur,

4:10:51

well, then suddenly there's no shadow,

4:10:53

but there's just a glowing effect around

4:10:56

the letters, making them visible, even

4:10:58

though they are in almost the same color

4:11:00

as the background. And if we make this

4:11:03

smaller, for example, one, you can see

4:11:05

the line around the letters look a

4:11:06

little bit sharper since it's very

4:11:08

little blur now. And if you do like 20,

4:11:12

each letter gets a lot of blur around it

4:11:14

and thus making them visible. So that is

4:11:17

a little trick to use normally with

4:11:20

small values on the blur in order to

4:11:22

make your text stand out a little bit

4:11:24

more in the situation where your text

4:11:27

color and your background color is a

4:11:29

little bit too similar. And this is very

4:11:31

relevant if you have a background image

4:11:33

in which the contrast between that image

4:11:35

and the text color is a little bit too

4:11:37

weak. So then you'd use this hack to

4:11:40

make your text stand out despite the

4:11:43

similarities between your text color and

4:11:45

the background image. So that was quite

4:11:47

a lot about text shadows, but now you

4:11:50

know it. So we are ready to move on to

4:11:51

the next scrim.

4:11:55

Okay, now we are going to fix this

4:11:57

problem of the text blending too much

4:12:01

into the background when it is broken

4:12:03

into two lines and thus are located

4:12:05

exactly over the galaxy in the

4:12:07

background image here because the

4:12:09

readability is a bit too low. Now, in my

4:12:11

opinion, I want you to fix that by

4:12:13

adding a blurred border around the H1

4:12:16

tag using the technique you just

4:12:18

learned. You should set the blur to four

4:12:20

pixels and the color to black. So go

4:12:23

ahead and do this right now. Then I will

4:12:25

show you the solution as well when you

4:12:26

return back to me.

4:12:33

Okay, let's do this. So first we need to

4:12:37

select the H1. And we've been really

4:12:39

good at using IDs and classes here. So

4:12:42

instead of just selecting the element,

4:12:44

I'm actually going to give this one an

4:12:46

ID of title because we probably only

4:12:48

have one title on the page. So running

4:12:51

this and navigating back into the CSS

4:12:54

file, I can select the title and then I

4:12:57

need to use the text shadow property. We

4:13:00

want both the horizontal offset and

4:13:02

vertical offset to be zero pixels. We're

4:13:05

not actually doing creating a shadow

4:13:07

here, the effect we want is more of an

4:13:08

outline. So then without any offset, but

4:13:11

four pixels blur, it'll blur a black

4:13:14

shadowish effect around the entirety of

4:13:16

all the characters. So if you look at it

4:13:19

now and look closely, there is a slight

4:13:22

blurred black border around the letters.

4:13:26

It's not that easy to see, but if you

4:13:28

now look at this while I comment out

4:13:31

that CSS rule, you'll see the

4:13:32

difference. So keep looking at the

4:13:34

exploration word and I will comment it

4:13:36

out now. Now I'll comment it back again

4:13:40

there.

4:13:42

Comment it out. Comment it back in

4:13:45

again. So, so hopefully you saw that it

4:13:47

changed here a little bit. So, now the

4:13:49

readability is a little bit better.

4:13:52

Great job.

4:13:55

Hey, it's Gil. I'm a teacher at Scribba.

4:13:57

Before we wrap up this section, I want

4:13:59

to drop in and teach you about a small

4:14:01

yet important part of your HTML

4:14:03

document, and that is setting the

4:14:06

document language using the HTML lang

4:14:09

attribute. And this is important for

4:14:11

several reasons. First, screen readers

4:14:14

use the lang attribute to determine

4:14:16

which language to use when reading the

4:14:17

content. And this is essential for users

4:14:19

who rely on assisted technologies.

4:14:22

Search engines also use the lang

4:14:23

attribute to understand the language of

4:14:25

your content. And it also ensures

4:14:27

consistency in language specific

4:14:29

features like date formats and specific

4:14:31

character sets. Setting the language is

4:14:34

quite straightforward. In your HTML

4:14:37

file, you'll use the lang attribute like

4:14:39

this in your opening HTML tag. And the

4:14:42

value of this attribute should be a

4:14:44

standard language code. For example, to

4:14:46

set the language of your document to

4:14:48

English, you would use en. And for

4:14:51

Spanish, it would be E S for espanol.

4:14:54

These language codes are standardized

4:14:56

and usually consist of two or three

4:14:58

letters. You can easily find the correct

4:15:00

code for your language with a quick

4:15:01

online search. Sometimes your page might

4:15:03

contain content in multiple language. In

4:15:06

that case, you'll set the primary

4:15:07

language in the HTML tag and use the

4:15:10

lang attribute on elements with

4:15:11

different languages. For example, in the

4:15:13

H3 tag, add a lang attribute and set it

4:15:16

to Spanish. Setting the language of your

4:15:18

page might seem like a small step, but

4:15:21

it does play a big role in accessibility

4:15:23

and helps your website reach the right

4:15:25

audience. To learn more about the ling

4:15:28

attribute and all the different language

4:15:29

codes, be sure to review the MDN docs

4:15:32

reference listed here.

4:15:36

Now, I'm not sure if you're aware of

4:15:38

this, but you're the best because you've

4:15:41

completed this section and that is very

4:15:44

well done. Plenty of people who have

4:15:46

started this section has never completed

4:15:48

it. You're not like them. So, I am

4:15:51

really proud of you. And let's take a

4:15:52

quick look at what you've learned.

4:15:55

Starting out, you learned about

4:15:56

background images. More specifically,

4:15:58

you learned about the background image

4:16:00

property and the URL function and also

4:16:02

the background size property in CSS and

4:16:05

setting that to cover. We also then used

4:16:07

a webp format in order to get this

4:16:10

animated image in our hero section,

4:16:12

which is super cool and really breathes

4:16:14

life into our website. And then you

4:16:16

learned about Google fonts. We imported

4:16:18

them up here in the head section and

4:16:21

then you set the font family like this.

4:16:23

Fonts do so much for the design of

4:16:25

websites. So, this is an important thing

4:16:27

to know as a web developer. And you also

4:16:30

learned a new HTML tag, which is the

4:16:32

span tag, which you can see right here.

4:16:34

It is what allowed us to create this

4:16:35

underline under the exploration word,

4:16:38

which it did in combination with a

4:16:40

utility class. The underline class,

4:16:43

which only has one job, and that is to

4:16:45

set the underline whatever element it's

4:16:47

applied to. And then also we learned

4:16:49

about ids which is another attribute in

4:16:51

HTML that you target in the CSS using a

4:16:54

hashtag. And at the very end we did a

4:16:57

really cool trick with the text shadow

4:16:58

property in order to make the

4:17:00

readability of our title here a little

4:17:02

bit better. So you've learned some key

4:17:04

concepts in this section. Now is the

4:17:07

time for you to get up, stretch, maybe

4:17:10

get a cup of coffee or whatever you

4:17:11

prefer to recharge because be sure to do

4:17:14

exactly that. And then I will see you in

4:17:16

the next section.

4:17:20

Welcome to this section where you are

4:17:22

going to build a birthday gift site. And

4:17:24

it is just so cool because this site is

4:17:27

something you can use for whenever a

4:17:29

friend or family member of yours has a

4:17:32

birthday. So what you do is basically

4:17:33

add their information to the header

4:17:35

here. And then we have these gifts. So

4:17:38

for example, this one saying here's how

4:17:39

happy I am for you today. And when the

4:17:41

birthday boy or girl hovers over the

4:17:43

image, they will see a nice gift that

4:17:46

makes them feel truly appreciated. Going

4:17:49

down, we have other gifts. How people

4:17:51

react when you enter the room. Ooh, this

4:17:53

is meant to make them feel really

4:17:55

good-looking. And here, if I had to

4:17:57

describe you with one word, genius, so

4:18:00

that you make them feel really smart.

4:18:02

Next up, the only person as badass as

4:18:04

you is, of course, James Bond. And then

4:18:07

rounding it up with a little toast. So

4:18:10

hopefully you have someone special to

4:18:12

send this site to like Nick Air for

4:18:14

example who despite being a

4:18:16

computerenerated image created by an AI

4:18:19

also is one of my best friends. So I am

4:18:23

looking forward to make Nick happy on

4:18:25

his birthday. Let's just get started

4:18:27

with this section.

4:18:31

Okay, it's time for your first

4:18:33

challenge. What you're going to do is

4:18:35

create this basic design here for the

4:18:38

header of our app. and it's pretty far

4:18:40

from what we got right now. As you can

4:18:41

see in the styles.css, we have no

4:18:44

styling at the moment. So, our site

4:18:46

looks pretty dull. You can see

4:18:48

everything is left aligned and the image

4:18:50

of Nick is far too large. Plus, we're

4:18:53

lacking the appropriate font. Taking a

4:18:55

look at the HTML here. It's just a very

4:18:57

simple structure with an H1, an image

4:18:59

tag, an H2, and an H4 inside of the

4:19:02

body. So, nothing special there. The

4:19:05

font that you will use is called Happy

4:19:07

Monkey and it is a Google font. So

4:19:09

you're going to have to head over to

4:19:11

Google Font, fetch it, and then embed it

4:19:13

into our project. As you can see in the

4:19:15

provided design, the image of Nick

4:19:18

should be rounded and not squared as it

4:19:20

is right now. So you will have to figure

4:19:22

out how to make an image round. And yet

4:19:24

again, you'll find the answer if you

4:19:26

Google it. Finally, I want you to

4:19:28

consider how you should select the

4:19:30

image. So, should you use a class

4:19:32

selector, an ID selector, or an element

4:19:35

selector? You can use any of them, but I

4:19:37

want you to think about it and try to

4:19:38

figure out what you think makes most

4:19:40

sense. Go ahead and do this right now,

4:19:42

and then I of course will show you the

4:19:44

solution when you return back to me.

4:19:53

Okay, hopefully that went well. Let's do

4:19:55

it together. I want to start with

4:19:57

centering everything. And for that, I'm

4:19:59

going to do

4:20:01

body and then set the text align to

4:20:05

center like that. As you can see, that

4:20:08

indeed centered our elements. Next up, I

4:20:10

want to fix the image. It is here. And I

4:20:13

think it makes sense to use an ID

4:20:15

selector here because this is kind of

4:20:17

the main image of our birthday boy. And

4:20:20

I don't think we'll duplicate it across

4:20:21

the page. So, it is unique, meaning we

4:20:24

can use an ID. So, I'll do ID equals and

4:20:27

then BFF for best friend forever because

4:20:30

Nick is my BFF. Please don't make fun of

4:20:32

me because my BFF is a computerenerated

4:20:35

image. But that is just how it is. And

4:20:37

then I'll do dash img just to make it a

4:20:39

little bit easier to understand what it

4:20:40

is based upon the ID name. Then I'll run

4:20:44

the code so that that is applied to the

4:20:45

DOM. And heading over to the styles,

4:20:48

I'll do #bfff-

4:20:50

img like that. And first I want to fix

4:20:53

the width of it. It's far too wide. This

4:20:56

looks more like 100 200 pixels. So,

4:20:59

let's try width of 150 pixels. Like

4:21:02

that. Yes, that is pretty much what

4:21:05

we're looking for. And hopefully you

4:21:07

figured out how to make an image round.

4:21:09

And the way to do it is to use the

4:21:11

border radius property, which you've

4:21:13

seen a couple of times by now. And the

4:21:15

maximum border radius an element can

4:21:18

have is 50%. And boom, there it is

4:21:22

completely round. All right. The final

4:21:24

part is to add the Google font, the

4:21:27

happy monkey font. That is a very

4:21:28

birthdayish font. Actually, I found it

4:21:31

just by googling Google fonts birthday.

4:21:33

Then happy monkey was the top result.

4:21:35

Clicking into that, we'll select it by

4:21:37

clicking select this style and then

4:21:39

we'll copy the links here so that we can

4:21:41

embed it into our project. I'll paste

4:21:44

that into the head of our project. Then

4:21:46

copy the font family rule so that I can

4:21:49

paste that directly in as well. Now I'll

4:21:51

have to rerun so that the font is

4:21:53

embedded. And yes, there we go. That is,

4:21:56

as far as I can see, exactly the design

4:21:58

we were looking for. So great job. Let's

4:22:02

move on.

4:22:05

Okay, your next challenge is to colorize

4:22:08

the app because I want it to look like

4:22:10

this with a nice blue background, pink

4:22:13

border, and white text. And as you can

4:22:16

see, I've provided the hexadesimal

4:22:18

values for the pink, blue, and white

4:22:20

colors here. So your job is simply to

4:22:22

figure out where you need to add these

4:22:24

and what kind of CSS properties you're

4:22:26

going to use. Go ahead and do this right

4:22:28

now.

4:22:35

Okay, hopefully that went well. Let's do

4:22:37

it together. I'm going to start here in

4:22:39

the body taking the blue hexodimal value

4:22:42

and setting it as the background of the

4:22:45

body. Boom. There we go. Next up, we

4:22:49

want to set the color property here to

4:22:52

white. Just six Fs after each other

4:22:56

like that. Now that is inherited down

4:22:59

from the body into all of these. Okay.

4:23:02

Final step is the image. As you can see,

4:23:05

it should have a border around Nick and

4:23:08

it should be pink. So here we'll use the

4:23:10

border property and let's try six pixels

4:23:12

because it looks pretty thick. It should

4:23:15

be solid. And then we'll copy the hex

4:23:18

value from pink and paste in right

4:23:21

there. And actually that looks about

4:23:24

right to me. So great job. Let's move

4:23:27

on.

4:23:30

There is one problem with our site at

4:23:33

the moment, which is that if we run

4:23:35

these two colors through a contrast

4:23:37

checker, for example, userway.org,

4:23:40

you'll see that our accessibility

4:23:41

actually fails because the contrast

4:23:43

ratio is too small. So, what can we do

4:23:46

to improve this? Given that we want to

4:23:48

keep the colors we have, what we can do

4:23:50

is use the trick you learned in the

4:23:52

space exploration section. Because pay

4:23:55

attention to what happens to this text

4:23:58

if we add a thin black border around the

4:24:01

text using the text shadow property. So

4:24:04

this is without the text shadow property

4:24:06

and this is with it. As you can see the

4:24:09

text now stands out more as the black

4:24:12

contrasts well with both the white and

4:24:14

the blue background. And it is also

4:24:15

pretty subtle. So the text still looks

4:24:18

white but it's just a little bit more

4:24:20

visible. And in my opinion I think the

4:24:21

readability here is pretty good. So what

4:24:23

I want you to do now is write the CSS

4:24:26

for this exact technique. So add a thin

4:24:29

blurred border around the H1, H2, and H4

4:24:32

elements using the text shadow technique

4:24:35

you learned in the space exploration

4:24:37

section. You're going to set the blur to

4:24:39

one pixel and the color to black. Okay,

4:24:42

hopefully you remember how to do that.

4:24:44

Give it your best shot and then I will

4:24:45

of course show you the solution as well

4:24:47

when you return back to me.

4:24:55

Okay, let's do this. So, let's start

4:24:58

with the H1 here. And here I'm just

4:25:00

going to use an element selector as

4:25:01

we'll have a lot of H2s and H4s

4:25:03

throughout the site. And I think we want

4:25:05

all of them to have this style. So,

4:25:07

there's no point separating it into a

4:25:08

class. So, text shadow

4:25:14

setting the first two values to 0 pixels

4:25:16

as we don't want any offset vertically

4:25:18

or horizontally. But the third value,

4:25:20

the blur should be set to one pixel. And

4:25:22

then the color is black. And boom, there

4:25:25

we go. We have that thin outline which

4:25:28

improves the readability. And now you

4:25:30

probably did something like this. Added

4:25:32

a whole new rule for the H2 and yet

4:25:35

another one for the H4.

4:25:37

And if you did, that is completely fine.

4:25:39

That is how I expected you to solve this

4:25:42

challenge. But I do want to show you a

4:25:44

little trick which allows us to reduce

4:25:46

all of these into one line. And that is

4:25:48

simply by using a group CSS selector

4:25:51

where you simply add multiple selectors

4:25:53

on one line. So what you do is instead

4:25:55

of just writing H1, you write H1,

4:25:59

H2. Now we can delete the H2 because

4:26:03

this rule is applied to both the H1 and

4:26:05

the H2. And likewise we can just add the

4:26:08

H4 here as well. Like that. Now we can

4:26:11

remove all of this. As you can see, the

4:26:13

thin border is applied to all of the

4:26:16

elements. Now, it is really important

4:26:17

that you actually use a comma here and

4:26:20

not just add it like this. This means

4:26:22

something entirely different and we're

4:26:23

not going to learn about that right now

4:26:25

as it's outside of the scope of this

4:26:27

section. So, make sure you have the

4:26:29

commas and then you can use this

4:26:30

technique. And I happen to know that we

4:26:33

also want this text shadow to be applied

4:26:35

to our H3 elements down the line and

4:26:37

also our paragraphs down the line. So,

4:26:40

I'm just going to add them here so that

4:26:41

we don't have to think about this as we

4:26:43

add new elements to our site later down

4:26:45

the line. So, great job. Let's move on.

4:26:51

Now, we want to take this pink

4:26:53

background that we have around the image

4:26:55

and apply it behind the H2 and the H4

4:26:58

element so that it looks like this. So,

4:27:01

let's try the most intuitive approach

4:27:03

and see how that works. That would be to

4:27:06

target the H2 and the H4. I'm going to

4:27:08

use this comma selector here to target

4:27:10

both simultaneously as we've done up

4:27:12

here. And then we'll set the background

4:27:16

to this pink color right here. However,

4:27:19

as you can see, that did not give us

4:27:21

what we wanted because heading elements

4:27:24

like H2 and H4 are by default display

4:27:27

block. So they take up all the available

4:27:29

horizontal space. So let's then try to

4:27:31

turn them into display inline and see

4:27:33

what happens then.

4:27:35

Ah, that did not work well either

4:27:38

because when they're in line, they're

4:27:39

actually narrow enough to be on the same

4:27:41

line and actually jump up to the line

4:27:43

above with the image, which also is

4:27:45

display inline. So, let's remove the

4:27:47

display inline as well. And the way to

4:27:49

actually solve this is to use a

4:27:50

technique you haven't learned yet. Now,

4:27:52

I'm just going to show it to you fast,

4:27:53

and then we're going to take a closer

4:27:55

look at how it works in the next script.

4:27:57

Because what we can do is head into the

4:27:59

body, which is the container element for

4:28:02

these two and for all of our elements

4:28:04

actually, and do bisplay flex. That

4:28:08

stacks things up on a horizontal line,

4:28:10

turning every element into its own

4:28:12

column. But we can change that by doing

4:28:14

flex direction, which now is set to row

4:28:18

by default. And that might sound a

4:28:20

little bit confusing since I've always

4:28:21

said that flexbox turns every element

4:28:24

into its own column. And yes, it does

4:28:26

that. However, what it also does is make

4:28:28

sure that all of the elements are in the

4:28:30

same row. So that is why it's called

4:28:32

flex direction row because rows go from

4:28:35

left to right. And you can see there's

4:28:37

only one row from left to right here,

4:28:39

which becomes even clearer if you do

4:28:41

like this. And all the elements are

4:28:42

inside of the same row. Now, in order to

4:28:45

flip this, we can simply change row from

4:28:48

column like that. Now all of the

4:28:50

elements are stacked on top of each

4:28:51

other again in one column because a

4:28:54

column goes from top to bottom. So this

4:28:56

is just one column. Now with that in

4:28:58

place, we can use another CSS property

4:29:00

in that flexbox gave us which is called

4:29:02

align as items and set that to center.

4:29:06

And boom, there we go. Now, this was

4:29:10

probably pretty confusing and you were

4:29:12

not meant to to understand this right

4:29:13

now, which is why we're going to take a

4:29:15

little digression here and look closer

4:29:17

at how flexbox works and then return

4:29:19

back to this example where you will code

4:29:21

it up yourself and properly understand

4:29:23

it.

4:29:26

If you are to become a flexbox master,

4:29:28

you will need to know align items.

4:29:31

Luckily though, it's not that hard to

4:29:32

learn because it is a close cousin of a

4:29:35

property you already know, which is

4:29:37

justify content. So, let's pretend that

4:29:39

the two of us, for example, work in a

4:29:41

lab together. Well, if so, we'd have our

4:29:44

lab equipment, which you can see here,

4:29:46

inside of our lab, which is this green

4:29:48

rectangle right here. And what we're

4:29:50

going to do now is use flexbox along

4:29:52

with the justify content and line items

4:29:54

in order to organize our lab equipment

4:29:57

in different ways in our lab. So let's

4:29:59

have a look at the code. The HTML is

4:30:02

very simple. It's just a container which

4:30:04

has three divs and each div hold exactly

4:30:07

one piece of lab equipment visualized

4:30:09

via an emoji. If we head over to the

4:30:11

CSS, you can see that the container has

4:30:13

a border and a fixed height. So that is

4:30:16

why we get this green rectangle. The

4:30:18

items have a width and a height. There's

4:30:21

some margin in between them and some

4:30:23

padding on the inside. I've set the font

4:30:24

size and also added a border. And

4:30:26

finally, something you haven't learned

4:30:28

yet, but I've added a gradient

4:30:30

background so that the color slightly

4:30:32

fades from a darker shade of green to a

4:30:35

lighter shade of green in the

4:30:36

background. Now, you are going to learn

4:30:37

about the linear gradient later on. So,

4:30:40

don't worry a second about this right

4:30:41

now. Just accept that it is how it is.

4:30:44

And let's get going with the organizing.

4:30:46

So as you can see by default the lab

4:30:49

equipment the divs that is are stacked

4:30:52

on top of each other because as you

4:30:54

remember divs are display block. However

4:30:57

if we turn it into a flexbox layout

4:31:00

each of the item gets its own column and

4:31:02

as a consequence they stack up on the

4:31:04

horizontal line. So far so good. And if

4:31:07

we set the justify content property

4:31:09

it'll arrange these in different ways

4:31:11

along this horizontal axis. So if we do

4:31:14

center for example they are centered. If

4:31:16

we do end they are pushed all the way to

4:31:17

the end and yeah you know the deal. So

4:31:20

what align items does is instead of

4:31:22

controlling the horizontal line which I

4:31:24

from now will call the main axis it

4:31:27

controls the crossaxis which is the

4:31:30

vertical one going from top to bottom.

4:31:33

So let's turn this back to start and do

4:31:37

align items.

4:31:40

Enter. And boom, there you can see now

4:31:42

it pushed all of the three items down to

4:31:45

the center so that they are centered

4:31:48

vertically meaning they are centered

4:31:49

along the crossaxis. And then I can

4:31:52

combine this with the main axis which is

4:31:55

justify content that controls the

4:31:57

horizontal one going from left to right.

4:31:59

For example, do end here and boom then

4:32:02

we are still vertically aligned. So

4:32:04

we're in the middle but we are pushed

4:32:06

all the way to the right hand side along

4:32:08

the main horizontal axis. So the values

4:32:11

you are going to use for line items to

4:32:13

begin with are start, center and end.

4:32:16

Whereas with justify content as you know

4:32:18

you can use start, center and end but

4:32:20

also these space around space evenly and

4:32:22

space between properties. Okay, let's

4:32:24

move on to the challenge. What I want

4:32:26

you to do is follow my orders on where

4:32:28

we should leave our lab equipment

4:32:30

because I want you to do it in very

4:32:32

specific ways. Starting with this

4:32:34

position here where they're all squeezed

4:32:36

down in the bottom left corner. So go

4:32:38

ahead and modify justify content and

4:32:40

align items to achieve that layout right

4:32:42

now.

4:32:46

So to achieve this layout you can see it

4:32:48

is at the bottom of the crossaxis the

4:32:51

vertical one. So we'll do end on align

4:32:54

items but it is at the start of the main

4:32:56

axis because it is pushed all the way to

4:32:59

the left meaning that we should do start

4:33:01

up here. And there we go. We have solved

4:33:04

it. Okay. New challenge. I want you to

4:33:07

achieve this layout. Go ahead and do

4:33:09

this right now.

4:33:15

So here we can see we are actually

4:33:17

centered both along the main axis

4:33:19

horizontally and the crossaxis

4:33:21

vertically. So I'll try center. Yes. And

4:33:26

center again. And there we go. Okay.

4:33:29

Final one. I want you to organize the

4:33:31

equipment like this. Go ahead and do it

4:33:34

right now.

4:33:38

Okay, hopefully that went well. The

4:33:40

first thing I'll notice here is that all

4:33:42

of the items are squeezed to the top.

4:33:43

So, align items should be start. And

4:33:46

there's some space around the elements.

4:33:49

So, we need to try one of these. For

4:33:51

example, space around, space evenly, or

4:33:52

space between. So, let's try for example

4:33:56

space between.

4:33:58

Hm, that didn't exactly achieve what we

4:34:01

wanted because there should be some

4:34:02

white space on the left side and the

4:34:03

right hand side here where these two are

4:34:06

squeezed all the way to the end. So

4:34:08

maybe we can do space around instead.

4:34:11

Yes, that looks exactly like what we

4:34:14

want. So really good job solving these

4:34:17

three challenges. Before we move on,

4:34:19

there's just a small thing I want to

4:34:21

tell you. And that is something you

4:34:22

might see from time to time, which is

4:34:24

that if I now remove the height of our

4:34:28

items, see, then they just became a

4:34:30

little bit higher because the content

4:34:32

inside of it wants a little more height.

4:34:33

But that was besides the point. What I

4:34:35

wanted to do is also remove the align

4:34:37

items. Let's see what happens. Oh wow.

4:34:40

It turns out that flexbox in the

4:34:43

crossaxis actually stretches the content

4:34:46

like this. And the reason it didn't

4:34:48

happen previously was because our height

4:34:49

property overrode that stretching. So

4:34:52

what this means is that align items by

4:34:56

default has the value stretch. When we

4:34:59

do for example start, it's no longer

4:35:01

stretched and it's pushed to the start.

4:35:04

So this might feel very confusing and

4:35:06

the only reason I wanted to tell you

4:35:07

about it now is that when you are in a

4:35:09

flexbox layout and you notice that

4:35:11

something is stretching in a way you

4:35:13

don't want it to stretch, the prime

4:35:15

suspect you should look at is align

4:35:17

items and experiment with that. So be

4:35:19

aware of that. But don't worry too much

4:35:21

if you found this a little bit

4:35:22

confusing. It's totally okay. Let's just

4:35:24

keep up the pace and move on to the next

4:35:26

scrim.

4:35:29

Now you're going to learn about flex

4:35:31

direction because there is one problem

4:35:34

with our lab system now and that is that

4:35:36

regardless of how we change around on

4:35:38

the align items and justify content.

4:35:41

Let's center and end for example our lab

4:35:44

equipment will always stack up besides

4:35:47

each other. They'll be on the same row

4:35:49

and there's no way to get them to stack

4:35:52

on top of each other. But maybe that's

4:35:54

how I prefer to leave my lab equipment

4:35:55

for the night. But regardless of how we

4:35:57

change to justify content and align

4:35:59

items, that is now impossible. Now we

4:36:02

could of course remove the display flex

4:36:04

and then these divs will stack on top of

4:36:06

each other by default. So by doing this

4:36:10

now they stack on top of each other.

4:36:12

However, justify content and line items

4:36:16

no longer work. So if I try changing

4:36:18

these,

4:36:20

nothing happens because these properties

4:36:22

work inside of a flexbox, not inside of

4:36:24

a random div that by default is display

4:36:26

block.

4:36:28

So we need the display flex like that in

4:36:32

order to make these work. However, what

4:36:34

we can do is change the flex direction.

4:36:37

So first let me just both of these two

4:36:39

back to start and then I'll do flex dash

4:36:42

direction

4:36:44

and it by default is a row because as I

4:36:47

said these stack up alongside of each

4:36:49

other on a row but if we change this to

4:36:51

column boom there you can see now they

4:36:53

suddenly stack on top of each other as

4:36:56

if they are in the same column as

4:36:58

columns go from top to bottom. So now we

4:37:01

are back to the original layout we had

4:37:03

before we made this into a flex

4:37:04

container. But justify content and align

4:37:08

items now work. However, they work in a

4:37:11

little bit of a different way than you

4:37:12

might expect because as you remember I

4:37:15

previously talked about the main axis

4:37:18

going from left to right and being the

4:37:20

one controlled by justify content

4:37:22

whereas the crossaxis going from top to

4:37:25

bottom and also being controlled by

4:37:27

align items. Well, when we change the

4:37:30

flex direction and our items stack up

4:37:33

differently on top of each other, we

4:37:36

also change the main axis. So, this is

4:37:39

no longer the crossaxis, it is the main

4:37:41

axis and it's controlled by justify

4:37:43

content. Whereas the horizontal one is

4:37:46

no longer the main, it is the cross and

4:37:49

it's controlled by align items. So, we

4:37:51

basically flipped align items and

4:37:54

justify content. So if I now do justify

4:37:58

content end, they'll jump downwards

4:38:01

whereas previously they would have

4:38:02

jumped to the right. And if I now do

4:38:05

align items and they'll jump to the

4:38:08

right whereas previously align items

4:38:10

control the vertical position. So this

4:38:12

is probably a little bit confusing now.

4:38:14

You should not feel bad if this feels

4:38:16

overwhelming. This will take time to

4:38:18

mature in your mind and it's totally

4:38:20

okay that in the beginning now you're

4:38:22

just experimenting with these values in

4:38:24

order to get the layout you want and not

4:38:26

really remembering exactly why it works

4:38:28

as it works. So let's now give you some

4:38:30

practice. I want to clean up my lab

4:38:32

equipment and I want it to be like this.

4:38:35

So go ahead and change around on these

4:38:38

two values in order to achieve that

4:38:40

layout.

4:38:45

Okay. What we need to do is on justify

4:38:48

content I want to center it so that it's

4:38:50

vertically centered but then we want to

4:38:53

align it to the start on the left hand

4:38:55

side. Yes, that is correct. Okay, new

4:38:59

one. Achieve this layout.

4:39:06

Okay, here we can see some space in

4:39:09

between the items. So I think we need to

4:39:11

use space between on justify compent.

4:39:15

Yes, looking good. But we are aligning

4:39:18

to the left. We want to align it to the

4:39:19

right instead. So align items should

4:39:22

probably be end instead of start. And

4:39:25

boom, that is correct. Final layout.

4:39:28

This one right here. Give it a shot

4:39:30

right now.

4:39:35

Okay, we can see that they are all

4:39:37

squeezed towards the top. So I think

4:39:40

we'll do justify content start like

4:39:43

that. Yes, this is good. But we want to

4:39:46

center it as well. So, we'll do align

4:39:48

items center. And there we go. So, great

4:39:52

job doing this. Let's just move on.

4:39:58

Okay. Now, we're going to put your

4:39:59

freshly acquired flexbox skills to the

4:40:02

test because you are going to turn this

4:40:05

layout here into this layout. So first I

4:40:08

want you to wrap the HTML elements in a

4:40:11

div with an ID called header. So that is

4:40:16

all of these items right here. And then

4:40:18

you are to select this header and then

4:40:20

use flexbox to achieve the layout from

4:40:23

the design slide. And as you might have

4:40:25

guessed, you will need to use flex

4:40:26

direction and align items to solve this.

4:40:29

So go ahead and give this your best

4:40:31

shot.

4:40:38

Okay. So, we'll start in the HTML.

4:40:41

Create that div opening tag and close it

4:40:44

off down here. Indent this, run it. No

4:40:48

change seen in the mini browser. That is

4:40:51

to be expected because we'll have to

4:40:54

target it and style it. So, I'm going to

4:40:56

do header and then first display flex.

4:41:00

that forces all of the elements into one

4:41:03

row because it is flex direction row by

4:41:06

default. However, we don't want that. We

4:41:08

want everything in one column. So, we'll

4:41:11

do flex direction column like that. Now,

4:41:15

they stack on top of each other, which

4:41:17

is just what we want. But there's a

4:41:19

problem. The two elements here are

4:41:21

stretching and the image of Nick is left

4:41:23

aligned. It's not centered. So, I think

4:41:25

we need to change the align items. align

4:41:28

items into center like that. And there

4:41:33

we have the layout we wanted. So great

4:41:37

job. Let's move on.

4:41:42

Okay. Now you're going to fix up the

4:41:44

design for this 24 years old element and

4:41:46

the date element right here because I

4:41:49

want it to look like this. Here you can

4:41:51

see that there's some space between the

4:41:53

content of the element and the edge of

4:41:55

the element. And there's not as much

4:41:58

space between the elements. And also the

4:42:00

edges of the rectangles are a bit

4:42:03

softer. But before you start doing this,

4:42:05

there's a couple of things I want to do.

4:42:08

Because here the H2 and the H4 have no

4:42:11

IDs or classes. They are just selected

4:42:13

using the element selector and also

4:42:16

using a selector list separated by

4:42:18

commas. And I don't think we should do

4:42:20

either of those. First of all, we

4:42:22

probably don't want all of our H2 and

4:42:25

H4s on the page to be styled according

4:42:27

to how it looks here up in the header.

4:42:30

So, we actually want to give these two

4:42:32

ids. I'm going to call this one Bday age

4:42:36

and this one Bday date. Running this

4:42:40

code so that we got it applied. And then

4:42:43

in the CSS, instead of using element

4:42:45

selectors, we'll use ID selectors. Eday

4:42:49

age and e day date. And then finally,

4:42:52

let's avoid applying styles to both of

4:42:55

these simultaneously. Let's work with

4:42:57

one or the other because this is really

4:42:59

an optimization and writing code which

4:43:01

is so-called dry, short for don't repeat

4:43:04

yourself. And while that is a good

4:43:05

thing, I want you to focus on the core

4:43:07

CSS now because this will introduce a

4:43:10

little bit more complexity. So let us

4:43:12

instead just keep it simple. So I'll

4:43:14

break this into a new line. So, we got

4:43:16

the birthday date rule here and then

4:43:18

copy the exact same thing to the bday

4:43:21

age like that. Okay, now it's time for

4:43:25

your challenge. You are going to make

4:43:27

the bday elements look like the provided

4:43:30

design slide like this. So, go ahead and

4:43:33

do this right now.

4:43:39

Okay, hopefully that went well. Let's

4:43:42

start with the age element. As you can

4:43:44

see, there is some space around it. That

4:43:46

is padding most likely. So, let's add

4:43:49

padding, for example, 10 pixels, and see

4:43:52

how that works. If we compare that with

4:43:54

what we have in the design, it looks

4:43:55

pretty good, but I think we shouldn't

4:43:57

have 10 pixels on each side. I think the

4:44:00

padding on the left and right side is

4:44:02

meant to be slightly larger than the top

4:44:05

and bottom, as we've often seen with

4:44:06

buttons and layouts in general. So, for

4:44:08

the top and bottom, we'll do 5 pixels

4:44:10

and and left and right 10 pixels. That

4:44:13

is what we are looking for as far as I

4:44:15

can see. Okay, next up there is some

4:44:17

border radius here as well. Not that

4:44:19

easy to see, but it definitely is there.

4:44:21

So, we'll do border radius 5 pixels for

4:44:23

example. That looks pretty good to me.

4:44:25

And now let's just try to copy this down

4:44:28

to our birthday date and see how that

4:44:30

works. Here you can see except for the

4:44:32

fact that there's much less space

4:44:33

between the elements here. They look

4:44:35

pretty similar as far as I can see. So,

4:44:38

we need to move on to the margin. Let's

4:44:40

try first and remove all the margin from

4:44:42

the birthday date. Margin zero like

4:44:44

that. Now it's quite a lot closer and

4:44:46

whatever margin comes from the age two

4:44:49

element and it probably has a bit too

4:44:50

much margin bottom. So let's rather

4:44:53

control that by doing margin bottom. For

4:44:55

example, 10 pixels and yes that looks

4:44:58

pretty good to me. Let's also look at

4:45:00

the margin top here. It is too much

4:45:02

space between the age element and the

4:45:04

image. So if we do margin top by 10

4:45:07

pixels there, that looks pretty good,

4:45:10

but it's perhaps still a little bit too

4:45:12

much. Let's do five instead. Yeah,

4:45:14

actually I think we got it. So the final

4:45:17

step then is to convert this into a

4:45:19

shorthand because we know how to use

4:45:21

short hands, don't we? We want five on

4:45:23

the top and 10 at the bottom. Then we'll

4:45:25

do margin 5 px for the top, zero for the

4:45:28

right hand side, 10 px for the bottom,

4:45:31

and zero for the left hand side. And

4:45:34

there we go. Now, if your solution is

4:45:36

slightly different from mine, perhaps

4:45:38

you used slightly different margins,

4:45:40

border radius, padding, that doesn't

4:45:43

really matter. Give yourself a pat on

4:45:45

the back regardless of how you solve

4:45:46

this and let's move on.

4:45:51

Okay. Now, you are going to create the

4:45:53

first gift section of our site. So, as

4:45:56

you can see, it contains a title, a

4:45:58

little hint about hovering over the

4:46:00

gift, and then there's the image itself.

4:46:02

Now, the hover effect is not a part of

4:46:04

this challenge. You're only going to

4:46:06

work with this hard-coded gift cover at

4:46:08

this point. And that gift cover has been

4:46:10

added up here in a images folder, which

4:46:13

I've just created. As we now have two

4:46:15

images, so I wanted to gather them

4:46:16

together in this images folder. That

4:46:18

means that I've also changed the image

4:46:20

of Nick or the source that is referring

4:46:23

to the image of Nick in the HTML. It now

4:46:25

contains the correct path into the

4:46:27

images folder. So, the challenge is

4:46:30

described in detail here. I want you to

4:46:32

start by creating a gift section div

4:46:34

that will wrap all of the elements for

4:46:36

the first gift. And then I want you to

4:46:38

add the H2, H3, and img elements. So

4:46:42

that is the title which is an H2, the

4:46:44

hint which is an H3 and finally the

4:46:47

image itself. And I want you to give

4:46:49

them all their own classes so that you

4:46:52

can use the classes to select the

4:46:54

elements when you are to style them

4:46:56

according to the design. And as a final

4:46:57

hint, the image should be 400 pixels

4:47:00

wide. So go ahead and do this right now.

4:47:08

Okay, hopefully that went well. So I'll

4:47:11

start by heading over to the HTML and

4:47:13

create the markup. So we wanted a div to

4:47:16

begin with. I'm going to create that and

4:47:18

then give it a class of gift section

4:47:21

like that. And inside of it, we wanted

4:47:24

first an H2 for the title, which should

4:47:27

contain the following text. Let's run

4:47:28

this. And yeah. Ah, nice. We can see

4:47:32

that the text already has the correct

4:47:33

font and also the slight shadow around

4:47:36

it. Okay, very nice. Let's then give it

4:47:38

a class as that was something we should

4:47:40

do with all elements.

4:47:42

I'll call this gift a title like that.

4:47:46

And there was the H3 with the following

4:47:48

text. And I'll give that a class of gift

4:47:51

hint. So you can see I'm using gift and

4:47:54

then a description. I think that makes

4:47:55

it easy to understand that these are all

4:47:57

somewhat related to each other. Finally,

4:48:00

the image element to have a source of

4:48:03

images/gift

4:48:05

cover.jpeg

4:48:07

and also a class of gift img. All right,

4:48:11

let's run this code. And as you can see,

4:48:13

everything is being rendered, though the

4:48:15

image is far too large. So we need to

4:48:18

get going with the styling. All right,

4:48:21

I'll start with the image. So, dot

4:48:24

imgd and give it a width of 400 pixels.

4:48:28

Yes, that is much better. And it is

4:48:30

centered because of our text align

4:48:32

center up here. Very nice. Okay, let's

4:48:35

just carry on with this one. You can see

4:48:37

it has a white border. So, let's do

4:48:40

border. Looks to be something like 6

4:48:43

pixels or something. And solid white.

4:48:46

Yep, pretty good. And finally, a border

4:48:48

radius because the corners here are a

4:48:50

little bit rounded off. So, let's try

4:48:52

border radius at 10 pixels for example.

4:48:56

And yeah, that looks pretty much like

4:48:59

the design for the image. Nice. Okay,

4:49:02

next up is the spacing. As you can see,

4:49:05

we have far too little space from the

4:49:07

gift section itself to the header

4:49:09

section above. And I could add that to

4:49:12

the top element here to the title for

4:49:14

example, but it makes a lot more sense

4:49:15

to add it to the container element

4:49:17

itself because it should control how far

4:49:20

it is between this container and the

4:49:22

container above. So let's do div section

4:49:26

margin top and for example 50 pixels.

4:49:29

That is much better and looks pretty

4:49:31

much like what we have here. Now you can

4:49:33

see that the space between the title and

4:49:35

the hint is very limited. It's not that

4:49:37

much space. Whereas here the default

4:49:39

margins for the H2 and H3 elements

4:49:42

create quite a lot of space in between

4:49:44

them. So now we probably have to work

4:49:46

with both the default margin that the H2

4:49:49

has at its bottom and the default margin

4:49:52

which the H3 has at its top. It doesn't

4:49:55

really matter what we start with. Let's

4:49:57

for example just start with the gift

4:50:00

hint and see what happens if we set the

4:50:02

margin top. Actually let's bring it up

4:50:04

on the side here. Now we've not done

4:50:06

anything with the margin top at all.

4:50:07

Let's set it to zero. You can see, hm,

4:50:10

nothing happened. Okay, that must be

4:50:12

because the margin top here and the

4:50:15

margin bottom under the H2 collapsed

4:50:17

into each other. And the margin bottom

4:50:19

for the H2 was probably larger than the

4:50:22

margin top for the H3. So removing it

4:50:24

served no purpose. That means that we

4:50:27

also need to try and remove the gift

4:50:29

titles margin at its bottom. Set it to

4:50:32

zero, for example. And there we go. Now

4:50:35

they're really crammed into each other.

4:50:38

Actually too much. They should have a

4:50:39

little bit of spacing in between them.

4:50:41

So let's try to instead of reducing that

4:50:43

to zero, we would set it to, for

4:50:44

example, 10 pixels. That looks much more

4:50:47

like the design we have here. Very good.

4:50:50

So you probably had different names on

4:50:52

your classes and different margins and

4:50:55

perhaps different borders and radiuses.

4:50:57

That doesn't matter. The important thing

4:50:59

is that you gave it a shot and got some

4:51:01

kind of result hopefully resembling

4:51:03

this. So, no matter what you did, great

4:51:06

job. Let's carry on with this course.

4:51:11

Okay. Now, we're going to prepare our

4:51:13

project so that we later can add the

4:51:16

hover feature. So, we're not going to

4:51:17

add the hover feature right now. We're

4:51:19

just going to set the stage for it. And

4:51:22

in order to do that, I'm going to first

4:51:24

mess up this project a little bit and

4:51:26

then it'll be your job to fix it because

4:51:29

we are not going to use the image tag

4:51:32

here in order to display this gift.

4:51:35

Instead, we are going to use a div tag.

4:51:38

So, I'm changing this into a div, which

4:51:41

means I also need to close it like that

4:51:43

because divs are not self-closing as img

4:51:46

tags are. And then next up, divs don't

4:51:48

have a source attribute. So we can't use

4:51:51

this in order to display the image. If I

4:51:53

now run this, you can see boom, suddenly

4:51:55

our image is gone. This src attribute

4:51:58

has no place here because instead we are

4:52:00

going to render this image through the

4:52:02

CSS background image property. So I'm

4:52:05

going to remove this one. If we run the

4:52:07

code again, you can see nothing else has

4:52:09

happened. And moving over to the CSS,

4:52:12

now it is your job to turn this weird

4:52:14

line here into something that looks like

4:52:17

this, which is exactly what we had

4:52:18

before. I messed up the code here. So,

4:52:20

you are to fix the gift img div because

4:52:24

I kept the class right here

4:52:27

so that it looks like the provided

4:52:29

design. And a little bit of a hint, it

4:52:32

needs a height. And if you wonder how

4:52:33

much, I want it to be a square, so equal

4:52:36

width and height. It also needs a

4:52:38

background image, which is how you'll

4:52:39

render this gift cover. It also should

4:52:42

be centered again because as you can see

4:52:44

here, this looks very much left aligned.

4:52:47

So basically what's happened here is

4:52:49

that the div has zero height because the

4:52:52

div has no content inside of it. So the

4:52:55

only thing that's visible is the border

4:52:57

which spans 400 pixels starting from the

4:53:00

left hand side and over towards the

4:53:01

right hand side. So go ahead and give

4:53:03

this a shot and then I will show you the

4:53:05

solution when you return back to me.

4:53:12

Okay, let's do this. First, it needs a

4:53:14

height, and it should be a square,

4:53:16

meaning equal width and height. So,

4:53:19

let's just do eight and set it to 400 px

4:53:23

like that. As you can see, we now have a

4:53:26

empty div on our page. Next up, we're

4:53:28

going to set the background image. So,

4:53:30

how do we do that? Well, you've seen

4:53:31

that one before. Background image URL

4:53:35

and then point it to the images folder

4:53:37

and the gift cover. Ape. And there you

4:53:42

go. But what is happening here? It seems

4:53:44

like we only kind of see the top left

4:53:47

corner of the image. That is because the

4:53:49

image itself is huge, much larger than

4:53:52

this 400x 400 pixel container. So, we

4:53:55

need to use our good old trend

4:53:58

background size and set that to cover.

4:54:00

And that squeezes our large image into

4:54:03

the current width we have available

4:54:05

here. Now, finally, why isn't this

4:54:07

element centered anymore? Well, the

4:54:09

centering of the image used to happen

4:54:11

because the text align is set to center.

4:54:13

But text align will only center inline

4:54:15

elements inside of its container. And as

4:54:18

you hopefully remember divs, they are

4:54:20

not in line. They are display block. And

4:54:22

and you might have tried to do display

4:54:26

inline like that. Then you can see that

4:54:29

doesn't really work. Then our width

4:54:31

property and height property gets this

4:54:33

weird underline underneath them because

4:54:35

they are simply ignored by CSS because

4:54:38

you can't force the width and height of

4:54:40

an inline element as they should only be

4:54:42

as large as the content inside of them

4:54:44

are. And this div doesn't have any

4:54:46

content. So we can't really use display

4:54:49

inline. What we rather can use is the

4:54:52

margin technique you learned earlier.

4:54:54

the one where you set the left and right

4:54:56

margin to auto because that works on

4:54:58

elements that are display block and

4:55:01

which have a set width. So let's do

4:55:03

margin zero on the top and bottom and

4:55:06

auto on the left and right. And there we

4:55:08

go. We have it centered. We are back to

4:55:12

our original design and we've set the

4:55:15

stage for our hover effect which Nick is

4:55:18

going to be so glad to experience. So,

4:55:20

it's really cool that you've made it

4:55:22

this far and let's just keep up the pace

4:55:24

and move on to the next scrim.

4:55:29

Hey there, it's Bob Zroll again and I'm

4:55:31

coming to you now with a quick update to

4:55:33

the lesson that used to be here. We're

4:55:34

going to have a quick aside to learn

4:55:36

about the hover pseudo class. To see

4:55:38

this, we're just going to use this

4:55:40

simple little app that we have here

4:55:42

where we have a restaurant menu. And the

4:55:44

user should be, of course, able to click

4:55:46

on any of these, which would

4:55:48

theoretically take you to a different

4:55:49

page. In the HTML, you can see we have

4:55:52

this semantic nav element, which

4:55:54

indicates that it will be a section of

4:55:55

navigation. And we kept it simple here

4:55:57

with three anchor tags to link to other

4:56:00

parts of our site. Now, currently, these

4:56:01

are just going to this hash mark, which

4:56:03

is sort of a placeholder. It won't

4:56:05

actually direct us anywhere different.

4:56:06

We can head over to the CSS and we can

4:56:09

see there's just a few rules here to

4:56:11

make these anchors look a little bit

4:56:12

more like buttons. We have the text

4:56:14

aligned to the center. The color of the

4:56:16

font is white. There's some margin to

4:56:18

separate it from other elements and some

4:56:20

padding inside. The background is the

4:56:22

red color that you see. We've increased

4:56:24

the font size. And because anchor

4:56:26

elements are typically display inline,

4:56:28

we changed that to block and then got

4:56:30

rid of the underline by using text

4:56:32

decoration none. And that's referring to

4:56:34

the underline that is typically there

4:56:35

when you have a link. Now, what would be

4:56:38

really nice with this menu is if we gave

4:56:40

some kind of visual feedback to the user

4:56:42

when they were hovering over the

4:56:43

different menu items here. I'm sure

4:56:44

you're not a stranger to this concept.

4:56:46

It's something that many websites do

4:56:48

when you're hovering over the

4:56:49

navigation. There's some kind of hover

4:56:50

effect that happens. And we can target

4:56:52

our CSS specifically to an element that

4:56:55

is currently being hovered by using the

4:56:57

hover pseudo class. The way we can do

4:56:59

this is by selecting our anchor just

4:57:02

like we did up above, but this time

4:57:04

putting a colon hover. This way any CSS

4:57:07

properties that we include here will

4:57:09

only be applied when the element is

4:57:11

currently being hovered. Or in other

4:57:13

words, whenever the mouse has entered

4:57:14

the perimeter of that element. So for

4:57:17

example, one thing we could do is when

4:57:19

the element is being hovered, we could

4:57:21

change the background color to this

4:57:23

hexodimal value here, which is a little

4:57:25

bit cryptic. doesn't really tell you

4:57:27

much about it, but just know that it's a

4:57:28

slightly darker shade of the red

4:57:30

background that we have when the item is

4:57:32

not being hovered. And you can see that

4:57:34

just by putting my mouse inside the

4:57:36

perimeter of that element, we get our

4:57:38

hover styles or this change in

4:57:39

background color applied and it's a much

4:57:42

more interactive experience. So, what's

4:57:44

happening here is we have added an

4:57:46

additional level of specificity or in

4:57:48

other words, we are being more specific

4:57:50

about this background color rule than we

4:57:53

were about the background that's up

4:57:55

here. And actually maybe just to have an

4:57:57

apples to apples, we could change this

4:57:58

to background color. That way we can see

4:58:00

that our anchor colon hover is being

4:58:02

more specific and therefore this

4:58:04

background color is being applied when

4:58:06

we hover. To be clear, this isn't

4:58:08

happening because we have written this

4:58:10

below our other anchor. I can move this

4:58:12

up above and see that the styles will

4:58:14

still apply just like they were before.

4:58:16

But rather it has to do with how

4:58:18

specific our rules are and the way CSS

4:58:20

is working under the hood, which we

4:58:22

don't have to dive into too deeply at

4:58:24

this point. But it's enough to know that

4:58:26

CSS is doing the intuitive thing just as

4:58:28

you would expect. Of course, background

4:58:30

color is not the only thing that we

4:58:32

could change here. We could change the

4:58:34

font size, for example, to let's call it

4:58:36

40 pixels and see that we can make as

4:58:38

many different changes as we want. And

4:58:40

now the hovered menu item is really

4:58:42

jumping out at you. I think that might

4:58:43

be a little bit much. So, I'm going to

4:58:45

get rid of that rule. On that vein of

4:58:47

being able to change other properties,

4:58:49

one cool trick that we can do, and this

4:58:50

will help us in the challenge that's

4:58:52

coming up in the next scrim is we could

4:58:54

do something like changing the

4:58:56

background image and we could set this

4:58:58

to a URL. We'll use this CSS URL

4:59:01

function as you are familiar with and

4:59:03

let's just point it to eyes.jpg

4:59:06

which we have inside of our files up

4:59:08

here. All right, let's see what happens.

4:59:10

I'm going to go to my menu and we'll see

4:59:12

that we get our friend Nick's eyes kind

4:59:15

of creepily looking at us through the

4:59:17

background of these menu items. Again,

4:59:19

this is a little creepy and probably the

4:59:21

strangest menu items you've ever seen on

4:59:23

a website, but hopefully this is a

4:59:25

perfect primer for the challenge that's

4:59:26

coming up on our birthday gift site as

4:59:28

we are just about ready to help Nick

4:59:30

unwrap his birthday presents. So, that's

4:59:32

what we'll be jumping into next.

4:59:36

Okay, now we are getting into the fun

4:59:38

stuff here because now we're going to

4:59:40

create this epic feature where Nick when

4:59:42

he hovers over the gift paper gets

4:59:45

revealed an underlying gift that makes

4:59:47

him feel happy and appreciated on his

4:59:50

birthday. So the challenge is described

4:59:52

here. You are to swap the gift paper

4:59:54

image out with the happy gift when you

4:59:58

hover over the gift paper. So the happy

5:00:01

gift is added here in the images folder.

5:00:03

I'm not going to show it to you. I want

5:00:05

you to solve this challenge in order to

5:00:06

see this gift. Now, the gift paper image

5:00:09

you are to swap out is this div right

5:00:12

here. As you remember, we gave it a

5:00:15

background image, which is the gift

5:00:17

cover.jpeg file, which also is in our

5:00:19

images folder. So, go ahead and solve

5:00:21

this challenge right now, and then I

5:00:22

will show you the solution when you

5:00:24

return back to me.

5:00:30

Okay, hopefully that went well. What

5:00:32

we'll do is first target this gift img

5:00:35

here as we want to create a hover effect

5:00:37

on it. So I'll do gift img colon hover.

5:00:42

Now whatever CSS properties and values

5:00:45

we are setting inside of these curly

5:00:46

brackets will be applied when the user

5:00:49

hovers over this gift image. And what

5:00:52

kind of properties do we want to change?

5:00:54

Well, it's actually only one, just the

5:00:56

background image here. So, I'm going to

5:00:58

copy that one, paste it in, and we don't

5:01:00

want it to be the gift cover.jpeg. We

5:01:02

want it to be the happy.gif.

5:01:05

Like that. Let's see how this works.

5:01:07

I'll move the cursor down towards the

5:01:09

image. And when it crosses over, we see

5:01:12

Phoebe and Rachel from Friends being

5:01:14

super happy for Nick on his birthday.

5:01:17

And I don't know about you, but if

5:01:18

someone told me that they would be this

5:01:20

happy for me on my birthday, it would

5:01:22

make me feel so grateful and

5:01:24

appreciated. So, we are really doing a

5:01:26

good deed creating this website. And you

5:01:29

know what? You've done a great deed for

5:01:30

yourself in terms of getting this far in

5:01:32

the course. You have crushed through so

5:01:34

many difficult CSS concepts. So, Phoebe

5:01:36

and Rachel are also cheering for you.

5:01:38

Take a moment to appreciate that and

5:01:40

then I will see you again in the next

5:01:41

scrim.

5:01:44

Okay, now that we've made sure that Nick

5:01:46

feels appreciated on his birthday

5:01:48

through this Phoebe and Rachel gift,

5:01:50

let's make sure he also feels really

5:01:52

good-looking because now we're going to

5:01:54

create this gift right here, which says

5:01:56

how people react when you enter the

5:01:58

room. And the GIF will show when he

5:02:00

hovers over this element is this hot GIF

5:02:04

up here. I'm not going to show it to you

5:02:05

now. You're going to have to solve the

5:02:07

challenge to see it. And speaking of

5:02:08

that, let's have a look at the challenge

5:02:10

text. So you are to create the next gift

5:02:14

which uses the hot GIF and its HTML

5:02:17

structure should be like the previous

5:02:19

one but without the gift hint element

5:02:22

because as you can see here we have this

5:02:23

hint written in parenthesis. However,

5:02:27

that's not needed for this one. I think

5:02:28

Nick will probably get the point by the

5:02:30

time he scroll down to this one. So

5:02:33

let's just skip it. But other than that

5:02:35

you can simply copy paste this section

5:02:37

and then of course change the text as

5:02:39

well. However, you will need to do some

5:02:41

more things as well because now that you

5:02:44

have multiple gifts on the page, you

5:02:47

cannot use the gift image class to set

5:02:49

the background image on hover. That is

5:02:52

this one right here. Because if you have

5:02:54

multiple gift image elements on the

5:02:57

page, well then every single one of them

5:02:59

will just show this happy gift. And

5:03:01

that's obviously not what we want. So

5:03:04

instead, each of the gifts will need a

5:03:07

unique ID that controls which background

5:03:10

image that should be shown when the user

5:03:13

hovers over the element. Okay, that was

5:03:15

probably a lot to parse for you. But if

5:03:17

you didn't quite catch it, just go ahead

5:03:20

and try to solve the challenge because I

5:03:22

think you will see this problem sooner

5:03:23

or later anyway. You definitely will,

5:03:26

actually. So make it your best shot and

5:03:28

then of course I will show you the

5:03:29

solution when you return back to me.

5:03:36

Okay, let's do this. So, starting in the

5:03:39

HTML by simply copying this one right

5:03:43

here and pasting it in down here,

5:03:45

removing the gift hint because we don't

5:03:47

need that. And then updating the title.

5:03:50

Let's run the code now. And here we can

5:03:52

see the first element with Phoebe and

5:03:54

Rachel. Let's scroll a bit down. And

5:03:57

there we have our second element, though

5:03:59

it still shows Phoebe and Rachel. So

5:04:02

that is a problem and that is because as

5:04:04

I said this gift image class just sets

5:04:07

the background image on hover to the

5:04:10

happy gift on both of these elements

5:04:12

right now. So we can't use a class for

5:04:14

this. We need a unique ID. But we're not

5:04:17

going to remove the class of gift img

5:04:20

because it actually gives a lot of

5:04:23

styling actually all the styling to the

5:04:26

element. So it's only the hover pseudo

5:04:28

class that needs to be applied to

5:04:30

something else. So let's instead now on

5:04:33

the first one here add an ID that we'll

5:04:36

call gif- img-happy.

5:04:40

We'll run the code so that it's applied

5:04:42

and then instead of referring to the

5:04:44

generic class here refer to this gift

5:04:47

img happy ID. Now, if we run the code,

5:04:52

you can see that it works on the first

5:04:55

gift, though the second gift now lacks a

5:04:58

hover effect. And that is because the

5:05:00

only hover effect we've applied now is

5:05:02

on this specific ID here on the first

5:05:05

gift. Previously, we used the generic

5:05:08

gift img class. So, it was applied to

5:05:10

all gift images, but now the hover only

5:05:13

works on the first one. So, what we need

5:05:14

to do is use this exact technique, but

5:05:17

on this section as well. So I'll create

5:05:19

an ID on this section and call it gift

5:05:24

bash img bash hot. I'll run the code so

5:05:28

that it's applied.

5:05:30

And then since I'm lazy, I'll copy this.

5:05:34

Gift img happy should be changed to gift

5:05:37

img hot because that is our new ID that

5:05:39

targets that element. And we don't want

5:05:42

to show the happy gift. We want to show

5:05:43

the hot gift. So let's see if this

5:05:46

works. Here we are at the section. When

5:05:49

we hover over the image, we see someone

5:05:51

looking pretty interested in Nick. So, I

5:05:55

think he will feel really goodlooking

5:05:57

and hot on his birthday when he sees

5:05:59

this gift. So, great job solving this

5:06:02

challenge. Let's move on.

5:06:06

As you can see over in the file system,

5:06:08

I've added a genius GIF and a badass

5:06:11

GIF. So, your job is now to create the

5:06:15

genius and badass gift sections. They

5:06:18

should look exactly as the hot section.

5:06:21

So, I'm not going to give you any more

5:06:22

instructions other than giving you the

5:06:24

titles so that you can just copy them

5:06:26

from here instead of writing them out on

5:06:29

your own. So, go ahead and create these

5:06:31

two sections right now and then I will

5:06:33

show you the solution when you return

5:06:35

back to me. Good luck.

5:06:42

Okay, let's do this. So, I'm going to

5:06:45

start in the HTML file because we're

5:06:47

simply going to copy paste this one

5:06:52

two times.

5:06:55

Then I'm going to add the titles. I'll

5:06:58

copy this one and paste it in here. And

5:07:02

copy this one and paste it in here.

5:07:07

Okay, let's run this

5:07:10

now. You can see we have the hot gif and

5:07:13

then the genius section which still has

5:07:15

the hot gif underneath it. That's to be

5:07:18

expected. And there we have the badass

5:07:19

section which also still has the same

5:07:21

GIF. So now we have the sections

5:07:24

rendered on the page at least. But we

5:07:26

need to fix up the CSS. So lazy as I am,

5:07:30

I'll copy this one here. It says gift

5:07:32

image hot. The first one will be the

5:07:35

genius one. I'll do genius instead. That

5:07:39

should refer to the genius gif. Now that

5:07:42

we have this in place, we can just give

5:07:44

this class to the respective image like

5:07:47

that. Running the code. And we have the

5:07:51

happy gif, we have the hot gif, and then

5:07:54

the genius gift. That is pretty cool. I

5:07:58

surely think Nick will appreciate this

5:08:00

compliment. Okay, the final one here.

5:08:03

The keyword is badass. So I'll change

5:08:06

the ID to badass now that we are in the

5:08:08

HTML

5:08:11

and moving on to the CSS. Copy this and

5:08:15

change from genius to badass because

5:08:18

that's the ID we just created. And the

5:08:21

GIF we want to fetch out from our images

5:08:23

folder is the badass.gif.

5:08:25

Let's open up our example again. Scroll

5:08:28

down to who is the only person as badass

5:08:31

as you. It is of course Chuck Norris.

5:08:34

All right, we are done with this

5:08:37

challenge. Great job. Let's move on.

5:08:43

Now, it's finally time to add the very

5:08:46

last gift, and that is the chairs gift.

5:08:50

So, you're going to add this section,

5:08:51

but there's a little difference between

5:08:52

this section and the previous ones

5:08:54

because, as you can see here, it is not

5:08:57

squared, but rather more rectangular. So

5:09:00

what I want you to do is give the gift

5:09:02

section a height of 200 pixels which is

5:09:05

different from the original height that

5:09:07

we controlled up here on the gift img

5:09:10

class where we set it to 400 pixels. So

5:09:13

the way you are to change this or

5:09:15

override it is by selecting the gift img

5:09:18

chairs ID which you are going to create

5:09:21

just like you've created ids for all the

5:09:23

other gift images as well. And then

5:09:25

you're going to set the height on that

5:09:27

element which essentially means to

5:09:30

override the previous height. And

5:09:32

finally here is the text as well along

5:09:34

with the chair skiff up in the file

5:09:36

system here. And I really think you'll

5:09:38

enjoy this one. So go ahead and give it

5:09:40

your best shot and then I will show you

5:09:42

the solution when you return back to me.

5:09:49

Okay, let's do this. I'll start in the

5:09:50

HTML by again copy pasting the preview

5:09:54

section and here I need to change the

5:09:57

text first. So I'm going to do

5:10:00

like that

5:10:03

and then we're not going to have that

5:10:04

ask but rather it shares.

5:10:07

So running this we can see we have a

5:10:09

squared image in place. That's not

5:10:12

exactly what we want. So we need to do

5:10:13

the next step which is to use this ID

5:10:16

which we just created and override the

5:10:19

height. I'll do height 200 pixels like

5:10:22

that. And there we can see it is now

5:10:25

just as we want it. The final step then

5:10:27

is to use this hover pseudo class in

5:10:30

order to change the background image to

5:10:33

chairs. Oh, copy this one and do chairs

5:10:38

instead. And now if we hover over it, we

5:10:40

see Leonardo DiCaprio in a smoking

5:10:43

giving us a toast. Really nice.

5:10:47

And one thing I want to mention here is

5:10:50

that you might be a little bit confused

5:10:52

as to why this height property takes

5:10:55

precedence over this height property.

5:10:58

And it is actually not because this is

5:11:01

written further down in the CSS file.

5:11:04

Actually, if we remove it to even

5:11:06

further up in the CSS file, even though

5:11:09

CSS reads from the top and then

5:11:11

downwards, this still takes precedence

5:11:14

over this. And that is because of

5:11:16

something called specificity. Which

5:11:18

means that the more specific a CSS

5:11:21

selector is, the higher it will be

5:11:23

prioritized. And this ID selector is a

5:11:26

more specific selector than the class

5:11:28

because as you know only one element can

5:11:31

have an ID whereas multiple elements can

5:11:34

share the same class. So ids are more

5:11:37

specific than classes. Now I don't want

5:11:39

to get more into specificity. We're

5:11:41

going to learn more about that later in

5:11:43

the front end developer career path. For

5:11:45

now I just wanted to mention it in case

5:11:46

you were a little bit confused. So, we

5:11:48

have now done all of the gifts and we

5:11:52

have a super cool birthday page we can

5:11:54

send to Nick. There's just a few things

5:11:56

left and then we are completely done

5:11:58

with this epic birthday site. So, I'll

5:12:01

see you in the next scrimm.

5:12:06

Now, you are going to create the footer

5:12:08

for our site and it should have a

5:12:10

paragraph that says, "Want to create

5:12:12

your own birthday gift site? take this

5:12:14

HTML and CSS course with a link to well

5:12:17

this exact HTML and CSS course and I

5:12:21

want you to configure the anchor tag so

5:12:23

that it opens up the link in a new tab

5:12:25

and if you've forgotten how to do that

5:12:27

well then you simply have to Google it.

5:12:30

I've provided the link right here and

5:12:32

also the text so that you don't have to

5:12:34

write that out on your own. However,

5:12:36

outside of that, I'm not going to give

5:12:38

you any more hints, but I want you to

5:12:39

notice that there is some spacing around

5:12:42

this paragraph, both above it and

5:12:44

beneath it. You can see it doesn't touch

5:12:46

the bottom of the site. And also, it is

5:12:49

centered. It's about as wide as the

5:12:51

images themselves, and it's also in

5:12:53

italic. So, you're going to have to

5:12:55

figure out how this translates into CSS.

5:12:58

I think you can do it. Go ahead and give

5:13:00

it your best shot, and then I will see

5:13:01

you again when you return back to me.

5:13:09

Okay, let's do this. So, I'll head over

5:13:11

to the HTML and add a paragraph which

5:13:15

I'll give an ID of footer. And let's

5:13:18

paste in the text

5:13:22

like that. And also the link

5:13:27

else we need to create an anchor tag and

5:13:30

it should be around this HTML and CSS

5:13:33

course. So we'll start the anchor tag

5:13:36

here. Do an href

5:13:40

and then in order to open the anchor tag

5:13:42

in a new tab, we'll do target equals

5:13:45

underscore blank. And then we'll close

5:13:48

it off at the end here.

5:13:51

Let's run this. Okay, so we have now

5:13:54

something that looks not too far from

5:13:57

our design. It's decent, but still a lot

5:13:59

of things lacking. First of all, this

5:14:02

text is far too wide. It should be more

5:14:05

or less the same width as the images.

5:14:08

So, let's do

5:14:12

footer.

5:14:14

Set the width to 400 pixels. Okay. What

5:14:18

happened now? Well, we do have text line

5:14:21

center, but now that this is 400 pixels

5:14:24

wide and it's still a display block

5:14:26

element as paragraph is that the text

5:14:28

line center won't center the content

5:14:31

here inside of its container. So, we

5:14:34

need to center it using the margin

5:14:36

technique. Meaning that we'll do margin

5:14:38

zero at top and bottom and then auto at

5:14:41

left and right. Yes, there it is

5:14:43

centered. But actually, we do want some

5:14:45

margin at the top and bottom because, as

5:14:47

you can see right here, it has some

5:14:48

spacing above and a little bit more

5:14:50

spacing beneath it. So, let's try 40

5:14:52

pixels on top. Yeah, that's pretty good.

5:14:56

And now 40 pixels at the bottom. That's

5:14:58

a bit too much in my opinion here. It

5:15:00

looks more like 20 or something. So,

5:15:02

let's rather than do 20 pixels like

5:15:04

that. Now, we have 40 at top, auto at

5:15:07

left, right, and 20 at bottom. And that

5:15:10

looks pretty good to me. However, one

5:15:13

obvious thing we need to fix is that

5:15:15

this anchor tag should also be white.

5:15:18

So, I'm going to target the element

5:15:20

itself. New color white like that. Now,

5:15:25

I think the final step we have is to

5:15:27

make it itallic. And that's done up here

5:15:29

where we can do font style

5:15:32

italic.

5:15:34

And there we go. That looks identical in

5:15:37

my eyes. So, really good job. I'll see

5:15:40

you in the next scrimm.

5:15:45

Okay, now we're going to talk about

5:15:47

gradients. And that's something you've

5:15:48

probably seen many times in nature,

5:15:51

though not really thought much about

5:15:53

because, for example, because the sky is

5:15:55

full of gradients. Here you can see a

5:15:57

sky that kind of fades from a light blue

5:16:00

color into a whitish color. And this

5:16:03

fade is basically a gradient. Here's

5:16:06

another example where it starts almost

5:16:07

black at the top and then slowly fades

5:16:10

over into purple and then again into a

5:16:13

orangeish or light brown or I don't know

5:16:16

what you want to call this color, but

5:16:18

you get the point. It's fading from one

5:16:20

color to another. And this is very often

5:16:22

used in web design and you can and you

5:16:24

can do it with CSS pretty easily. Let's

5:16:27

for example remove this background image

5:16:30

of the gift card from our gifts. Now you

5:16:32

can see it's just transparent.

5:16:36

and then instead we'll write background

5:16:39

and linear dash gradient

5:16:43

and then two parenthesis. So this looks

5:16:46

a little bit like the URL keyword we

5:16:48

write when we want to refer to images.

5:16:50

Meaning that this is also a so-called

5:16:52

CSS function. Now inside of the

5:16:54

parenthesis we simply write the two

5:16:56

colors we want to fade from and to. So

5:16:59

let's do from red to blue. And boom,

5:17:01

there you go. Now you can see that all

5:17:04

of our gifts fade from red down to blue.

5:17:07

And by default, it starts with the first

5:17:09

color at the top and then the second

5:17:11

color at the bottom. So let's try to

5:17:13

mimic this image here in CSS. I happen

5:17:16

to know that there's a CSS color called

5:17:18

light sky blue. So if we start with that

5:17:22

one and go down to white and have a look

5:17:25

at this gradient here. Actually to me

5:17:28

it's kind of similar to this one we have

5:17:31

here. Not quite, but you get the point.

5:17:33

Okay, now I'm going to remove this, give

5:17:36

us our gift cover back, and then give

5:17:38

you a challenge because now I want you

5:17:40

to change our site's background into a

5:17:43

gradient that goes from blue at the top

5:17:45

to pink at the bottom. And let me show

5:17:49

it to you. Let me and and let me here

5:17:51

show you how it will look. I'm going to

5:17:53

do some magic now. I'm going to knit my

5:17:54

fingers and then the gradient and then

5:17:56

the gradient will be applied

5:17:58

automatically.

5:18:00

pretty nice. But now you can see the

5:18:02

bottom here is pink and if we scroll up

5:18:05

it slowly fades over into blue and at

5:18:08

the top it's totally blue. So this makes

5:18:10

the site slightly more fancy which I

5:18:13

think is cool and matches the birthday

5:18:14

team. So now I'm going to knit again and

5:18:17

the gradient will be gone like that. Now

5:18:20

our site is blue all the way from the

5:18:23

bottom to the top and it's your job now

5:18:25

to get the gradient back. So go ahead

5:18:27

and do that right now.

5:18:33

Okay, let's do it. So, the property we

5:18:36

need to fix is the background on the

5:18:37

body because we need here a linear

5:18:41

gradient

5:18:43

going from the blue color it used to

5:18:46

have to the pink color which we've been

5:18:49

using as a border of our image of Nick.

5:18:52

So then I'll simply paste that one in

5:18:54

right here. Now we should be fading from

5:18:56

blue to pink.

5:18:58

Let's see. We can see the blue. And yes,

5:19:01

it looks like it is slowly fading

5:19:03

towards pink. Really good job. Now

5:19:06

you've learned a super cool CSS

5:19:08

technique. I'll see you in the next

5:19:10

scrim.

5:19:13

Okay, now that we have completed Nick's

5:19:15

birthday site, I want you to make it

5:19:18

your own. So, first try to think of

5:19:20

someone whose birthday is upcoming. It

5:19:23

could be a friend, a family member, a

5:19:25

celebrity, yourself, or even me. I would

5:19:29

love to get tons of these sites sent my

5:19:31

way on my birthday on January 26th. And

5:19:34

then once you figured out who to send

5:19:36

this to, make this site about them,

5:19:39

meaning that I think you should choose

5:19:41

your own gifts. You can just drag and

5:19:43

drop a GIF file into the images folder

5:19:45

here and then refer to it in the code.

5:19:48

Though, be aware that Scribba sets

5:19:49

certain size limitations on GIFs. So, if

5:19:52

it doesn't work to upload it, you might

5:19:54

instead just want to grab the URL for a

5:19:57

GIF you can find online, copy it, and

5:20:00

paste it in right here, so that Scribba

5:20:02

isn't hosting it, but rather the website

5:20:04

where you originally found the GIF.

5:20:07

Another thing you can do is change

5:20:09

around on the text for the gifts. And of

5:20:11

course, also, if you really want to go

5:20:13

crazy, feel free to change around on the

5:20:15

design. Perhaps you want to use other

5:20:17

colors, other fonts, and in general, be

5:20:20

creative and make it your own. Finally,

5:20:22

you have to deploy this to the web.

5:20:24

That's the whole point with this site

5:20:26

because the person who has a birthday

5:20:28

needs to see it. So, you know how to do

5:20:30

that as we've done that already earlier

5:20:32

in this course. And I would love to see

5:20:35

your site in I built this. So, feel free

5:20:38

to drop the link to your deployed site

5:20:40

in this channel if you are up for it. So

5:20:43

hopefully I'll see tons of these in the

5:20:45

I Built This channel and I'll also see

5:20:46

you in the next scrim.

5:20:51

It is not just Nick who deserves a

5:20:53

congratulation on this day. You too, my

5:20:55

friend, deserve exactly that. Congrats

5:20:58

on completing this section. Let's now

5:21:01

take a look at what you've learned.

5:21:02

Early on, we took a deeper dive into

5:21:05

Flexbox and learned about align items.

5:21:07

this property here which aligns the

5:21:09

items in a flexbox container along the

5:21:12

crossaxis. And speaking of axis, you

5:21:15

learned how to flip the main axis of a

5:21:17

flexbox using the flex direction

5:21:19

property. We set it to column here,

5:21:21

which is the opposite of the default row

5:21:24

value. So then flipping the direction

5:21:26

from being horizontal to being vertical.

5:21:28

You also learned about a super cool

5:21:30

pseudo class called hover which allowed

5:21:33

us to create this epic feature where

5:21:35

Nick hovers over the image and sees the

5:21:37

underlying GIF. And you learned about

5:21:39

another cool CSS feature which is how to

5:21:42

create gradient so that the background

5:21:44

of this website slowly fades from blue

5:21:47

to pink. And we achieved that using the

5:21:49

linear gradient function which we added

5:21:52

to the background of the body. A final

5:21:54

thing we touched briefly upon was the

5:21:56

grouping selector, which allowed us to

5:21:58

make our CSS syntax much more compact as

5:22:01

we could target all of these HTML tags

5:22:03

instead of having to recreate this text

5:22:06

shadow rule again and again on new

5:22:08

lines. So, you have made a ton of

5:22:10

learnings. Make sure you take a break

5:22:12

and get some rest. And then I will see

5:22:14

you back here in the next section when

5:22:16

you are ready.

5:22:20

Welcome to the final section of this

5:22:22

course. And here it is time for you to

5:22:25

go solo. And what do I mean about that?

5:22:27

Well, you know how I've kind of been

5:22:29

peeking over your shoulder, helping you

5:22:31

step by step throughout all of the

5:22:33

projects we've built? Well, that time is

5:22:36

over. Now, I'm going to remove the

5:22:39

training wheels and you will have to

5:22:41

build a full project on your own because

5:22:44

that's actually the only way you can

5:22:46

know whether or not you've truly learned

5:22:48

HTML and CSS. So, you're going to build

5:22:51

a so-called solo project. And the

5:22:54

project is a homepage for your hometown.

5:22:57

You can see it here on the right hand

5:22:59

side. This version right here happens to

5:23:01

be about my hometown or the place I grew

5:23:04

up in Oslo, Norway. It's a part of the

5:23:06

city called Torchov. However, the point

5:23:08

with this is not for you to build

5:23:09

exactly this, but rather build a website

5:23:11

about a place, area, city, or country

5:23:14

that you care about and you have a

5:23:15

connection to. Because when you do that

5:23:17

and then share it in the Discord

5:23:19

community, it'll give an opportunity for

5:23:21

other students on Scribba to get to know

5:23:23

you better. And hopefully you'll enjoy

5:23:24

building it as well because it is about

5:23:26

the place you care about. Now, I'm going

5:23:28

to go deeper into the content of the

5:23:30

solo project in the next Scrim. But for

5:23:32

now, there's one thing you need to do,

5:23:34

and that is to head over to figma.com.

5:23:37

Because Figma is the design tool in

5:23:39

which you'll get the design for your

5:23:41

project. It is the most popular design

5:23:43

tool these days. It can kind of be seen

5:23:46

as the GitHub equivalent for designers.

5:23:49

So I want you to click on this image

5:23:51

right here and then you'll be taken to

5:23:52

figma.com. There, click on sign up and

5:23:55

create an account. And I also want you

5:23:57

to click on this image right here. Is

5:23:59

that'll take you to a quick 10-minute

5:24:01

Figma tutorial which Bob Zerole, our

5:24:04

teacher here at Scribba created

5:24:06

specifically for students who need to

5:24:08

learn a little bit of Figma in order to

5:24:09

do solo project here on Scribba. So you

5:24:12

can either watch this right now or you

5:24:14

can wait until you've started the solo

5:24:16

project when you feel the need for some

5:24:18

guidance through the Figma interface.

5:24:20

The reason this is at YouTube and not

5:24:22

here on Scribba is because learning a

5:24:24

browserbased tool like this is actually

5:24:26

better to do via a regular video than

5:24:28

via slides here on Scribba. So with

5:24:30

that, let's move on and take a closer

5:24:32

look at the actual solo project.

5:24:38

Now it is time for you to solve your

5:24:39

very first solo project, the hometown

5:24:42

homepage. And here it is. As you can

5:24:44

see, it is a website that consists of

5:24:46

three sections. The hero here has a

5:24:49

background image and a heading and

5:24:51

subheading. There's the activities

5:24:53

section, which has a title and three

5:24:56

columns, each one containing an image, a

5:24:58

heading, and a paragraph. And then

5:25:00

there's finally this card at the bottom

5:25:02

which is meant to introduce you to a

5:25:04

tourist guide for this area. And you

5:25:07

might look at this and think, how on

5:25:08

earth am I supposed to create all of

5:25:10

this? Well, take a look at each of the

5:25:12

elements and think back at what we've

5:25:14

done in this course. For example, this

5:25:17

hero section here with a background

5:25:19

image and another section beneath it.

5:25:21

Well, that's pretty similar to what we

5:25:23

did in the space exploration site. And

5:25:26

these two headings right here with the

5:25:28

background colors. Well, that's what we

5:25:30

did in the birthday gift card with the

5:25:32

year element and the date element. And

5:25:34

as for the card down here, I think that

5:25:37

resembles our business card quite a lot.

5:25:40

Finally, the three columns we have in

5:25:42

the activity section, well, that looks

5:25:44

like a job for flexbox if you ask me.

5:25:46

And we've used flexbox multiple times.

5:25:49

Even the way we use it here where

5:25:50

actually all of the three flex children,

5:25:53

the items are containers in themselves

5:25:56

which contain an image, a heading, and a

5:25:58

paragraph. So I think you got this.

5:26:00

Let's then look at the specific

5:26:02

requirements. First of all, you're going

5:26:04

to build it from scratch or I'm saying

5:26:06

that with quotes because I've actually

5:26:09

added a little bit of a skeleton here

5:26:11

for you. So you can see what we got.

5:26:14

basically a version with hardly any

5:26:15

styling but with some of the elements in

5:26:18

place. You can see there's the hero

5:26:20

section here. There's the activity

5:26:22

section. It doesn't have all the data

5:26:23

but at least the three images. And then

5:26:26

there's the guide section at the bottom

5:26:28

here. Obviously though it looks terrible

5:26:30

because the only styling I've applied is

5:26:32

some margin zero on the body and I've

5:26:34

aligned the text to the center and also

5:26:36

limited the width of the images to 100

5:26:38

pixels. So you can use this as a

5:26:41

starting point if you want or you can

5:26:43

wipe it out and do it completely from

5:26:44

scratch. That's up to you. Next I want

5:26:47

you to make sure that you do use classes

5:26:50

flexbox the background image property

5:26:53

and also the color plet that I'm

5:26:55

providing. As you can see in the CSS

5:26:57

here are the hex values for the color

5:27:00

pallet I'm using. And also I have a link

5:27:02

to coolers here. You can click this

5:27:05

image and you'll be taken to the color

5:27:06

palette. And then once you're done, if

5:27:08

you are up for it, there are some

5:27:09

stretch goals. First, make it about your

5:27:12

own hometown, country, or whatever place

5:27:14

you like. I hope everyone wants to do

5:27:16

this because when you share it in the

5:27:18

Scribba community, we will get to know

5:27:20

you a little bit better. Secondly, if

5:27:22

you use a different color palette, your

5:27:23

site will be even more unique. And if

5:27:26

you add a Google font, you can really

5:27:27

level up the design because I've not

5:27:29

done that. And as a result, the font

5:27:31

here is a little bit boring. Also, if

5:27:33

you want to go crazy, find a way to use

5:27:35

the hover pseudo class on any of these

5:27:37

elements. That would be super cool. And

5:27:39

finally, you could add an entire new

5:27:41

sections. That would be so cool.

5:27:43

However, do remember that these stretch

5:27:45

coils are optional. You don't have to do

5:27:47

them, but I would encourage you to give

5:27:49

it a shot if you have the energy. So,

5:27:51

moving on. To get to the actual Figma

5:27:53

file, click on this image right here.

5:27:56

And if you get confused, do remember the

5:27:58

Figma tutorial I talked about in the

5:28:00

previous scrim. You can click on this

5:28:01

link right here to get to it. Now, if

5:28:03

you're watching this on YouTube, these

5:28:05

links have also been added to the

5:28:07

description below the video and they are

5:28:09

in the corresponding GitHub repo for

5:28:11

this course. Finally, you can do this

5:28:13

solo project either locally on your

5:28:15

computer or here at Scribba. If you do

5:28:18

it here at Scribba, I would recommend

5:28:19

you to click on the three dots in the

5:28:21

bottom right corner and choose fork to

5:28:24

new scrim as that'll give you your very

5:28:26

own scrim to work on instead of just

5:28:28

working on a note on the timeline of

5:28:31

this specific lesson. So, I will leave

5:28:33

you with these requirements so that you

5:28:35

can look back at them when you need to.

5:28:37

With that, I wish you the best of luck.

5:28:39

You got this. Happy coding.

5:28:44

Oh, wow. Did you just complete a

5:28:47

fivehour long module here on Scribba?

5:28:51

Wow, that is amazingly well done.

5:28:55

Because you know if this is the number

5:28:57

of people who start learning HTML and

5:29:00

CSS, this is the number of people who

5:29:03

actually learn it and you belong in this

5:29:05

group. So you are truly something

5:29:08

unique. So actually I think you should

5:29:10

brag about this as much as you can. For

5:29:13

example, in the today I did channel on

5:29:15

Discord or in one of the module channels

5:29:18

or to whomever is in the same room as

5:29:20

you. Make sure that you communicate to

5:29:22

the world that you rock because you are

5:29:25

the kind of person that completes online

5:29:27

courses. A rare breed in today's day and

5:29:30

age. So feel free to rest a little bit

5:29:33

as well and then I will see you when you

5:29:35

are ready to tackle JavaScript in module

5:29:38

3.

5:29:42

Hi there, it's Pier from Scrimby here

5:29:44

again. You are doing a phenomenal job

5:29:46

plowing through this path and I feel

5:29:48

super privileged to be able to follow

5:29:50

you into the exciting world of

5:29:52

JavaScript as well. We are going to

5:29:54

build a bunch of cool projects together.

5:29:56

Starting out with a very simple

5:29:58

passenger counter until we up the game

5:30:00

and build a blackjack game. You are also

5:30:03

going to practice your skills through

5:30:04

building a password generator, a unit

5:30:07

converter, and even a Chrome extension

5:30:09

that serves as a tool for salespeople in

5:30:12

order to track their leads. So, it's

5:30:14

going to be a lot of fun. And I can

5:30:16

promise you that learning your very

5:30:18

first proper programming language really

5:30:20

changes how you think. You're going to

5:30:22

feel like you've become somewhat of a

5:30:24

genius at the end of this path, having

5:30:26

unlocked a whole new level of logical

5:30:28

thinking in your brain. So, let's just

5:30:30

dive in and learn some JavaScript.

5:30:36

Your very first exposure to JavaScript

5:30:38

will come through building a passenger

5:30:40

counter app. Now, you might ask

5:30:42

yourself, why on earth should we build a

5:30:44

passenger counter app? What's the point

5:30:46

of that? Well, you'd be surprised

5:30:49

because when I was 19, right around this

5:30:51

time, my full-time job was to count

5:30:53

people who entered the subway. So every

5:30:54

day I would stand outside in the cold

5:30:56

and be like, "Oh, so there's 1 2 3 4 5

5:31:00

six people entering the subway this

5:31:02

morning. How interesting." And then I

5:31:04

would bring up my pen and paper and note

5:31:06

down the number six, which at times was

5:31:08

really cold. So it would have been so

5:31:10

much better if I had a little people

5:31:12

counter app on my Nokia phone so that I

5:31:14

could just tap these buttons while

5:31:16

having the phone in my pocket. But this

5:31:18

was long before I learned to code. So

5:31:20

instead we are going to build this

5:31:22

passenger counter app together so that

5:31:24

you will learn the basics of JavaScript

5:31:26

and so that you are prepared in case you

5:31:29

one time in the future have to stand

5:31:31

outside in the cold counting people who

5:31:33

enter the subway.

5:31:37

Welcome to this lesson where we are

5:31:38

going to take a look at the setup for

5:31:40

our people counter app. Here you can see

5:31:42

we have a basic HTML structure which

5:31:45

probably looks familiar to you. You can

5:31:47

see we have the HTML tag, the head tag,

5:31:49

and inside of the body, we only have two

5:31:51

elements, the H1 and an H2. That is the

5:31:55

title up here, and our counter element.

5:31:57

We also have some styling in our

5:31:59

index.css.

5:32:01

You can check it out here. This is just

5:32:02

very basic styling that we're not going

5:32:04

to go through because you want to get

5:32:05

into the JavaScript as soon as possible.

5:32:07

So, the first thing we're going to do

5:32:09

actually is to simply inside of our body

5:32:12

tag create a so-called script tag like

5:32:16

that. Looks just like any other HTML

5:32:18

tag. It just says script. And inside of

5:32:21

here, you can actually write JavaScript.

5:32:24

So, inside of this tag, I'm going to

5:32:25

write a pretty long JavaScript

5:32:27

expression that you probably find a

5:32:28

little bit frightening, but don't worry

5:32:30

about that. You're not meant to really

5:32:32

understand it in this lesson. I just

5:32:33

want to demonstrate that this works. So

5:32:35

I'm going to start by writing document

5:32:38

that refers to the HTML document itself.

5:32:40

And then I'll do dot and get element

5:32:45

by id and then open and close

5:32:47

parenthesis.

5:32:49

Then inside of the parenthesis I'm going

5:32:51

to copy the ID of our H2 element. So

5:32:55

here we're saying hey HTML document I

5:32:58

want to get an element and I want to get

5:33:00

it by its ID and the ID is this count L.

5:33:04

So what do you think we get as a reply?

5:33:05

Well, we grab a hold of this element

5:33:07

right here. And then we can do dot inner

5:33:11

text set that equal to, for example,

5:33:14

five. If I now run this code, you'll see

5:33:17

that boom, we have changed the text on

5:33:20

the inside of the H2 element, this one

5:33:23

right here, from zero to five using

5:33:26

JavaScript. And that opens up a whole

5:33:29

world of opportunities. It essentially

5:33:31

gives us the power to breathe life into

5:33:34

our application and turn it into a

5:33:36

realworld product that solves problems

5:33:39

for people. That's why this is so cool

5:33:41

to learn. However, we are not going to

5:33:43

write our JavaScript this way here. It's

5:33:45

kind of an amateurish way to do it. What

5:33:47

we rather want to do is create an

5:33:49

index.js file like that. Here is our

5:33:52

index.js file. It's currently empty. But

5:33:55

what I'm going to do is copy this line

5:33:58

here.

5:34:00

Then paste it into the index.js file.

5:34:03

And now

5:34:05

add an attribute to my script tag called

5:34:08

src, which is short for source. And then

5:34:12

inside of here, I'm just going to write

5:34:13

index.js.

5:34:15

We are in the HTML file and the

5:34:17

JavaScript file. It is in the same

5:34:19

folder. So I don't need to navigate into

5:34:21

any folder or type in a complicated path

5:34:23

here. Just write the name of the file.

5:34:25

If we now run this code again, you can

5:34:27

see that yes, it still works. So now we

5:34:30

have a proper setup for our app and we

5:34:32

are ready to get started building our

5:34:34

people counter. Let's move on.

5:34:40

So today is actually a really important

5:34:43

day in your life because you're going to

5:34:45

write your first lines of JavaScript.

5:34:47

And that is just such a powerful thing

5:34:50

to do because you take the first step

5:34:52

into a world of opportunities and it

5:34:54

might even change your life. So in a

5:34:56

year you might want to celebrate this

5:34:58

day as the anniversary the day you met

5:35:00

JavaScript and changed your life for the

5:35:02

better. Anyway, the line you're going to

5:35:06

write is not this long one right here.

5:35:08

It's a little bit too difficult at the

5:35:09

moment. I'm actually going to add a

5:35:11

double slash in front of it like that.

5:35:13

And you can see that grade it out. That

5:35:15

means that JavaScript will ignore this

5:35:17

since this is now a code comment, not

5:35:21

real code. So if we run the code here in

5:35:23

the browser, you can see that now we are

5:35:25

not modifying the H2 tag anymore. So we

5:35:30

are ready here down at line three to

5:35:32

write our first lines of code. Now let's

5:35:35

think a little bit. What do we need

5:35:36

actually to build this subway passenger

5:35:39

counter app? Well, the first thing we

5:35:41

need is some way to store the count. And

5:35:45

that's a natural job for JavaScript

5:35:47

because it's kind of like the data we

5:35:49

need to store. And when you need to

5:35:50

store data, you need to create so-called

5:35:53

variables to store the data in. And I'm

5:35:55

now going to create a variable called

5:35:57

count. And the way we do that is we

5:35:59

write let pounds equal zero. Now we have

5:36:05

a variable called count. and that holds

5:36:07

a tiny piece of data, namely the number

5:36:10

zero. The way you can read this in

5:36:12

English is actually let count be zero.

5:36:16

So pretty natural. And let's actually

5:36:18

try and verify that actually our count

5:36:20

variable does indeed equal zero. Well,

5:36:23

we can do that by using a tool that

5:36:25

every single developer uses every single

5:36:27

day. It's called console.log.

5:36:31

Then open and close parenthesis. And

5:36:33

inside of these parenthesis, you can put

5:36:34

almost whatever you want. And in our

5:36:36

case, we are going to put this count

5:36:39

variable here. If we now run the code,

5:36:42

you can see that down in the console at

5:36:43

the bottom, we printed out the number

5:36:46

zero. And the console is something that

5:36:48

the browser provides us with. It's there

5:36:50

mainly for debugging purposes, for

5:36:53

checking our code like we are doing

5:36:54

here, verifying that actually, yeah, I

5:36:56

want to take a look at at count. I want

5:36:58

to print it out to the control and see

5:37:00

with my own eyes that it is what I think

5:37:02

it is. And indeed, it was. And this

5:37:04

console you see here is Grimbus

5:37:06

implementation of the console. If you

5:37:08

want to check out the real world console

5:37:09

in a Chrome browser, you can for example

5:37:11

head over to google.com or any page

5:37:14

basically and then rightclick and choose

5:37:17

the inspect option. When you click that,

5:37:19

it'll open up this so-called developer

5:37:22

tools which shows you a bunch of HTML.

5:37:24

As for now, we're not going to worry

5:37:26

about that. Instead, just click on the

5:37:27

console option and that'll open up a

5:37:30

blank console where you actually in

5:37:32

addition to printing out stuff which we

5:37:34

did down here in the scribba console.

5:37:36

You can write JavaScript as well. So if

5:37:38

you want to write let count equals 5 and

5:37:40

then hit enter and then write console

5:37:42

log and then pass in count in the

5:37:44

parenthesis and then hit enter, you'll

5:37:46

see that it'll log out five as well. So

5:37:49

the console is available to you in all

5:37:51

browsers and it's a tool that developers

5:37:53

use every single day. So, I'm really

5:37:54

happy that you've learned about it this

5:37:56

early on. Now, I actually have a

5:37:58

challenge for you. I want you to do two

5:38:01

things. First, you're going to create a

5:38:03

variable called my age and then set its

5:38:06

value to your age and then log the my

5:38:09

age variable to the console. So, go

5:38:11

ahead and do this right now and then I

5:38:13

will show you how to do it as well when

5:38:15

you come back.

5:38:21

Okay, hopefully that went well. Let's do

5:38:23

it together. Do let my age. I happen to

5:38:27

be 35 at the moment. Then to console log

5:38:30

out my age, I'll do console log in close

5:38:34

parenthesis my age. If we run this code,

5:38:38

you see now we are printing out both

5:38:40

account and also my age. So we have

5:38:43

verified that our variables indeed work

5:38:46

as expected. Before we move on, there's

5:38:48

one thing I want to show you. and that

5:38:50

is to take this line console logging of

5:38:52

my age and place it above the my age

5:38:56

variable declaration. So now we try to

5:38:58

console log my age before we define it

5:39:00

since JavaScript starts reading at the

5:39:02

top and works its way downwards. So what

5:39:05

do you think then will happen if I now

5:39:07

remove these other control logs and only

5:39:10

keep the my age console log? Let's take

5:39:12

a guess. Well, what happens is that we

5:39:16

get a reference error. cannot access my

5:39:19

age before initialization. So,

5:39:21

JavaScript actually understands what

5:39:23

we're trying to do that we're actually

5:39:25

referencing a value before it has been

5:39:27

initialized and that simply doesn't

5:39:29

work. So, now that you are aware of

5:39:32

that, let's move on.

5:39:36

Okay, so let's return back to our count

5:39:38

variable and learn some more advanced

5:39:39

concepts, which is that you can actually

5:39:41

use JavaScript kind of as a calculator.

5:39:44

So instead of just writing let count

5:39:46

equals 5, you can do let count= 5 + 7

5:39:50

for example. And when you run that code,

5:39:52

you'll see 12 in the console. You can do

5:39:54

minus of course that'll result in minus2

5:39:57

in the console. Or you can even divide

5:39:59

0.71 bunch of numbers after that. And of

5:40:03

course multiply gives us 35. So there's

5:40:06

a lot of mathematical operations built

5:40:07

into JavaScript. And you're not going to

5:40:09

learn about all of them now because now

5:40:11

instead of just hard- coding raw

5:40:13

numbers, let's try to use variables here

5:40:15

instead because often times you won't

5:40:17

see this kind of operation. You'll

5:40:19

normally see numbers represented as

5:40:21

variables in real world code bases. So

5:40:24

removing this right here and for example

5:40:27

do let

5:40:30

first batch equals 5. So this was the

5:40:34

batch of people that first entered the

5:40:35

subway wagon. And instead of hard coding

5:40:37

five here yet again, just going to do

5:40:40

count equals first batch. Well, what do

5:40:42

you think will be logged out here then?

5:40:45

Quite correctly, it's five because first

5:40:48

batch is five and count is set to the

5:40:50

same as five. And perhaps there was

5:40:53

another batch as well. Let second batch,

5:40:56

a group of people that entered just

5:40:57

before the doors closed. Maybe that was

5:40:59

seven people. Well, then we can do

5:41:03

count equals first batch plus second

5:41:05

batch. Yes, this works as well. So, this

5:41:08

is a much more common thing to see in

5:41:10

JavaScript that a variable is set to the

5:41:12

value of, for example, two other

5:41:14

variables added together. Now, I want to

5:41:17

comment out this like that. And if you

5:41:19

wondered how I did that magic of

5:41:20

commenting out multiple lines at once, I

5:41:22

did simply command + k + c or replacing

5:41:27

this with control if you're on a windows

5:41:29

machine because what I want to do now, I

5:41:32

want to gather this code here

5:41:35

and then I want to give you a three-part

5:41:37

challenge where you are going to convert

5:41:39

your age into dog ears. So first create

5:41:43

two variables my age and human dog

5:41:46

ratio. That is the ratio between human

5:41:48

years and dog years. And for the sake of

5:41:51

simplicity, we're going to say that one

5:41:52

human year is about seven dog years.

5:41:55

Now, the calculation is actually a

5:41:56

little bit more complicated than that,

5:41:58

but that's not that important. The

5:41:59

important thing here is the learning.

5:42:01

So, set then the human dog ratio to

5:42:03

seven and then multiply the two

5:42:06

variables together and then store the

5:42:08

result in my dog age. Finally, log my

5:42:12

dog age to the control. This is great

5:42:14

practice. It's important to build up

5:42:15

your muscle memory. So, go ahead and do

5:42:17

this right now and then return back to

5:42:19

the screencast when you want to see how

5:42:20

I solve it as well.

5:42:26

Okay, hopefully that went well. Now,

5:42:29

let's do it together. Move the console

5:42:31

so we can get some more space here. And

5:42:33

we'll start with my age, which still is

5:42:37

35. And we'll do human

5:42:41

ratio. That should be seven. Finally,

5:42:45

the my dog age should be my age

5:42:49

multiplied with human aug ratio. Let's

5:42:54

verify that this works by logging out my

5:42:57

dog age.

5:42:59

The code and yes, we can see in the

5:43:01

console we get 245.

5:43:03

My god, I would be an old dog if I was a

5:43:06

dog. I'm really glad I'm a human

5:43:09

actually. So, let's move on.

5:43:15

Okay, so let's return back to our count

5:43:17

example. Now you've learned how to

5:43:19

initialize a variable and even how to do

5:43:21

mathematical operations on it, both with

5:43:23

hard-coded numbers and with other

5:43:25

variables if we need that. And that's

5:43:27

all great. However, up until now, we've

5:43:30

just been working on the initialization

5:43:32

or the so-called assignment of the

5:43:35

variable. What if you want to reassign

5:43:37

it or in plain English, you want to

5:43:39

change the variable? Well, then you can

5:43:41

do that, for example, down here on line

5:43:43

five and just do count equals 3. And if

5:43:46

we now run the code, you see that we log

5:43:48

out three as opposed to five because

5:43:50

JavaScript starts from the top and runs

5:43:52

down and uses the latest value it can

5:43:55

find for any variable defined with the

5:43:57

let keyword. Now, there are other types

5:44:00

of variables that you can't reassign

5:44:02

like this, but we'll get to that later.

5:44:04

As for now, we're just going to work

5:44:06

with the let. And you can do this as

5:44:08

many times as you want. If I want to

5:44:10

change it even further down down to one,

5:44:12

you can see now that JavaScript is only

5:44:14

taking into account the line seven

5:44:16

reassignment of the count variable. So

5:44:19

this is all good, but it doesn't really

5:44:20

help us if we want to increment our

5:44:23

people entered count with one every time

5:44:25

we for example click a button. What we

5:44:27

then want to do is something like count

5:44:30

plus one because we want to take the

5:44:32

current count, keep track of how many

5:44:34

we've counted up until now and then just

5:44:36

increment with one. The way to do that

5:44:38

is actually by simply doing like this.

5:44:42

Now this might look a little bit weird

5:44:44

since we have a count on both sides of

5:44:46

the equal mark and probably you've

5:44:48

learned at school that the left and

5:44:51

right hand side of the equal mark should

5:44:53

be completely equal in mathematics.

5:44:55

However, that's not how it works in

5:44:57

JavaScript. Here we are assigning this

5:44:59

variable to take on this value. So first

5:45:02

you want to calculate the value and the

5:45:04

value is this point 5 + 1. Well then

5:45:09

count now will be equal to six. Let's

5:45:13

run this code and see that it works.

5:45:14

Yes. And let's say we wanted to

5:45:17

increment it by two. Then we do two and

5:45:20

now it's seven because 5 + 2 is 7. Do

5:45:24

the same thing again. This time we can

5:45:26

increment it with 10. Now we're up at 17

5:45:29

and minus that with two again and then

5:45:32

we're down at 15. I think you get the

5:45:34

point. Now I have a challenge for you.

5:45:37

Okay. So you are to create a variable

5:45:40

bonus points. So this could for example

5:45:41

be a game where your bonus points goes

5:45:43

up and down. And I want you to

5:45:45

initialize it as 50 and then increase it

5:45:48

to 100, decrease it down to 25 and then

5:45:50

finally increase it up to 70 again. And

5:45:53

you are to use the same technique that

5:45:54

we used here with the count where you

5:45:57

reassign the variable to the old value

5:45:59

of the variable and then adding or

5:46:01

subtracting a value. And I want you to

5:46:04

console log the value after each step.

5:46:07

So go ahead and do this right now and

5:46:08

then I will show you the solution as

5:46:10

well.

5:46:15

Okay, hopefully this went well. Let's do

5:46:18

this together. We'll start with let

5:46:20

bonus points be 50. Console logging it

5:46:24

out. And then we're going to do bonus

5:46:26

points equals bonus points plus 50

5:46:31

because we want to get to 100. Again,

5:46:32

console logging it. Next up, bonus

5:46:35

points equals bonus points

5:46:38

minus 75 because we want to get down to

5:46:40

25. Logging it out again. Finally, bonus

5:46:44

points equals bonus points. Now we need

5:46:48

to increase it with 45

5:46:51

70. Let's comment out this code up here

5:46:54

and run the code. Bring up the console

5:46:56

and yes 50 100 25 70. Great job. Let's

5:47:00

move on.

5:47:05

Okay, now you know enough JavaScript for

5:47:07

us to move on to the HTML and build the

5:47:10

interface for our app. And it's not a

5:47:14

lot of interface. It's h to begin with

5:47:17

just a button and later down the line

5:47:19

we're going to create another button but

5:47:21

it has to be written and you are going

5:47:23

to do that. So I want you to follow

5:47:25

these instructions. You are to create an

5:47:27

increment button that is the text of the

5:47:29

button with the ID of increment-b.

5:47:34

So go ahead and do this right now.

5:47:41

Okay. Hopefully that went well. Now

5:47:44

let's do it together button. Then I'll

5:47:46

create the closing tag inside of here.

5:47:48

I'll write increment. Could have written

5:47:51

count here. But I think increment is

5:47:52

more of a technically descriptive word.

5:47:54

So let's use that. And ID

5:47:57

increment dashbtn like that. If we run

5:48:02

this code, you'll see yes, we indeed

5:48:04

have this button and it is already

5:48:06

styled. How convenient. Let's check out

5:48:09

the CSS for that. We have a general

5:48:11

styling for buttons which are reused

5:48:13

across both of our buttons since they're

5:48:15

using the button selector. And then our

5:48:17

increment button and our save button has

5:48:19

a specific background each of them.

5:48:22

They're dark red and dark green. Great

5:48:24

job doing this. Now the question is how

5:48:27

do we make this button interactive?

5:48:28

Because right now nothing happens if I

5:48:30

click it. Well, in the next lecture

5:48:33

we'll go through exactly how to do that.

5:48:38

Okay. Okay, so now we're going to put

5:48:40

the different pieces in this puzzle

5:48:42

together and also add a whole new piece.

5:48:45

And in order to free up some space in

5:48:46

our JavaScript file here, let's just

5:48:48

remove this previous exercise and

5:48:50

actually write out in pseudo code the

5:48:52

procedures that we need to do in order

5:48:54

to make this work. So first we know that

5:48:57

we need to store the count somewhere

5:49:00

and we know that we want to initialize

5:49:01

it as zero. And then as I said in the

5:49:04

previous lesson, we need to kind of

5:49:06

listen for clicks on this button here.

5:49:09

When it's clicked, we need to increment

5:49:11

our count.

5:49:13

Then finally, which we aren't going to

5:49:14

do just yet, but I just want to write

5:49:16

that procedure out as well so you know

5:49:18

what to expect,

5:49:21

we need to change the countell,

5:49:23

this paragraph right here in the HTML to

5:49:27

reflect the new count. So we know how to

5:49:31

initialize the count as zero and we know

5:49:33

how to increment a count variable. So to

5:49:36

achieve these first three we need to do

5:49:38

this task that is listening for clicks

5:49:40

on the increment button and that can be

5:49:42

done in a multitude of ways. The easiest

5:49:44

one is simply in the HTML defining an on

5:49:49

click event listener. You simply write

5:49:52

on click equals and then something in

5:49:55

between quotes. So this is an attribute

5:49:57

in the HTML just like the ID is an

5:50:00

attribute as well. And inside of here

5:50:03

you write the function that you want to

5:50:05

be triggered when the button is clicked.

5:50:08

So I'm going to write increment and open

5:50:10

and close parenthesis here. Now that

5:50:13

probably looks really weird for you.

5:50:15

That's totally okay if you're confused

5:50:17

by what's going on here because we've

5:50:19

seen nothing of the word increment in

5:50:20

our JavaScript yet. So rightfully so. We

5:50:22

need to create that function. I'll do

5:50:25

that down here. And I'll use the keyword

5:50:26

function, then the name, increment, open

5:50:30

and close parenthesis, and then open and

5:50:32

close brackets. So, pretty funky syntax

5:50:36

right there. And the first time you type

5:50:37

them, it feels weird, but over time it

5:50:39

becomes second nature. What you write

5:50:41

inside of these curly brackets is the

5:50:44

so-called body of the function. And that

5:50:46

piece of code that is in the body will

5:50:49

be executed every time this function is

5:50:52

called or invoked. That's the same

5:50:54

thing. So just to see it in action going

5:50:57

to write console log button was clicked

5:51:01

like that. If we run the code and I

5:51:04

click the button you can see that in the

5:51:07

console we see the button was clicked.

5:51:08

If I do it again I again and again and

5:51:10

again and again. So every single time

5:51:12

the button is clicked this piece of code

5:51:14

runs. And it runs because we in the

5:51:16

HTMLs are saying, "Hey, JavaScript, when

5:51:19

this button is clicked on the on click

5:51:22

event, then I want you to run a function

5:51:25

called increment."

5:51:27

And that's what's happening here. And

5:51:30

then JavaScript is like, "Yeah, for

5:51:31

sure." So it sits ready and listens for

5:51:34

that specific click event. And

5:51:36

JavaScript can do that. It pays

5:51:37

attention to what the user does on the

5:51:39

screen. And when it sees someone

5:51:41

clicking on this button, it fires off

5:51:43

this piece of code.

5:51:45

This was probably a lot of information

5:51:47

to parse in one go. So before we move on

5:51:50

and continue on turning our pseudo code

5:51:53

into real JavaScript, let's take a

5:51:55

closer look at functions over the next

5:51:57

few casts so that you get to write some

5:51:59

functions as well and build up your

5:52:01

understanding and muscle memory.

5:52:06

Okay. So let's pretend that we are

5:52:07

building a race car game. So here I have

5:52:10

some comments which are meant as pseudo

5:52:12

code for the functionalities of the game

5:52:14

and the only real functional part of it

5:52:16

is these five console logs which are

5:52:18

counting down from 5 to 1. So we start

5:52:21

the game by setting up the race and then

5:52:23

we do 5 4 3 2 1. If I run the code, you

5:52:26

can see that is logged to the console.

5:52:28

That means that it's go. Players are to

5:52:31

start racing and they would be running

5:52:33

the race and then the race is finished

5:52:35

and a winner is declared. And then of

5:52:37

course we are getting ready for a new

5:52:39

race. However, with the current

5:52:42

knowledge we have about JavaScript, the

5:52:44

way we would count down for a new race

5:52:46

would have to be to copy all of these

5:52:49

lines and paste them in down here. So

5:52:51

that now when we run it, we get 5 4 3 2

5:52:54

1 printed two times to the console.

5:52:57

However, this isn't good. Anytime you

5:52:59

see these kinds of repetitions in your

5:53:02

code, you should try to think is there

5:53:04

any way we can extract this into a

5:53:06

function and that is exactly what we are

5:53:09

going to do. We are going to refactor

5:53:11

this so that it instead uses a function.

5:53:13

Another word for function could be

5:53:15

command. So we are asking JavaScript to

5:53:18

kind of remember a command so that we

5:53:20

can use it later on as well. And that

5:53:22

command can be as comprehensive as you

5:53:24

want. In our case, it's going to be to

5:53:26

countdown from 5 to 1. So let's just do

5:53:29

this to see it in action. To create a

5:53:31

function, as I talked about in the

5:53:32

previous cast, we use the function

5:53:34

keyword and then the name of the

5:53:37

function. I'm going to call this

5:53:38

function countdown, then open and close

5:53:42

parenthesis, and then open and close

5:53:44

curly brackets. And all of the action

5:53:48

happens inside of the curly brackets. So

5:53:49

I'm going to break that into a new line.

5:53:51

And I'm going to copy all of these

5:53:53

control logs and then paste them inside

5:53:56

here like that. And here I'm tabbing it

5:53:59

out just to highlight that this code is

5:54:03

inside of that function. This is not

5:54:05

something JavaScript cares about. It's

5:54:07

to make our code easy to read for

5:54:08

humans. So now I have declared our

5:54:11

function. However, if we remove this

5:54:14

down here and now try to run the code,

5:54:17

nothing happens because it has only been

5:54:19

declared. it hasn't been what we called

5:54:22

invoked or also called as this code

5:54:26

inside of here will only run if we call

5:54:29

the function. So if JavaScript was a dog

5:54:32

and we've taught our dog to roll around,

5:54:35

then in order to get our dog to actually

5:54:37

roll around, we have to say roll around.

5:54:40

Same thing here. We have taught

5:54:42

JavaScript to countdown, but in order

5:54:44

for it to actually do the counting, we

5:54:46

have to say countdown. And we do that

5:54:49

like this. Simply writing countdown with

5:54:52

open and close parenthesis. So now you

5:54:55

can see when I run the code, it indeed

5:54:57

does the counting. But if I comment this

5:55:00

out, it does nothing. So what I'm going

5:55:03

to do now is I'm going to take this

5:55:04

countdown and I'm going to put it all

5:55:06

the way here at the top. And then I'm

5:55:08

going to call it when we are ready to

5:55:10

start the first race and then also call

5:55:12

it when we are ready to start the second

5:55:15

race. Now if I run the code, you can see

5:55:18

that we indeed countdown two times

5:55:20

before the first race and before the

5:55:22

second race. And this is much better

5:55:24

than typing out all five console logs

5:55:28

both here on line 11 and on line 19. So

5:55:31

we have compressed our code a lot. So

5:55:33

with this knowledge fresh in mind, let's

5:55:36

move on to the next cast where you are

5:55:38

to write your first function.

5:55:43

Okay, now it's your turn. You are going

5:55:45

to create a function that logs out the

5:55:47

number 42 to the console. And you can

5:55:50

decide the name of the function. And

5:55:52

when you've done that, make sure you

5:55:54

call or invoke the function as well. So

5:55:57

go ahead and do this right now.

5:56:04

Okay, let's do this. I'm going to call

5:56:06

it my

5:56:08

logger. Open and close brackets. And

5:56:12

then inside of the body do console.log

5:56:15

42. Now we need to call it my logger.

5:56:19

Like that. We run the code. And yes, you

5:56:22

can see we are logging 42 to the

5:56:24

console. Great job.

5:56:28

Okay, time for a new challenge. So in

5:56:31

our race car game, we have certain laps

5:56:33

and of course we track how much time our

5:56:36

players use to race through the laps.

5:56:38

And here we have three lap times in the

5:56:40

variable lap 1, lap 2, and lap three.

5:56:43

And the thing is, if you create a

5:56:44

function down here on line six, it will

5:56:46

be able to access these three variables

5:56:49

from within the function. So what I want

5:56:51

you to do now is create a function that

5:56:53

simply logs out the sum of all the three

5:56:56

laps. So that'll be the total racing

5:56:58

time for a player. So you decide what

5:57:01

name you want to give it. Just write

5:57:03

that function that logs out the total

5:57:05

lap time and then run the function as

5:57:07

well.

5:57:12

Okay, hopefully that went well. Let's do

5:57:14

this loop function. I'm going to call

5:57:17

this function log lap time. Open and

5:57:21

close parenthesis. And here I can either

5:57:24

first create a variable. Let total time

5:57:28

for example do lap 1 + lap 2 + lap 3 and

5:57:34

then console log out total lap time like

5:57:38

that and then log lap time invoke the

5:57:42

function down here on line 11. If we now

5:57:44

run the code we can see yes we are

5:57:46

logging out 103. This is one way of

5:57:48

doing it. Alternatively, I could have

5:57:50

skipped creating this variable in here

5:57:56

and simply added the variables inside of

5:57:58

the console log. It will give me, as you

5:58:00

can see, the exact same result. Now the

5:58:03

reason I wanted to create this variable

5:58:05

here though is to just show you one

5:58:07

thing which is that while this function

5:58:11

could access these variables from the

5:58:15

so-called global scope the outer scope

5:58:18

which is not on the inside of the

5:58:19

function but on the outside of it. This

5:58:22

doesn't work the other way around. So if

5:58:24

I now just try to console log total time

5:58:29

from the outer scope if we run this you

5:58:33

can say total time is not defined. That

5:58:35

is because when you define a let

5:58:37

variable inside of this scope it only

5:58:40

exists inside of this block of code.

5:58:43

This is the scope in which the function

5:58:45

lives. And that's why we call let

5:58:48

variables block scoped. So that might be

5:58:51

a little bit confusing in that the lap

5:58:53

could go from the outside of the

5:58:55

function and to the inside of the

5:58:56

function, but total time couldn't go

5:58:59

from the inside of the function to the

5:59:02

outside of the function. But don't worry

5:59:04

too much about this. JavaScript will

5:59:06

tell you when something isn't defined,

5:59:08

and you can be sure that you will

5:59:09

misstep at times, but that's just a part

5:59:12

of the process. Let's now move on to the

5:59:14

next challenge.

5:59:18

Okay, so now we have to combine some of

5:59:20

the things you've learned up until now

5:59:22

in order to build this lap counter

5:59:24

feature because in our racing game, we

5:59:27

want to keep track of how many laps a

5:59:29

player has completed. So I've created

5:59:31

this variable called laps completed and

5:59:34

initialized it to zero. So what I want

5:59:37

you to do now is create a function that

5:59:39

increments the laps completed variable

5:59:42

with one every time you run the

5:59:44

function. Then I want you to run or call

5:59:47

or invoke or whatever you want to call

5:59:49

it this function three times so that on

5:59:53

line 9 here the value that's logged out

5:59:55

will be three. Now if you're wondering

5:59:58

how to increment a variable in

6:00:00

JavaScript just look back a few casts

6:00:02

because we did that previously. So now

6:00:05

you have to combine that knowledge with

6:00:07

your freshly acquired knowledge about

6:00:08

writing functions. So go ahead and give

6:00:10

this your best try right now.

6:00:17

Okay, hopefully that went well. If not,

6:00:20

no worries. Let's do this together so

6:00:22

that you get to see how we do it. Do

6:00:24

function. And I'm going to call this

6:00:26

function increment lap like that. Open

6:00:29

and close parenthesis and then open and

6:00:32

close curly brackets. And here we have

6:00:34

to increment this variable just as we

6:00:36

did a few casts ago by doing laps

6:00:39

completed equals the old value of laps

6:00:42

completed plus one like that. If I now

6:00:45

run increment lap one time you'll see

6:00:49

that we're logging out one. Good stuff.

6:00:52

Let's

6:00:54

invoke it three times. And there we can

6:00:57

see we are logging out three to the

6:00:59

console. So great job doing this. If you

6:01:02

didn't manage it, just go back and try

6:01:04

again now that you've seen my solution

6:01:06

because it's really important that you

6:01:08

actually write the code here so that you

6:01:10

build up that important muscle memory.

6:01:15

Okay, we're back at the subway counter

6:01:17

app. And as you can see, I've deleted

6:01:19

the increment function because I want

6:01:21

you to write it instead. It's much

6:01:23

better than me writing everything. And

6:01:25

you want to do it as a part of turning

6:01:27

these first three lines of pseudo code

6:01:29

into real code. So you're going to

6:01:32

initialize the count as zero. You're

6:01:33

going to listen for clicks on the

6:01:35

increment button and thus you have to

6:01:37

create that function that's triggered

6:01:39

when the increment button is clicked and

6:01:40

then you are going to increment the

6:01:42

count. I'm going to add a final little

6:01:44

challenge here and that is to log it out

6:01:46

after the count variable has been

6:01:48

incremented. So go ahead and do this

6:01:50

right now and then afterwards I'll of

6:01:52

course show you the solution as well.

6:01:58

Okay, hopefully that went well. Let's do

6:02:00

this together. We'll do function

6:02:03

increment

6:02:05

open and close parenthesis and close

6:02:07

curly brackets. We have the button.

6:02:10

Let's verify that it works. Good thing

6:02:13

to do after every single step so that

6:02:15

you know if you at some point get a bug,

6:02:17

you will have a better understanding of

6:02:18

where it happened since you know which

6:02:20

steps you were able to get to without

6:02:22

triggering any bugs. So, I'll do

6:02:24

clicked. Run the code. Click the button.

6:02:27

Yes, that works. Okay. Now we need to

6:02:30

increment the count. So we're going to

6:02:32

do that inside here. And of course then

6:02:34

we need the count initialized to begin

6:02:36

with. So count equals zero here. As you

6:02:40

remember it's just as we're simply going

6:02:42

to do what we did up line for. We'll do

6:02:45

count equals count + 1. Now finally

6:02:49

console log count. I'm going to remove

6:02:53

this and run the code. Hit increment.

6:02:56

Yes, we see one and two and three and

6:02:59

four. Nice. So then we have done these

6:03:03

three parts and remove this helper code

6:03:07

right here. We have the final part left

6:03:10

and we can finally start understanding

6:03:13

what this weird piece of code here up on

6:03:15

line one that we worked with in the very

6:03:17

beginning of the course actually means.

6:03:20

Let's do that in the next lecture.

6:03:25

Okay, so we are ready to add the final

6:03:27

piece of the puzzle which is to change

6:03:29

the count L that is the H2 right here

6:03:34

which currently has zero

6:03:36

so that reflects the new count and the

6:03:38

new count is down here which we are

6:03:40

logging out. So we have to do something

6:03:43

down here at line 9 and what we're going

6:03:45

to do is take this line right here which

6:03:47

has just been lying here in the

6:03:48

background all along. Now in order to

6:03:51

properly understand this expression, I

6:03:53

think we should break it into two. Take

6:03:55

the first part where we're actually

6:03:57

asking for the HTML element and the

6:04:00

second part where we're actually

6:04:01

modifying the HTML element. So starting

6:04:04

with the first part, I'm going to store

6:04:06

this in a variable called count L like

6:04:09

that. then document

6:04:12

get element by id and close parenthesis

6:04:17

and passing in count l

6:04:21

this exact string right here. Notice

6:04:24

that we're using different naming

6:04:26

convention here in the JavaScript. This

6:04:28

is called camel case like that where you

6:04:33

capitalize the first letter of the

6:04:35

second word but not the first letter of

6:04:37

the first word. This is how you want to

6:04:39

write JavaScript variables. It's a very

6:04:41

normal convention. And also, if we were

6:04:43

to try to use the same convention as

6:04:45

we've been using in our HTML and CSS,

6:04:47

JavaScript would actually tell us, uh,

6:04:49

uh, uh, you can't do that. As you can

6:04:51

see, we're getting a red line under this

6:04:53

character, which is the JavaScript's way

6:04:54

of complaining to us because it's not a

6:04:56

valid variable name when you use dash.

6:04:59

So, we got to remove it like that. Now,

6:05:02

as always, what do you think we should

6:05:04

do now? Now that we've taken one step

6:05:06

into the unknown, well, of course, we're

6:05:08

going to use our good old friend console

6:05:10

log because we have to verify at every

6:05:11

single step that we're actually on

6:05:13

track. We haven't introduced any bugs.

6:05:15

So, I'll do console.log and logging out

6:05:18

count L. And if we bring up the console,

6:05:21

we can see actually we're getting what

6:05:23

looks like an HTML element in the

6:05:25

console. Hm, that's pretty interesting.

6:05:27

Now, it's actually not a real HTML

6:05:30

element. It's more of a representation.

6:05:32

It's a model of an HTML element and it

6:05:34

gives us a lot of other opportunities to

6:05:36

change it using JavaScript as well. But

6:05:38

for now it's it's perfectly fine to

6:05:40

think of this as just yeah that is the

6:05:42

element that we are seeing right here.

6:05:46

It's a JavaScript representation of that

6:05:48

element because remember we said hey

6:05:50

HTML document why don't you get me the

6:05:53

element that has the ID of countell and

6:05:58

the HTML was like yeah sure just take it

6:06:00

and then you store that in the countell

6:06:03

variable and now you as a JavaScript

6:06:05

developer have control over this element

6:06:07

and you can manipulate it which is

6:06:09

exactly what we're going to do down here

6:06:10

at line 14 because now we're going to

6:06:13

move on to the second part of this big

6:06:14

expression We're just modifying the

6:06:16

element itself.ext

6:06:18

equals 5. Or in our case, how would we

6:06:21

write this? Well, we've turned this big

6:06:24

thing here into this variable. So, we'll

6:06:28

use this variable and do dot inner text.

6:06:32

That is inner text like that. Equals.

6:06:35

And we're not going to set it to five

6:06:37

because that would make any sense. What

6:06:39

are we going to set it to? Think a

6:06:40

second about that.

6:06:42

Indeed, it is the count because we know

6:06:45

from console logging earlier on that the

6:06:47

count does indeed increment correctly.

6:06:49

And now we're just saying that we want

6:06:50

the inner text. That is the text on the

6:06:54

inside of the tags. We want it to be the

6:06:57

count. We'll run the code. Hit the

6:07:00

increment button. And yes, it works. Now

6:07:03

we are incrementing. We are counting

6:07:04

people. Really good job reaching this

6:07:07

point. and your JavaScript skills are

6:07:08

starting to become dangerous as you now

6:07:10

know how to create interactive apps. Now

6:07:13

before we move on, there's one thing I

6:07:15

want to mention which is that this get

6:07:18

element by ID here and this.log

6:07:22

both are functions in the same way our

6:07:25

increment function is a function. Now

6:07:27

they are hooked onto the document object

6:07:30

and the console object, but that's just

6:07:32

a nuance. There's still functions or

6:07:35

methods as we call functions that are

6:07:37

hooked onto so-called objects. If that

6:07:40

sounds confusing, it's because it should

6:07:42

be at this point because you haven't

6:07:43

learned about objects yet and methods on

6:07:46

objects. But don't worry about that.

6:07:48

Just think of them as functions. And

6:07:50

actually, the thing we've been doing

6:07:52

here of adding something in between the

6:07:54

parentheses of the function when we are

6:07:57

calling it is called to pass in

6:08:00

arguments. which means that we are

6:08:01

giving the function some data to work

6:08:03

with. Like here, we're specifying the ID

6:08:06

of the element we want to grab.

6:08:08

Otherwise, if we didn't do that, this

6:08:10

function would just be running in the

6:08:11

wild and not know what to look for.

6:08:14

Likewise, in this log here, we're

6:08:16

passing in which variable we want to log

6:08:19

to the console. If we didn't do this,

6:08:21

the log function wouldn't know what to

6:08:22

log. So speaking in analogies, if the

6:08:25

function is a chef that are to cook a

6:08:28

meal for you, then the arguments you

6:08:30

pass in are the ingredients the chef

6:08:32

uses to cook that meal. So hopefully

6:08:35

that made everything a bit more clear.

6:08:37

Let's clean up this code and move on.

6:08:43

Now before we move on, I want to talk a

6:08:45

little bit about what we're doing here

6:08:47

where we're saying document.getelement

6:08:48

get element by ID because you'll often

6:08:51

hear developers refer to this technique

6:08:54

as working with the DOM. And that's one

6:08:57

of those threeletter acronyms in web

6:09:00

development that sounds super

6:09:01

complicated and I was really confused

6:09:03

about this when I was learning to code

6:09:05

and I want you to avoid that confusion.

6:09:08

So, let's just unpack this expression.

6:09:10

It's short for document object model.

6:09:12

That sounds really fancy. However, it's

6:09:15

actually just how you use JavaScript to

6:09:18

modify a website. It's just that people

6:09:20

naming this wanted to give it a really

6:09:22

abstract name. But if we look at each of

6:09:25

the words separately, the name actually

6:09:27

does make sense. So, let's do that.

6:09:28

Starting with a document. Why that?

6:09:30

Well, that's because what you are

6:09:32

interacting with is an HTML document.

6:09:35

Object. Well, that's because the

6:09:37

document keyword in JavaScript is of the

6:09:40

data type object. meaning they've taken

6:09:42

the HTML document and shoved it into a

6:09:45

JavaScript object. Of course, that's a

6:09:47

little bit of a simplification, but

6:09:48

that's the essence. So, this word

6:09:50

document is of the data type object.

6:09:53

Now, you haven't learned about objects

6:09:55

yet, though you're going to do that a

6:09:57

little bit later. Finally, there's

6:09:59

model. Model is basically a

6:10:01

representation or a modelation, kind of

6:10:04

like, you know, there's the real Saturn

6:10:06

5 rocket that NASA built and then

6:10:08

there's the Lego model. And that's how

6:10:11

it is here as well. There's the real

6:10:13

HTML element which you've written in

6:10:15

your HTML file. Then there's the

6:10:17

JavaScript model, the representation you

6:10:19

have of this element in JavaScript.

6:10:22

So don't be frightened when people talk

6:10:25

about the DOM just in your head

6:10:26

translated to how to use JavaScript to

6:10:29

modify websites.

6:10:31

And with that out of the way, let's move

6:10:33

on with the coding.

6:10:38

Or actually before we move on, I have to

6:10:40

admit that I fooled you a little bit

6:10:42

because the problem with the previous

6:10:44

lecture was that I wrote the code and

6:10:46

that's just wrong. You are going to

6:10:48

write the code. That's how you learn. So

6:10:50

I have removed the two lines of code

6:10:52

that I wrote. Namely grabbing the

6:10:54

countell element and storing it in a

6:10:56

count variable and also setting the

6:10:59

count else inner text to the count. So

6:11:02

just do that and if you struggle just go

6:11:04

back and look at my solution. So, no

6:11:06

need for me to type this out for you yet

6:11:08

again. Just go ahead and give it your

6:11:10

best shot and refer to that if you need

6:11:12

help. And I will see you in the next

6:11:15

lecture.

6:11:18

Okay, it's time for you to build some

6:11:20

muscle memory cuz you are going to

6:11:22

create a save button and a save

6:11:24

function. You're going to start with a

6:11:26

function. Here is the instructions.

6:11:27

Create a function called save which logs

6:11:30

out the count when it's called. We're

6:11:33

going to modify this to do some other

6:11:34

stuff afterwards, but as for now, I

6:11:36

wanted to just log out the count.

6:11:38

Secondly, in the HTML, you are going to

6:11:40

create the save button. You are to set

6:11:43

the ID as save btn and have it call the

6:11:46

save function when it is clicked. So, go

6:11:49

ahead and do this right now and then

6:11:51

return back to the screencast when you

6:11:53

want to see my solution.

6:11:59

Okay, hopefully that went well. Let's do

6:12:01

this. We'll do function save open and

6:12:05

close parenthesis. Then the body of the

6:12:07

function will console log the count. If

6:12:11

we want to check that this actually

6:12:13

works now, we can call the save

6:12:14

function, run the code, and we can see

6:12:16

yes, that the count is indeed logged out

6:12:18

as a consequence of us calling the

6:12:20

function here on line 15. Okay, let's

6:12:23

remove that. Going over to the HTML,

6:12:26

we're going to create the save button

6:12:27

and we do open button tag.

6:12:31

Then we'll just close it right away.

6:12:33

I'll write save in between the tags and

6:12:36

give it the ID of save.btn.

6:12:39

Now we can actually run it to see the

6:12:40

dependency. Yes, it indeed does. But

6:12:43

nothing happens when we click it. And

6:12:45

that's because we have to do on click.

6:12:48

We want to run the save function. Here

6:12:51

we have to invoke it with the open and

6:12:53

close parenthesis otherwise it won't

6:12:55

call the function. So rerunning the

6:12:58

code, hitting save. Yes, there we are

6:13:00

logging out zero because of this line.

6:13:03

Now we can increment a couple of times

6:13:06

and see. Oo, now we're logging out six.

6:13:09

Pretty nice. Now we're starting to get

6:13:12

somewhere. It's only a matter of saving

6:13:14

the count to the website as well and

6:13:16

rendering it out under the buttons. But

6:13:18

before that, there's some new concepts

6:13:20

you need to learn. So I'll see you in

6:13:22

the next cast.

6:13:26

Okay, so now it's time for us to build

6:13:28

this little functionality here which

6:13:30

allows us to save the number of people

6:13:32

who have entered into the subway at each

6:13:35

of the departures. However, this

6:13:37

requires you to work with this full

6:13:39

paragraph which actually includes both

6:13:42

numbers which you can see but also like

6:13:44

regular text, previous entries and some

6:13:46

symbols as well. And once you move away

6:13:48

from just straight out numbers in

6:13:50

JavaScript, you're moving into the land

6:13:53

of so-called strings. And strings is a

6:13:56

data type in JavaScript. And in case you

6:13:58

wondered, yes, numbers is also a data

6:14:00

type. And if you think the word string

6:14:02

is a little bit weird, well, you can

6:14:04

also think of this as just text. The

6:14:06

strings you work with in JavaScript are

6:14:08

normally meant to be text that the user

6:14:09

reads on the page. Now, we have been

6:14:12

working with text here before. We've

6:14:14

hardcoded in some text here and there in

6:14:16

the HTML. And actually, as far as HTML

6:14:18

knows, everything is strings. Doesn't

6:14:20

even know about numbers. HTML can't do

6:14:23

calculations for you. So, when I'm

6:14:25

talking about strings and numbers, I'm

6:14:27

talking about it in the context of

6:14:28

JavaScript. And even though you're

6:14:30

probably not even aware of it, you've

6:14:32

actually written a string already up

6:14:34

here on line one. You've wrapped the

6:14:36

count d-l inside of two quotes. And that

6:14:40

is how you create a string in

6:14:42

JavaScript. But you've had far from

6:14:44

enough practice to start working with

6:14:46

strings in our people counter app. So in

6:14:48

the next lesson, we're going to go over

6:14:50

the basics of it and then you're going

6:14:52

to solve some challenges so that we

6:14:53

build up that muscle memory and make you

6:14:55

capable of using strings in our app.

6:14:58

I'll see you there.

6:15:02

So strings are used all over the place

6:15:04

in software. Let's say that you for

6:15:07

example are building an app where people

6:15:09

can authenticate. Well, then most likely

6:15:11

you'd have to store some kind of

6:15:13

username for your users. That would most

6:15:16

likely be stored as a string. For

6:15:18

example, pair wrapped in double quotes.

6:15:21

Then this string just like we did with

6:15:24

numbers will be stored in a variable. So

6:15:27

let username equals pair. Now we can

6:15:32

console log out username

6:15:36

and we get pair logged to the console.

6:15:39

Now, one thing I want to mention is that

6:15:41

I'm using double quotes here to create

6:15:44

this string. I could use single quotes

6:15:47

instead if I want to. You can see that

6:15:49

works. However, I cannot start with a

6:15:52

single quote and end with a double

6:15:53

quote. As you can see, now our editor

6:15:57

tells us that this syntax is off. And if

6:15:59

we try to run the code, we are getting a

6:16:01

syntax error. So, you got to stick with

6:16:04

one or the other. And I usually use

6:16:06

double quotes, but that's just a matter

6:16:07

of preference. If you prefer single

6:16:09

quotes, go ahead. Now, I want to give

6:16:12

you a challenge.

6:16:14

Here you are to create a variable

6:16:16

message that stores the string. You have

6:16:18

three new notifications.

6:16:21

Go ahead and do that right now.

6:16:28

Okay. Hopefully that went well. Let's do

6:16:31

this. Message equals

6:16:36

this string right here. Now, what we

6:16:38

want to do here is combine this string

6:16:42

with this string because this string

6:16:44

right here is probably the result of us

6:16:47

checking in the database and seeing that

6:16:49

oh, there's three new notifications that

6:16:51

pair hasn't seen. So, render out this

6:16:54

string right here. And then, of course,

6:16:56

we need to combine it with the name. So

6:16:59

what we want to do is message plus

6:17:02

username like that. When we add a plus

6:17:05

here we so-called concatenate the two

6:17:08

strings together. So let's have a look

6:17:09

at what happens when we run the code

6:17:12

becomes this slightly ugly string. We

6:17:14

have three new notifications pair with

6:17:16

no space in between the strings. So it

6:17:18

kind of becomes like this

6:17:22

isn't really what we wanted. What we

6:17:24

then also can do is add a third string

6:17:27

in between here which includes a comma

6:17:30

and a space. Now if we run it, you have

6:17:32

three new notifications pair. And maybe

6:17:34

we even want to add a exclamation mark

6:17:37

at the end like that. As you can see,

6:17:40

when we use the plus for strings, it

6:17:43

simply concatenates the characters

6:17:45

together. Okay. Now I have a new

6:17:48

challenge for you.

6:17:50

You are to create a variable message to

6:17:53

user that contains the message we have

6:17:56

logged. By that I mean the entire

6:17:58

message in here. This should be a new

6:18:01

variable and then afterwards I would log

6:18:04

it out just to make sure that you have

6:18:06

configured the message to user in the

6:18:08

correct way. Go ahead and do this right

6:18:10

now.

6:18:16

Okay. To do this you do let message to

6:18:19

user equals message plus comma space

6:18:25

plus username plus exclamation mark. Now

6:18:30

we can replace all of this with message

6:18:34

to user and running the code again we

6:18:37

get the exact same string which is just

6:18:40

what we wanted. Great job.

6:18:45

Okay, time for another challenge. You

6:18:47

are to create two variables, name and

6:18:49

greeting. And the name variable should

6:18:51

store your name. And the greeting should

6:18:54

store, for example, hi, my name is. Then

6:18:56

you are to create a third variable, my

6:18:58

greeting, that concatenates the two

6:19:01

strings. And finally, log the my

6:19:03

greeting variable to the console. So

6:19:05

this is just to give you some muscle

6:19:07

memory. Go ahead and do this right now.

6:19:14

Okay, let's do this. Maloo let name

6:19:17

equals pair Harold organ. Then let

6:19:22

greeting I my name is and then a space

6:19:26

at the end. And then finally let my

6:19:30

greeting equals greeting plus name. Then

6:19:34

to see how this went we do console log

6:19:37

my greeting.

6:19:40

Running the code. Yes, we get, "Hi, my

6:19:42

name is Pier Harold Borggan." Now,

6:19:46

notice that here I added the space

6:19:48

inside of one of the strings as opposed

6:19:51

to doing something like that. However,

6:19:55

doing that would work the exact same

6:19:57

way. So, great job solving this

6:20:00

challenge. Let's move on.

6:20:05

Okay, now let's mix it up a little bit.

6:20:07

Let's say that my name isn't Pier Harold

6:20:09

Borgen. It's actually 42. A strange

6:20:11

name, but anyway, what do you think will

6:20:13

happen when we have one number and one

6:20:15

string? What will the result be? Let's

6:20:17

do it. It's actually, hi, my name is 42.

6:20:20

So, the 42 here has actually been turned

6:20:22

into a string that has been added into

6:20:25

like this. And that's kind of what

6:20:27

happens in a wrestling game. Between a

6:20:29

string and a number, the string always

6:20:31

wins. Now, this was a little bit of a

6:20:33

weird example. So, let's take one that's

6:20:35

a bit more interesting. Let's try let

6:20:38

points equals four. And then let's say

6:20:42

bonus points. This is some kind of game

6:20:45

that is 10. Let total points equals

6:20:50

points plus bonus points. Total points.

6:20:54

Now, what do you think we'll log out

6:20:57

here? I'm going to comment out this one

6:20:59

right here. Take two seconds to think

6:21:01

about what the result will be.

6:21:05

Okay, let's run this. The result is 410.

6:21:09

That is weird because perhaps you

6:21:10

expected 14. No, as I said, the string

6:21:14

always wins. So when we say 4 + 10,

6:21:17

which is the values of these variables,

6:21:20

the four will be turned into a string.

6:21:22

And the result when you concatenate two

6:21:24

strings is just pretty easy to see by

6:21:26

just removing this fluff in between

6:21:28

them. 410. If the numbers won the

6:21:31

wrestling game would be like this. and

6:21:33

it would indeed log out 14, but it

6:21:36

didn't. So, I'm going to give you a

6:21:39

couple of challenges here. What do you

6:21:40

think these four control logs will log

6:21:42

out? Take a minute to think about that.

6:21:44

Potentially write your solutions in a

6:21:47

bold comment either above or perhaps

6:21:49

even after each of the lines and then

6:21:51

return back to the screencast and then

6:21:53

we'll have a look at it together.

6:21:59

Okay, here we have a number and a

6:22:01

number. So this will end up as a number

6:22:03

as well. 4 + 5 is nine as far as I can

6:22:05

remember. Here a string plus a string.

6:22:09

Even though they are number characters

6:22:10

inside of the strings, that doesn't

6:22:12

matter. JavaScript still sees this as a

6:22:14

string. And the result will be a string

6:22:15

of 24. Here wrestling match between a

6:22:19

string and a number. Sadly the number

6:22:21

always loses. So this will be 51. And

6:22:24

finally again wrestling match between a

6:22:27

number and a string. The result is

6:22:29

always that the string wins. So this

6:22:31

will be 100 100 like that. Let's run the

6:22:34

code. Yes, as you also can see from the

6:22:37

console, the way the scribble console

6:22:38

highlights the difference between

6:22:40

numbers and strings is with the color.

6:22:42

The strings are white whereas the

6:22:43

numbers are blue. So great job. Let's

6:22:46

move on.

6:22:49

Now you've had a chance to work with

6:22:51

strings. We need to talk about a common

6:22:53

problem that you might already have come

6:22:54

across. I've got a string here that

6:22:56

says, "I'd love to see the show The Lion

6:22:58

King." Let's just hit save. And we're

6:23:01

successfully logging that out. So, it

6:23:03

works. But what if I wanted to emphasize

6:23:05

the fact that The Lion King was the name

6:23:07

of the show? In that case, I might want

6:23:10

to put that in quotation marks. As soon

6:23:12

as I do that, you can see the red

6:23:14

squiggly line, and that tells us we're

6:23:16

about to get an error. Let's save. Yeah,

6:23:19

there we are. It says unexpected

6:23:22

identifier the Well, that tells us that

6:23:24

it's running into a problem right here.

6:23:27

And the reason this is happening is that

6:23:29

to JavaScript's rather basic brain, the

6:23:32

string is starting right here with this

6:23:34

quotation mark and it's finishing right

6:23:36

here with this quotation mark. So if

6:23:39

this is the string, then what on earth

6:23:42

is all of this? Well, at that point,

6:23:44

JavaScript gets confused and it throws a

6:23:46

tantrum, or rather it throws an error.

6:23:49

Now, we could potentially get around

6:23:50

that by changing these quotation marks

6:23:53

to inverted commas. But look, now we've

6:23:55

got loads of red squiggly line. Let's

6:23:57

just hit save. And now it says

6:23:59

unexpected identifier D. And the problem

6:24:02

that we've got is that JavaScript thinks

6:24:05

the string starts with this inverted

6:24:07

comma and actually finishes with this

6:24:09

apostrophe. Because to JavaScript, the

6:24:11

inverted comma and the apostrophe are

6:24:13

exactly the same thing. Now, if I

6:24:16

removed this apostrophe, well, look, the

6:24:18

red lines disappeared, and that actually

6:24:21

works. But that's not good enough. We

6:24:23

don't want to have to make a typo in our

6:24:25

string just to avoid an error. So, we

6:24:28

need another solution here. And the

6:24:30

solution is the escape character. Let me

6:24:33

just put that apostrophe back in. Now,

6:24:36

the escape character is the backslash.

6:24:39

And I put it right in there. And you'll

6:24:41

see the red line has all disappeared.

6:24:44

Let's hit save. And now I could do the

6:24:46

same thing if I went back to our

6:24:48

original quotation marks. The apostrophe

6:24:50

now doesn't need an escape character. So

6:24:52

I can delete that. But we do need an

6:24:55

escape character right here. And a

6:24:58

second one right here. Now let's hit

6:25:00

save. And we get the same result. It is

6:25:03

working. So what exactly are these

6:25:05

escape characters doing? Well, what the

6:25:07

escape character does is it tells

6:25:09

JavaScript that the next character

6:25:11

should not be seen as a string

6:25:14

delimiter. So the next character is not

6:25:16

starting or finishing a string. It's

6:25:18

just part of the string. So whenever you

6:25:21

run into the problem of having to use a

6:25:23

quotation mark or an apostrophe inside a

6:25:26

string and you get an error because it's

6:25:28

clashing with your string delimiters,

6:25:30

i.e. whatever you're using to open and

6:25:33

close the string. Well, you can use the

6:25:35

escape character to tell JavaScript that

6:25:38

the character that comes next is not to

6:25:40

be treated as a string delimiter. It's

6:25:42

not to be treated as a piece of code.

6:25:44

It's just part of the string. Now, as

6:25:47

you spend more time in coding, you will

6:25:48

come across escape characters more and

6:25:50

more. But that is just a really quick

6:25:52

introduction to them to solve that

6:25:54

really common problem. Okay, I just

6:25:56

wanted to bring that to your attention.

6:25:57

Now, let's get back to the main project.

6:26:03

Okay, it's time for a challenge. This

6:26:05

time you are going to create a feature

6:26:07

that we already have on Scrimma because

6:26:09

on the dashboard we welcome our users by

6:26:11

saying welcome back Pier Harold Borggan.

6:26:13

That's a normal thing a lot of apps do.

6:26:15

So it makes sense to try to implement it

6:26:17

and the way you want to do it is through

6:26:19

grabbing a hold of this paragraph here

6:26:21

which I've given an ID of welcome-L.

6:26:24

That is the first part of the challenge.

6:26:26

You are going to store that paragraph in

6:26:28

a variable called welcome L using this

6:26:31

camel case convention. And then you are

6:26:33

to create two variables name and

6:26:35

greeting that contains your name and the

6:26:38

greeting we want to render on the page.

6:26:40

In our case that is welcome back.

6:26:42

Finally you are going to render the

6:26:44

entire welcome message using welcome

6:26:46

liner text. So go ahead and give this

6:26:50

one a shot and then I will show you the

6:26:51

solution when you return back to this

6:26:53

cast.

6:26:58

Okay, let's do this. We'll start by

6:27:00

grabbing the welcome L paragraph. Do let

6:27:04

welcome L equals document.getelement

6:27:08

by id passing in the id we have here

6:27:12

like that. Now we need to create the two

6:27:15

variables. Let name my name is pair

6:27:18

harold.

6:27:20

Let greeting

6:27:22

clear welcome back and finally rendering

6:27:26

it out. That is done by doing welcome l

6:27:31

dot inner text

6:27:34

equals meeting plus name. Now if we run

6:27:39

this we can see we are rendering out

6:27:41

welcome back pier Harold Borggan but

6:27:43

there's no space between welcome back

6:27:45

and my name that can easily be solved by

6:27:47

just adding a space after welcome back

6:27:50

or we could of course hardcode it in in

6:27:52

between these two variables when we

6:27:54

concatenated the string as well but that

6:27:56

doesn't really matter that much in this

6:27:58

case. So let's just stick with this and

6:28:00

move on to the next lesson.

6:28:05

Okay. Now, there's one more thing we

6:28:07

want to do because personally, I think

6:28:08

this welcome message could be a little

6:28:10

bit more lively and fun. And what would

6:28:12

help there is to add an emoji. For

6:28:14

example, this emoji right here that will

6:28:16

look pretty nice. So, I want you to add

6:28:18

that to the welcome element inner text.

6:28:21

However, there's a catch. You are not

6:28:24

allowed to modify the code over line 9.

6:28:27

You have to write it below. So, the

6:28:29

question is, how can you add this emoji

6:28:32

to the end here in the browser? by

6:28:35

simply writing more code, not by

6:28:37

modifying any of the existing code. And

6:28:40

to give you a hint, you need to remember

6:28:42

back what you did when you incremented

6:28:45

numbers. This technique here, you can do

6:28:47

the same thing with welcomel.in text. So

6:28:50

go ahead and give this a shot.

6:28:56

Okay, hopefully that went well. If not,

6:28:59

no worries. We'll do this together. What

6:29:01

we're simply going to do here is instead

6:29:04

of using count, we're going to use

6:29:06

welcome liner text. And instead of the

6:29:08

one, we're going to use an emoji. So

6:29:10

here we'll do welcome liner

6:29:14

text equals the old welcome

6:29:19

else inner text plus this new emoji

6:29:24

right here. And an emoji is just a

6:29:26

string like all other characters. It's

6:29:28

just rendered out a little bit fancy.

6:29:30

So, if we run this, you can see yes, we

6:29:32

indeed get the emoji at the end. Now,

6:29:34

before we leave, I want to teach you a

6:29:36

little trick because this line here is

6:29:39

pretty clunky. Writing the welcome liner

6:29:42

text twice. It's not something you'll

6:29:44

see out in the while because there's a

6:29:46

shorter version of writing this and that

6:29:48

is simply using the plus equal operator.

6:29:53

What it does, it takes the current value

6:29:55

you have and then adds this one after

6:29:58

it. So it's the exact same thing that

6:30:00

you were doing here. Seem a bit weird to

6:30:03

do this plus equal sign here. Just try

6:30:05

and remember that it simply takes what

6:30:06

you have here and adds this to it. So

6:30:09

that after this line, welcome.ext

6:30:12

consists of the entire thing here.

6:30:16

Okay, with that in mind, let's go back

6:30:18

to our passenger counter app.

6:30:22

Okay, just a minor thing before we start

6:30:24

using strings in our app. I want you to

6:30:27

use the plus equals technique instead of

6:30:29

this slightly longer count equals count

6:30:31

plus one technique. Go ahead and do

6:30:33

that.

6:30:38

Okay, hopefully that went well by simply

6:30:40

doing like this. Count plus equals 1.

6:30:44

Run the code. Yes, it works. Let's move

6:30:47

on.

6:30:52

Okay, so now you are going to solve a

6:30:54

super cool challenge. You're going to

6:30:55

take everything you've learned about

6:30:57

JavaScript up until now and use it to

6:31:00

create this save feature. You can see it

6:31:02

says previous entries and then four, 5,

6:31:05

11 with dashes that separate them. And

6:31:08

these are, of course, added every time

6:31:10

you hit the save button. Now, there's a

6:31:12

dash after the three numbers as well.

6:31:15

Don't worry about that. It might look a

6:31:17

little bit weird, but it's the easiest

6:31:19

way to do this, and we want to do it the

6:31:20

easiest way now that you're building

6:31:22

stuff like this first time around. We

6:31:24

don't want to worry about details. Make

6:31:25

it work first, then make it better.

6:31:27

That's my philosophy. So, we're just

6:31:29

going to make this work. Okay. So, your

6:31:32

three challenges are listed as comments

6:31:34

here in the JavaScript. And in the HTML,

6:31:37

I'm going to write the paragraph for you

6:31:39

so that you have something to work with.

6:31:41

So, this is a P tag and it should say

6:31:44

previous entries like that. And I'm

6:31:47

going to give it an ID equals save L for

6:31:51

save element. And then you are going to

6:31:53

grab the save element paragraph and

6:31:55

store it in a variable called save l.

6:31:58

And then in the save function which is

6:32:00

triggered when the save button is

6:32:01

clicked on you are going to create a

6:32:03

variable that contains both the count

6:32:06

that is the number and the dash

6:32:08

separator. So it'll look something like

6:32:10

this like 12 space dash space. And then

6:32:14

you are to render this newly created

6:32:16

variable into the save element using

6:32:18

inner text. However, you must make sure

6:32:21

that you don't delete the existing

6:32:23

content from the save l paragraph

6:32:25

because you want to concatenate the

6:32:27

string, not wipe it out entirely and

6:32:29

replace the paragraph with the latest

6:32:31

entry. So, you got to remember your plus

6:32:34

equal, but luckily you know how to use

6:32:36

plus equals and that might be helpful in

6:32:38

this situation. Finally, one thing I

6:32:40

want to mention is that you might

6:32:41

struggle a little bit with the spaces

6:32:43

here and it might end up slightly

6:32:45

different than what you can see here and

6:32:47

that is perfectly okay. Don't worry

6:32:48

about that. In the next cast actually,

6:32:50

we are going to do some searching online

6:32:53

to figure out if there are some

6:32:54

alternative methods we can do this on

6:32:56

which will help us keep these spaces.

6:32:59

That's a critical part of web

6:33:00

development, searching for solutions

6:33:02

online. So, I've left a little gotcha

6:33:04

for you here so that we get a nice

6:33:05

little problem to solve using Google and

6:33:08

some online docs in the next cast. So,

6:33:10

don't worry about that. Just go ahead

6:33:12

and give this your best shot. And if you

6:33:13

need help, just revert to this

6:33:15

screencast and I will show you the

6:33:16

solution as well.

6:33:22

Okay, hopefully this went well. If not,

6:33:25

no worries. Let's do it together. First,

6:33:27

we are going to do let save L. That'll

6:33:30

be document

6:33:32

getelement by id and we are going to get

6:33:35

the save d-l like that. As always, I

6:33:39

like to console log just to see that I

6:33:42

have the correct element fetched. Let's

6:33:45

run this code. Then yes, bringing up the

6:33:47

console, we see that we have grabbed the

6:33:49

correct element. Then we can move on.

6:33:51

First, create a variable that contains

6:33:53

both the count and the dash separator.

6:33:56

So, what are we going to call this

6:33:57

variable? I intentionally didn't give

6:34:00

you a name for it because I wanted you

6:34:01

to think what could be a suitable name

6:34:03

for this string. And there's no right or

6:34:05

wrong answer, but one thing you could

6:34:07

call it would be count string or count

6:34:09

str like that. So, it is the count, but

6:34:13

we've turned it into a string. So a

6:34:14

count string kind of makes sense and the

6:34:17

value of it will be count plus and then

6:34:20

the string. I'll add a space a dash and

6:34:23

a space. All right. Three render the

6:34:26

variable using inner text. Okay. Let's

6:34:28

do it down here. We'll do save l dot

6:34:33

text. Then you might have been tempted

6:34:35

to do equal count r but that won't work.

6:34:39

Let's just try it. Run the code. We

6:34:41

increment and we hit save. Boom. Then we

6:34:43

suddenly remove the previous entries

6:34:46

text. We cleared it out, of course,

6:34:48

because we set all of the inner text to

6:34:50

be just this count string. That doesn't

6:34:52

work. We have to take into account what

6:34:54

was there previously as well. So we add

6:34:56

plus equals like that. Increment,

6:34:59

increment, increment. Save. Yes, that

6:35:01

works. All right. So it works really

6:35:05

well actually. However, this dash at the

6:35:08

end here is gone as is our space here in

6:35:11

the paragraph. And that is a bit weird

6:35:14

because we want to keep those spaces.

6:35:16

However, it's also a great opportunity

6:35:18

to do some searching online in order to

6:35:20

solve this problem which is a critical

6:35:22

skill for any developers, namely finding

6:35:24

answers online. We'll do that in the

6:35:27

next cast.

6:35:31

Okay. So, we have this little problem

6:35:33

here, which is that our spaces aren't

6:35:35

working in the way we want them to work.

6:35:36

Basically, this space here gets lost on

6:35:40

the way somewhere. I don't know where

6:35:42

but um it happens. How do we go about

6:35:44

figuring out what's wrong? Well, looking

6:35:47

at these two lines, which is where we

6:35:49

deal with this save element paragraph,

6:35:51

you can think what would be a suspect?

6:35:53

Which tool that we're using would be a

6:35:55

good suspect.

6:35:57

And I'm going to point to this one right

6:35:59

here cuz I happen to know that that is

6:36:01

actually the guilty one, the inner text.

6:36:04

And let's say you' guessed that as well.

6:36:06

How do you go about finding another tool

6:36:09

that doesn't work this way? Well, one

6:36:11

thing you can do is you can write inner

6:36:13

text alternative and then MDN. Put that

6:36:17

into Google and see what it returns. And

6:36:20

MDN is short for Mozilla Developer

6:36:22

Networks and it's a great resource. So

6:36:24

if we do that, type that into Google,

6:36:27

you can see the very first result is

6:36:29

node text content. Hm. Okay, that's

6:36:32

interesting. Let's click into that.

6:36:35

There we land on an interface you're

6:36:36

going to get very familiar with the MDN

6:36:39

web docs. And it says node.ext content.

6:36:43

Don't worry about this node here. It's

6:36:44

kind of fancy way of saying HTML element

6:36:47

sort of, not entirely, but just

6:36:49

translate it to HTML element right now

6:36:52

and you'll be good. And then you can

6:36:53

read the text content property of the

6:36:55

HTML element represents the text content

6:36:58

of the element. Okay, seems pretty

6:37:01

useful to me. And then we can scroll a

6:37:03

little bit down and then you see they've

6:37:05

actually listed up differences between

6:37:07

inner text and text content. And here if

6:37:10

we scan through this you can see that

6:37:13

inner text only shows human readable

6:37:15

elements. And yet again inner text is

6:37:18

aware of styling and won't return the

6:37:20

text of hidden elements. Okay. So it

6:37:23

seems to be that the inner text somehow

6:37:25

struggles a little bit to return things

6:37:28

that are hidden or not human readable.

6:37:31

And like yeah, a space is certainly not

6:37:33

that human readable as a character. So

6:37:36

maybe we can just change it then to text

6:37:39

content instead. Let's try that. Text

6:37:43

content

6:37:44

code increment. Increment increment.

6:37:47

Save. Oh. Oh yes indeed. Now we get the

6:37:52

spaces. And one thing I want to

6:37:55

highlight here is that while the Misilla

6:37:57

WebDocs is a great resource, it's a very

6:38:00

comprehensive, the language you'll see

6:38:02

in these kinds of documentation sites is

6:38:04

often very technical, which is why I

6:38:05

kind of skimmed through and found some

6:38:07

hints of human readable and hidden. And

6:38:09

I kind of didn't worry too much about

6:38:11

going into depth. And I think you as

6:38:13

well should think when you see a page

6:38:15

like this, don't feel that you need to

6:38:18

understand everything. And for the love

6:38:20

of God, don't try to learn to code by

6:38:22

just reading documentation. Some people

6:38:24

say that's a good idea. I think it's a

6:38:26

terrible idea. You want to slowly learn

6:38:28

how to get comfortable reading

6:38:29

documentation, but you also want to

6:38:31

ignore all of the complex stuff that

6:38:33

it's very often wrapped within. And

6:38:35

there are other sites as well that

6:38:36

explain things in various degrees of

6:38:38

difficulty. For example, there's also

6:38:39

something called W3 Schools, which is

6:38:41

very good. There's Stack Overflow and

6:38:43

many more. And you're going to see more

6:38:45

of this as you progress in the course as

6:38:46

we're going to come back to this

6:38:48

debugging concept later on as well. But

6:38:50

as for now, we've just had a little

6:38:52

sneak peek on the Mozilla developer

6:38:53

network. And actually, it's kind of

6:38:55

trash talking the text here and saying

6:38:58

that it's also computationally

6:39:00

expensive. So to me, I've gotten enough

6:39:02

hints that I actually want to use.ext

6:39:05

content instead of inner text. I'm going

6:39:07

to change this up here as well.

6:39:10

Like that.

6:39:12

It still works. Great. Now our app is

6:39:16

almost complete. There's only one more

6:39:17

thing we need to do and we'll do that in

6:39:19

the next cast.

6:39:24

Okay. So now we are going to put the

6:39:25

final pieces in our puzzle because we

6:39:28

need to fix the fact that if I increment

6:39:31

this and then hit save and then the

6:39:33

subway leaves the station and I'm going

6:39:35

to count a new group of people then with

6:39:37

the current solution I will be counting

6:39:39

further on from six like 7 8 9 and

6:39:42

that's not what we want. We want this

6:39:43

one to be set back to zero every time we

6:39:46

hit save. And to do this you need to

6:39:48

write two lines of code. And at this

6:39:50

point, I want to just throw you into the

6:39:52

deep end of the pool and see how you

6:39:54

swim. So, I'm not going to give you any

6:39:56

hints or write any pseudo code or tell

6:39:58

you where you're going to write these

6:40:00

two lines. Now, you really have to think

6:40:02

and think for yourself, what do you need

6:40:04

to do here in order to make this work?

6:40:05

And feel free to hack a little bit on

6:40:07

it. Try a solution, run the code, see

6:40:09

how it works, console log out the

6:40:11

values, and just hack away at it and

6:40:12

give it your best shot. And if you don't

6:40:14

manage to do it, no worries at all

6:40:16

because I will show you how to do it

6:40:18

again, of course, when you return back

6:40:19

to the screencast. So then you can just

6:40:21

try to do it again after you've seen my

6:40:23

solution. Anyway, enough talk. Jump into

6:40:25

the code here and give this a shot.

6:40:32

Okay, now let's solve this together. So,

6:40:35

what we need to do is write a couple of

6:40:37

lines in this save function because this

6:40:39

is where the magic should happen because

6:40:41

it's when we hit the save button that we

6:40:44

want this value to be set back to zero.

6:40:47

And how do we set this element to be

6:40:49

zero? Well, it is the count element

6:40:52

which we've worked with previously. And

6:40:54

setting it to zero, we know how to do

6:40:55

that. We can do count L dot text content

6:40:59

and set that equal to zero. Like that.

6:41:02

If I rerun the code, increment,

6:41:04

increment, increment, increment, hit

6:41:05

save, and yes, it's now zero. But if I

6:41:09

now try to hit the increment again,

6:41:11

you'll see, oh, five.

6:41:14

That's weird. Why is that? That's

6:41:16

because we have indeed set the text

6:41:18

content of the count element to zero.

6:41:21

So, this H2 right here. But in the

6:41:25

JavaScript, we're still keeping track of

6:41:27

the count. And that count has been

6:41:28

incremented this point five times. So

6:41:31

what we needed to do here when we set

6:41:34

the text content to zero is to also set

6:41:38

the count back to zero as well because

6:41:40

JavaScript remembers what we've done

6:41:42

previously unless we refresh the entire

6:41:44

browser. So even though JavaScript can

6:41:46

see that yeah you are setting the text

6:41:47

content of this element here to zero it

6:41:50

still keeps track of the count here and

6:41:52

JavaScript can't deduct that since you

6:41:54

want to set this here to zero you also

6:41:56

want this to zero. No, you got to give

6:41:58

JavaScript very specific instructions.

6:42:00

So you need to do here count equals zero

6:42:03

as well. Now if we run the code bam bam

6:42:06

bam save it's set to zero. And yes we

6:42:10

indeed start at zero again.

6:42:14

Oh hey it's Gil from Scribba. I bet you

6:42:16

didn't expect me here. P just wanted me

6:42:18

to pop in real quick to share something

6:42:19

important with you. Thanks Pere. So in

6:42:21

this section, we started off by using

6:42:23

the onclick event handler HTML attribute

6:42:26

to call and run functions like increment

6:42:29

and save when their corresponding

6:42:31

buttons get clicked. This is an

6:42:33

intuitive and straightforward way to

6:42:35

understand how event listeners can be

6:42:37

attached to HTML elements and grasp the

6:42:40

basics of interactivity. But in larger

6:42:42

realworld projects, mixing HTML

6:42:45

structure and JavaScript behavior like

6:42:47

this can lead to code that is harder to

6:42:50

maintain and manage. So keep this in

6:42:53

mind and real soon we'll teach you the

6:42:54

more recommended and maintainable

6:42:56

approach for registering event listeners

6:42:58

and executing JavaScript. And this app

6:43:01

is looking outstanding by the way. So

6:43:03

great job getting this far.

6:43:08

So you have built your very first

6:43:11

JavaScript app from scratch.

6:43:14

Congratulations. That is a huge

6:43:16

accomplishment. So give yourself a pat

6:43:18

on the back. You have really learned a

6:43:20

lot in this section. And to prove that

6:43:21

to you, we're actually going to do a

6:43:23

little recap so that you get to see in

6:43:25

front of you all of the new concepts

6:43:27

you've shoved into your brain at this

6:43:29

point. So we started out with the script

6:43:31

tag. If you remember, we had it here in

6:43:33

the index.html HTML file and we wrote

6:43:36

our JavaScript internally in this file.

6:43:39

However, we realized that that wasn't

6:43:40

the way we wanted to go. So, we instead

6:43:42

pointed this script tag to a source,

6:43:45

namely the index.js file, so that we

6:43:47

could write our JavaScript there

6:43:49

instead. Then, we moved on quickly and

6:43:51

learned about variables, namely the let

6:43:54

variable, and we set its value to a

6:43:56

number, which brings us to your very

6:43:58

first data type, numbers. You learned

6:44:00

how to work with numbers, do

6:44:01

mathematical operations, and even

6:44:03

increment numbers here on line six, and

6:44:06

also reassign the count variable to zero

6:44:09

here on line 14. So, a lot of work with

6:44:12

numbers in this app, but you also

6:44:14

learned about strings, which was your

6:44:16

second data type. Here you added a

6:44:18

string to build the save feature, and

6:44:20

also you console logged out a few

6:44:22

strings along the way with code that

6:44:23

we've deleted now. So I added this

6:44:25

console log here to remind you about it

6:44:27

because that is a truly important

6:44:29

concept in developing and you will use

6:44:31

it throughout your entire career. Also

6:44:33

another thing you will use constantly as

6:44:35

a developer is functions. You learned

6:44:37

how to create functions like this

6:44:39

increment and save function and also how

6:44:42

to call them aka invoke them from the

6:44:45

HTML file here on the button clicks. And

6:44:48

that brings us to the next concept which

6:44:50

you learned a ton about which is the DOM

6:44:52

or the document object model or what I

6:44:55

like to call it how to use JavaScript to

6:44:57

change the website.

6:45:00

So we interacted with the DOM at several

6:45:01

places. For example, up here where we

6:45:03

did document.getelement

6:45:05

by ID. That's one you are going to get

6:45:08

very familiar with throughout this

6:45:09

module. We passed in the ID as a string

6:45:13

so that the JavaScript was able to head

6:45:15

into the HTML and fetch out the content

6:45:19

you told it to look for. And another way

6:45:21

we interacted with the DOM was through

6:45:23

the inner text property. We used that

6:45:26

here instead of text content. But then

6:45:29

we Googled our way to the Mozilla

6:45:30

developer network realized that actually

6:45:33

text content is a better solution. So,

6:45:36

we learned about that and oh my god,

6:45:38

this is a lot of concepts to learn. I

6:45:40

can totally understand if you're a

6:45:42

little bit overwhelmed and if you feel

6:45:43

that you are on thin ice on a few of

6:45:45

these concepts, that's totally okay. We

6:45:48

are going to repeat all of these things

6:45:50

over and over again throughout the

6:45:51

module. So, don't worry about that.

6:45:53

Actually, we are going to jump directly

6:45:56

into a section where you are going to

6:45:57

get assignments that test you for these

6:46:00

skills just to give you that repetition

6:46:02

and muscle memory you need in order to

6:46:04

make these concepts become second

6:46:05

nature. So, let's go ahead and get some

6:46:08

repetition and then once we've done with

6:46:10

that, we'll move on to our next big

6:46:12

project, the Blackjack app, which is

6:46:15

going to be so much fun to build. So, I

6:46:17

can't wait to see you there. For now,

6:46:19

let's jump into a few quickfire

6:46:21

challenges.

6:46:25

Okay, in this challenge you are going to

6:46:27

repeat variables. So first you are going

6:46:30

to create two variables first name and

6:46:33

last name. And obviously I want you to

6:46:35

set their values to your first name and

6:46:37

your last name and then concatenate the

6:46:40

two variables into a third variable

6:46:43

called full name so that you have your

6:46:45

full name. Finally, log full name out to

6:46:48

the console. Go ahead and give this a

6:46:49

shot right now and then I will show you

6:46:51

my solution when you return back to this

6:46:53

screencast.

6:46:59

Okay, let's do this. I'll do first name

6:47:03

equals pair and then I'll do let last

6:47:07

name equals Borggan like that. Then we

6:47:11

need to concatenate the two together.

6:47:14

Let all name equals first name plus last

6:47:19

name. Like that. Finally, I want to log

6:47:22

it to the console. Console.log

6:47:26

full name. Now I can run the code. And

6:47:29

as you can see, we're logging Pier

6:47:30

Borggan to the console. But there's no

6:47:33

space in between the two names. So I

6:47:36

could achieve this in a multitude of

6:47:38

ways. either by adding a space here. Now

6:47:41

it's better or adding a space before

6:47:45

Borggan still good. However, neither of

6:47:48

these are optimal since I want the first

6:47:51

name and last name to be the name and

6:47:52

the name only, not an extra space. So

6:47:55

what I'll do instead is in between here,

6:47:58

I'll add an extra space like that.

6:48:01

Running the code. There we go. Now first

6:48:04

name and last name contain only the

6:48:06

characters of my name. But we still get

6:48:09

the space by adding this third string

6:48:11

here when we create full name. So no

6:48:14

matter how you did it, great job. Let's

6:48:16

move on.

6:48:20

In this challenge, you are going to

6:48:22

create a function that logs out hi there

6:48:24

Linda when called. And you have to use

6:48:27

the name and the greeting variable

6:48:29

inside of the body of your function. And

6:48:32

also there's a comma and an exclamation

6:48:34

mark you also have to include so that

6:48:36

you get this exact string log to the

6:48:38

console. So go ahead and solve this one

6:48:41

and then I will show you the solution

6:48:42

afterwards as well.

6:48:47

Okay, let's do this. Create a function.

6:48:49

I'll call it greet Linda. Like that here

6:48:53

we are going to console log first the

6:48:55

greeting. Then we have to plus the comma

6:48:59

and the space and then plus again then

6:49:02

the name and then plus again and then

6:49:04

the exclamation mark like that. Final

6:49:06

step to check our code we need to run

6:49:08

it. Greet Linda like that. Running the

6:49:12

code and there we see this exact string

6:49:14

in the console. Great job.

6:49:20

In this challenge you are going to

6:49:21

practice your incrementing and

6:49:23

decrementing skills. So let's say that

6:49:25

you are building a game and the player

6:49:27

is collecting points which currently are

6:49:29

at three and you need to create two

6:49:31

functions. One which is called add three

6:49:33

points and one which is called remove

6:49:36

one point and of course then have these

6:49:38

add and remove their given points from

6:49:40

or to the my points variable. So remove

6:49:43

one point should decrease my points with

6:49:46

one. Add three points should add three

6:49:49

points to the my points variable. And

6:49:52

your job is to create those two

6:49:54

functions and then call them however

6:49:56

many times you need to call them in

6:49:58

order for this line down here to log out

6:50:02

the number 10. So you are going to write

6:50:04

your code in between here. You can add

6:50:07

as many lines as you want. But when you

6:50:09

eventually run the code, my point should

6:50:11

be 10. And you should only have changed

6:50:14

my points via calling these two

6:50:17

functions a number of times. So go ahead

6:50:20

and give this one your best shot and

6:50:22

then I of course will show you the

6:50:24

solution afterwards as well.

6:50:30

Okay, hopefully that went well. Let's do

6:50:32

it together. We'll do function add three

6:50:36

points. What that'll do is take my point

6:50:40

and plus equal three

6:50:44

function remove one point

6:50:49

and that should do my point minus equal

6:50:52

one like that. Okay, now we have them

6:50:56

which means that we just need to call

6:50:57

them a couple of times. We are at three

6:50:59

and we need to get it up to 10. What I

6:51:02

will do then is I'll first do add three

6:51:04

points. Call that three times because

6:51:07

then we'll go up to 12.

6:51:12

My calculation is correct. Let's run

6:51:15

this. Yes, we are indeed logging 12.

6:51:18

That means that we can remove one point

6:51:22

two times. That should get us to 10.

6:51:25

Yes, we are logging out 10. So, we have

6:51:28

solved the challenge. Great job.

6:51:34

Okay, it's time for some strings and

6:51:36

numbers repetition. You are going to add

6:51:38

a bunch of strings and numbers together

6:51:40

and try to predict what the result is.

6:51:43

So here after each one of these lines,

6:51:45

I've added two slashes. That means that

6:51:47

you can write your prediction. Try to go

6:51:50

through all of these and then run the

6:51:52

code and see how you did it. And then I

6:51:54

will give it a shot afterwards as well.

6:51:56

Good luck.

6:52:01

Okay, starting on the number two, it is

6:52:04

a string plus a number. We know that

6:52:07

JavaScript then turns both of these into

6:52:09

strings. So, it becomes 22. Here, 11 +

6:52:14

7, that's just two numbers. We get 18

6:52:16

and as a number this time and not as a

6:52:19

string. 6 + 5. You might be fooled to

6:52:22

think that JavaScript would treat this

6:52:24

as a number calculation since the number

6:52:27

is first. But no, actually the string

6:52:29

wins and it becomes 65. Likewise with

6:52:34

this one here, it's very natural to

6:52:35

think that what you want to do is add

6:52:38

these two points together so that it's

6:52:39

my points is 14. But no, since you have

6:52:42

a string here, everything will be turned

6:52:43

into a string and the result will be my

6:52:45

points colon 59. 2 + 2 that's four just

6:52:51

a number and finally two strings of

6:52:54

course becomes a string 1114 like that

6:52:58

let's run this and indeed all of my

6:53:00

predictions were correct that was good

6:53:03

otherwise I would lose all my integrity

6:53:05

so I'm really happy about that let's

6:53:08

move on

6:53:11

okay let's imagine that you are working

6:53:13

on an e-commerce website and this

6:53:15

website sells shoes so here you can see

6:53:18

a Nike shoe with a purchase button. The

6:53:20

HTML is located here, of course, with an

6:53:23

image tag, the paragraph or the Nike

6:53:26

shoe, the button, but then there's also

6:53:28

an empty error paragraph. And this is

6:53:31

pretty common because in case there's an

6:53:33

error going happening, for example, the

6:53:35

purchase didn't go through or some kind

6:53:37

of bug caused the operation to fail or

6:53:39

whatever it is, we want to render

6:53:41

something inside of this paragraph. So

6:53:44

that is your job in this challenge. You

6:53:46

are going to set up the JavaScript so

6:53:47

that when the user clicks on the

6:53:49

purchase button, you are to render out

6:53:51

something went wrong. Please try again

6:53:53

in the paragraph that has the ID of

6:53:56

error. That's of course this one. And

6:53:58

the button they will click is of course

6:54:00

that one. You can see there is some CSS

6:54:03

here, but you're not going to worry

6:54:05

about that because this challenge is all

6:54:07

about the JavaScript and of course also

6:54:10

hooking up the onclick event listener on

6:54:13

this button. You should know how to do

6:54:14

that by now and you should also know how

6:54:17

to render text inside of a paragraph. So

6:54:20

go ahead and give this one a shot and

6:54:21

then of course I will show you the

6:54:22

solution afterwards as well.

6:54:28

So there are two parts to this

6:54:30

challenge. First there's registering

6:54:32

that the user clicks on the button and

6:54:34

then there is rendering out the text in

6:54:36

the DOM. So let's take first things

6:54:38

first the button. So I'll head over to

6:54:41

the button and do an on click event

6:54:44

listener. And here we need to specify

6:54:46

which function we want to run. We

6:54:48

haven't written any function yet. So

6:54:50

let's do that. We'll do function. I'll

6:54:53

call it purchase because that's what the

6:54:55

user is trying to do. Open and close

6:54:57

curly brackets. Now I can take this

6:55:00

function and specify that when the user

6:55:03

clicks the button, we want to call this

6:55:05

function. Good stuff. Let's just console

6:55:09

log out button clicked.

6:55:12

Run this code. Try to click the button.

6:55:14

And yes, we are rendering out button

6:55:16

clicked. Good. The next step is to grab

6:55:19

a hold of the paragraph that we are

6:55:22

going to render text inside of. So we'll

6:55:24

do let

6:55:27

error paragraph and document.getelement

6:55:32

by id passing in error like that. Yet

6:55:36

again, we can do console log just to

6:55:38

verify that we have grabbed a hold of

6:55:40

the right paragraph. We run the code and

6:55:42

bring up the console and yes, we can see

6:55:44

that we have the paragraph.

6:55:47

Then inside of the purchase function,

6:55:49

this is where we want to trigger the

6:55:51

rendering of the error text. I'll do

6:55:54

error paragraph dot text content

6:55:59

equals

6:56:00

this string right here.

6:56:03

Now, if we rerun the code, click the

6:56:06

purchase button. Yes, something went

6:56:08

wrong. Please try again. And as you can

6:56:10

see, it's rendered out in red text,

6:56:11

which is very common because we want to

6:56:13

grab the user's attention and tell them

6:56:15

that something wrong has happened.

6:56:17

That's of course something we have

6:56:18

specified in the CSS, but this challenge

6:56:21

is not about CSS. It was about

6:56:22

JavaScript. So, great job solving this.

6:56:25

Let's move on.

6:56:29

Okay. In this challenge, you are going

6:56:30

to create a very basic calculator. As

6:56:33

you can see in the mini browser here,

6:56:35

I've set up the UI for you. Here we have

6:56:38

two buttons. Here we have the numbers 8

6:56:40

and two. And then there's four buttons.

6:56:43

Add, subtract, divide, and multiply. If

6:56:45

I try to click one of these now, nothing

6:56:47

happens. But what you then of course

6:56:48

want to happen is that for example, if

6:56:50

you hit subtract, you are to take 8

6:56:52

minus 2, which is six, and then render

6:56:55

that out in the sum here. so that it'll

6:56:57

say sum colon 6. Taking a look at the

6:57:01

HTML, we can see that the numbers at the

6:57:04

top num 1 L and num 2 L that's the 8 and

6:57:07

two are simply spans. However, they are

6:57:10

empty. So, how come we have content in

6:57:13

them when they are rendered? Well, that

6:57:15

is because I'm doing that in the

6:57:16

JavaScript. First defining two let

6:57:19

variables num one and num two and

6:57:21

setting them to 8 and two. And then

6:57:23

doing document get element by id

6:57:26

fetching out num 1 L and num 2 L and

6:57:29

setting each of their text contents to

6:57:32

num one and num two. And that's why

6:57:35

we're rendering out these numbers.

6:57:37

Moving on to the buttons, you can see

6:57:39

that they are very simple. Only the tag

6:57:42

and the text. I have not created the

6:57:44

event listeners because that's your job.

6:57:46

And then finally the span with the id of

6:57:49

suml is where you are going to render

6:57:51

out the result of the calculation.

6:57:54

So summing this up you are to create

6:57:56

four functions here in the JavaScript

6:57:57

file. Add, subtract, divide and

6:58:00

multiply. And then you need to call the

6:58:01

correct function when the user clicks on

6:58:04

one of the buttons. So obviously when

6:58:06

the user clicks the add button you are

6:58:07

to call the add function and vice versa

6:58:10

with all the others. Then inside of the

6:58:12

functions you are to perform the given

6:58:14

calculation. So in add you need to add

6:58:16

num one and num two together and

6:58:19

subtract you will take num one minus num

6:58:21

two and divide and so on. Finally render

6:58:25

the result of the calculation in the

6:58:26

paragraph that has the ID of sum.

6:58:29

So go ahead and give this one a shot and

6:58:31

then of course return back to the

6:58:33

screencast when you want to see my

6:58:34

solution.

6:58:40

Okay, let's do this. I'm going to start

6:58:43

by creating here an on click

6:58:47

event handler and call this function add

6:58:50

because when the user clicks the add

6:58:51

button we want to invoke a function

6:58:53

which are to be named add and then we

6:58:55

need to create the function function add

6:58:59

here what do we want to do

6:59:04

first we just want to check that it

6:59:05

works

6:59:07

the code add yes we are logging out now

6:59:11

then we need to grab a hold of the sum

6:59:13

paragraph. So I'll do let sum l equals

6:59:18

document getelement by id and the ID is

6:59:24

sum-l like that. Here I'm just going to

6:59:27

see if it works by doing sum l.ext

6:59:31

content equals

6:59:34

num 1 + num 2.

6:59:38

Rerunning the code. And yes, there we

6:59:41

can see we're rendering out 10. However,

6:59:44

we wanted to render out some colon

6:59:46

equals 10. So, let's try adding that sum

6:59:50

colon plus num one plus num two.

6:59:54

Rerunning the code, hitting add. And now

6:59:57

we have come into a situation where

6:59:59

actually JavaScript is turning all of

7:00:01

our three values into strings. As you

7:00:04

remember, when you add strings and

7:00:06

numbers together, they're all turned

7:00:07

into strings. What we need to do here is

7:00:10

first perform the calculation and then

7:00:13

concatenate that with the string. So

7:00:15

we'll do let result equals num 1 + num 2

7:00:19

because here we're only adding numbers

7:00:20

together and JavaScript will will treat

7:00:22

them as numbers and thus perform a

7:00:24

mathematical calculation and not a

7:00:26

string concatenation. So then we can

7:00:29

replace this expression here with

7:00:31

result. Rerunning the code, clicking

7:00:34

add. And yes, there we go.

7:00:37

Great stuff. Now, I'm a little bit lazy,

7:00:41

so I'm just going to copy this, paste it

7:00:44

in, and do subtract, and simply replace

7:00:49

this with a minus.

7:00:51

Add the on click equals subtract

7:00:56

like that. Running the code, clicking

7:00:59

subtract. A sum is six. Brilliant.

7:01:02

Now, we'll just

7:01:05

copy paste again.

7:01:07

divide

7:01:08

should get this. Use the division symbol

7:01:13

and multiply should use the

7:01:16

multiplication symbol. Now we only need

7:01:18

to add the last two event handlers.

7:01:24

Divide is the name of that function.

7:01:29

A space here. And multiply is the name

7:01:32

of the final function. Running the code.

7:01:34

Trying add gives 10. Brilliant. Subtract

7:01:37

gives six. That's correct. Divide

7:01:40

rightfully gives four. And multiply 16.

7:01:42

We have made a calculator. Good job. You

7:01:45

have all reason to be proud of yourself

7:01:47

now. And if you didn't manage to do this

7:01:49

one, if you found it a bit too hard, now

7:01:50

that you've seen the solution, just go

7:01:52

back and try it again. That's great

7:01:54

practice and gives you the muscle memory

7:01:56

you need. And when you're ready, I'll

7:01:57

see you in the next cast.

7:02:02

In the next scrim, you will be given a

7:02:05

solo project. That means a project that

7:02:07

you are going to build all on your own.

7:02:10

So I will not be there to help you

7:02:12

unfortunately. Now before you jump into

7:02:14

the solo project, there's one thing you

7:02:16

need to know about and that is the

7:02:18

service called Figma. It is a design

7:02:20

tool that is heavily used in the

7:02:22

industry these days. So it has almost

7:02:24

become a must-have skill for any

7:02:26

front-end developer working in a team

7:02:28

with designers. You will be given the

7:02:30

solo project design in a Figma file. So

7:02:33

click on this image right here and

7:02:35

create a Figma account. And then once

7:02:38

you're ready, you can click on this

7:02:39

image as Bob Zol here at Scribba has

7:02:42

created a quick walkthrough of Figma for

7:02:46

students who are doing solo projects

7:02:47

here on Scribba. So if you get confused

7:02:50

about the Figma interface, just revert

7:02:52

back to this video and you'll be all

7:02:54

good. Now, a final thing I want to

7:02:56

mention is that the solo project is a

7:02:58

pro offering. So, if you haven't

7:03:00

upgraded to Scribba Pro, now is a great

7:03:03

time to do that. With that, I wish you

7:03:05

good luck.

7:03:09

Okay, it is time to remove the training

7:03:11

wheels and have you build your very own

7:03:13

project from scratch. And the one you're

7:03:16

going to build is this basketball

7:03:18

scorecard. You can see on the right hand

7:03:20

side here. It is a very common app for

7:03:22

not only basketball but many sports

7:03:25

because you need a way to keep track of

7:03:27

the scores between the different teams.

7:03:30

And the requirements are that you are to

7:03:32

build this from scratch or I write that

7:03:34

in quotes because I've given you a

7:03:36

little bit of a skeleton to start from.

7:03:38

I'll show you that in a bit. And also

7:03:40

you are to follow the design. You will

7:03:42

get a Figma file so that you can inspect

7:03:44

this design right here. And of course,

7:03:46

we're going to make all of these six

7:03:48

buttons work according to the expected

7:03:50

behavior. And that is that if you click

7:03:52

on any of these three down here under

7:03:54

the home column, then the home score

7:03:57

will be incremented with the number that

7:03:59

is on the button. So if you click on two

7:04:01

here, the home score should be

7:04:03

incremented from 12 to 14. Likewise, if

7:04:06

you hit on the plus one in the guest

7:04:08

column, then in this case, the guest

7:04:10

score should increase from five to six.

7:04:12

So these are all the requirements.

7:04:14

However, we also have some stretch goals

7:04:16

that you can do if you want to go above

7:04:18

and beyond. But I want to warn you

7:04:20

because in this JavaScript module, I

7:04:22

haven't really taught you the concepts

7:04:24

you need to do in order to complete

7:04:25

these stretch goals. So, these are only

7:04:28

meant for students who are actually

7:04:30

ahead of the class and who've been doing

7:04:31

studying on their own. And actually,

7:04:33

it's only for those of you who find

7:04:35

these requirements to be a bit boring.

7:04:37

So, don't do these stretch goals if you

7:04:39

are struggling. But if you want to go

7:04:41

above and beyond, you can, for example,

7:04:43

add a new game button that sets both of

7:04:46

these scores to zero so that you can

7:04:48

start adding scores. Again, you can also

7:04:50

highlight which team is leading. I'm not

7:04:52

sure how you would want to do that, but

7:04:54

you'll probably find a nice way to

7:04:55

showcase that. And also, you can add

7:04:57

more counters, for example, which period

7:05:00

the game is in, how many fouls each team

7:05:02

has had, and even a countdown timer.

7:05:04

Though, this is really complex. It's far

7:05:06

beyond the scope of the JavaScript I've

7:05:08

been teaching you so far. So, I don't

7:05:10

expect to see a lot of solutions with

7:05:11

this timer implemented. And also, a good

7:05:13

way to practice your overall product and

7:05:16

design skills is to change the design.

7:05:19

Make it your own. You could even turn it

7:05:20

into a counter for a completely

7:05:22

different type of sport and then

7:05:24

accommodate the buttons to whatever

7:05:26

point system that sport has. But, as I

7:05:29

said, the stretch goals are only stretch

7:05:31

goals. They are not a part of the core

7:05:32

requirements. Now, as I said, there's a

7:05:35

Figma file you can use in order to look

7:05:36

at the design more closely. Just click

7:05:38

on this image right here and you'll be

7:05:40

taken to that Figma file. Now, when you

7:05:42

get there, you'll probably see other

7:05:44

people interacting with the file live.

7:05:47

That's how Figma work. It's a

7:05:48

multiplayer app. So, what I want you to

7:05:50

do here is click on the down arrow at

7:05:52

the top here and choose this duplicate

7:05:55

option as that'll give you your very own

7:05:57

Figma file to work with. And if you are

7:05:59

a little bit confused with Figma, you

7:06:01

can click on this link right here and

7:06:02

then that'll take you to a quick Figma

7:06:04

tutorial on YouTube. Now, if you ever

7:06:06

get stuck and don't know what to do

7:06:08

next, we have created a help section for

7:06:10

you where we'll give you hints that'll

7:06:12

hopefully get you unstuck. So, I'll

7:06:15

leave you here with the requirements and

7:06:17

the design as well. You can click on

7:06:19

this design to get to the Figma file and

7:06:21

also here is a link to the help section

7:06:23

I just mentioned. Now, as I said, I have

7:06:25

a little bit of a skeleton for you just

7:06:27

to make sure that you hit the gate

7:06:29

running. So as you can see in the HTML

7:06:31

I've created a div with a class of

7:06:33

container that contains two direct

7:06:35

children which both also are divs that

7:06:38

then again contain their own children

7:06:40

which are H3 elements with home and

7:06:43

guest as the text. And in the mini

7:06:45

browser, you can see that these are set

7:06:47

up side by side as columns, which might

7:06:49

seem a little bit weird given that divs

7:06:51

are block level. But if you head over to

7:06:53

the CSS file, you will understand why

7:06:55

because I've given this container a

7:06:57

display flex, which turns the children

7:06:59

into columns and then set some space

7:07:02

around each of these two columns using

7:07:04

the justify content property. So what

7:07:06

you can do then is start filling out

7:07:08

each of these two columns and slowly

7:07:11

inch your way towards this design and

7:07:13

also towards making it feature complete.

7:07:15

Of course you will have to deal with

7:07:17

JavaScript to make the buttons work and

7:07:18

there I haven't given you any hints. It

7:07:20

is a completely blank file but do

7:07:22

remember that there is a huge community

7:07:24

here at Scribba of amazing students who

7:07:27

love to help each other out. So good

7:07:29

luck and happy coding.

7:07:34

Hello students. My name is Treasure. I'm

7:07:36

a teacher here at Scribba. And first of

7:07:38

all, I want to congratulate you on

7:07:40

completing yet another solo project.

7:07:42

This is a huge accomplishment. So, I

7:07:44

hope that you're proud of yourself. But

7:07:46

our work is not done because now we have

7:07:48

to get this project up on the web to

7:07:51

share with the world. Earlier in your

7:07:53

coursework, you learned a quick way to

7:07:54

share a project on GitHub by creating a

7:07:57

repository or basically a folder that

7:07:59

holds your code using this uploading an

7:08:02

existing file link and manually dragging

7:08:04

your project files over into GitHub. And

7:08:07

this is a perfectly fine way to get

7:08:08

started, but I'd like to take things one

7:08:10

step further with you today and show you

7:08:12

a real world way to manage your coding

7:08:14

projects. So imagine you made this

7:08:17

scoreboard solo project for a client or

7:08:19

an employer. The employer loves your

7:08:21

work but wants a change. They want the

7:08:24

headers to read home and away instead of

7:08:26

home and guest. So, we could make these

7:08:28

changes in a scrim and then download the

7:08:30

files again, copy them over to GitHub

7:08:33

again. But instead, let's learn a less

7:08:35

manual, more professional way by setting

7:08:38

up what's called a local development

7:08:40

environment. What's a local development

7:08:42

environment? Well, a simplified answer

7:08:45

for our purposes is that it's all the

7:08:47

tools that you use to do web development

7:08:50

on your local machine. And that's going

7:08:52

to include a text editor, which is a

7:08:54

tool to edit code on your computer, and

7:08:56

version control, a tool to keep changes

7:08:58

updated on GitHub. Now, don't be scared

7:09:01

by the term version control. It

7:09:03

basically just means keeping track of

7:09:05

the changes you make to your coding

7:09:06

projects. The tool that we're going to

7:09:08

use for version control is called GitHub

7:09:10

Desktop. GitHub Desktop is a tool made

7:09:13

by GitHub that offers a really nice

7:09:15

interface that allows you to connect and

7:09:17

sync a repository. So remember that a

7:09:20

repository is basically a folder

7:09:22

containing all the files and folders

7:09:23

that your project requires. So you'll

7:09:25

have a repo that lives on your computer

7:09:28

and a repo that lives on the internet

7:09:29

and GitHub Desktop helps you keep them

7:09:31

in sync. For a code editor, we're going

7:09:33

to install and use Visual Studio Code.

7:09:36

VS Code is super popular and widely used

7:09:39

and has a ton of features. In its most

7:09:42

basic form, it's not actually that much

7:09:44

different than coding in a scrim. In

7:09:46

fact, Scribba uses VS Code under the

7:09:48

hood, so it should look a little

7:09:49

familiar to you. Most of VS Code's

7:09:52

features are beyond the scope of what

7:09:53

we're trying to accomplish today, but we

7:09:55

will use it to open our code locally and

7:09:57

make some changes. Before we get

7:09:59

started, I'd like to quickly remind you

7:10:01

how to download your project files from

7:10:03

a scrim. So from the scrim where you've

7:10:05

completed the scoreboard project, click

7:10:08

on the gear and then click on download

7:10:10

as zip. That downloads the files to your

7:10:13

computer and we will do something with

7:10:14

these files shortly. Please join me in

7:10:16

the next scrim where I'll walk you

7:10:18

through how to create a local repo for

7:10:19

your project, connect it to GitHub

7:10:21

Desktop, and push it to GitHub. I'll see

7:10:23

you there.

7:10:26

Let's get started by downloading GitHub

7:10:28

Desktop. So you can click on this link

7:10:29

or on the image to go to

7:10:31

desktop.github.com.

7:10:33

And once you're there, we can click on

7:10:34

download. That will download a zip file

7:10:36

to your computer. And you can follow the

7:10:38

installation process and then sign into

7:10:41

GitHub desktop with your GitHub login.

7:10:43

And after you do that, your screen

7:10:45

should look something like this with

7:10:46

some options on the left and any

7:10:48

existing repositories that you might

7:10:50

have on GitHub on the right. After this

7:10:52

is all set up, here is your first

7:10:55

challenge. You will use GitHub Desktop

7:10:57

to create a new local repo. Unzip the

7:10:59

project files you downloaded earlier and

7:11:01

move those files into the new repo.

7:11:03

Here's a couple of hints. On the getting

7:11:05

started screen of GitHub Desktop, there

7:11:07

is a button called create new

7:11:09

repository. I highly suggest that you

7:11:11

use that. And your second hint is that

7:11:14

you can use all default options. So if

7:11:16

you're not sure what an option should

7:11:17

be, leave it how it is. Go ahead and

7:11:19

pause the scrim and give this a try and

7:11:22

I will be right back to walk you through

7:11:23

it.

7:11:28

All right, we're back. Hopefully, you

7:11:30

have a shiny new repository. And here we

7:11:32

go. I'm going to start by clicking on

7:11:34

the create a new repository on your hard

7:11:36

drive button. I can then give my

7:11:38

repository a name and a description, as

7:11:41

well as choose where I want to put this

7:11:43

repository on my computer. Now might be

7:11:45

a good time to create a special folder

7:11:47

where you'll keep all of your present

7:11:48

and future coding projects. So, I've

7:11:51

created a folder called projects, and

7:11:53

that's where I've saved my project zip

7:11:55

file. That's also where I'm going to

7:11:57

save my new repo by clicking open. And I

7:12:00

can go ahead and leave these options how

7:12:01

they are, and click create repository.

7:12:03

So, now I have a new repository called

7:12:06

scoreboard, but there are no uncommitted

7:12:08

changes because there's nothing in it. I

7:12:10

still need to move my project files into

7:12:12

the repo folder that I've just created.

7:12:14

So, GitHub Desktop, you'll find, is

7:12:16

super helpful. Here are some friendly

7:12:18

suggestions. it says for what to do

7:12:20

next. And we have this option that says

7:12:23

view the files of your repository in

7:12:25

Finder. So I'm going to click this show

7:12:27

and finder button. And that will take me

7:12:29

to the location on my computer where I

7:12:31

have stored my repo. So here I have my

7:12:34

repository and my project zip file. So I

7:12:37

will click on the zip file to unzip and

7:12:40

then copy and paste these files into my

7:12:42

scoreboard repo. So, when I return to

7:12:45

GitHub desktop, you'll see that it has

7:12:47

detected that I have added three files

7:12:50

to this repository. Before I can put

7:12:52

this repository up on GitHub, I'm going

7:12:55

to need to make what's called a commit.

7:12:57

Making a commit means that you're making

7:12:59

a record of the changes that you've made

7:13:01

to your project so that you or future

7:13:03

devs you're collaborating with will know

7:13:05

what you've done. So, as you can see in

7:13:07

green are the changes that I've added.

7:13:09

And if I were to delete anything, and

7:13:11

we'll see this later, that will show up

7:13:13

in red. To commit these files, I will

7:13:15

need to write a commit message. And that

7:13:17

is just a brief summary of the changes

7:13:20

that I'm including in my commit. Once

7:13:22

I've written my commit message, I can

7:13:24

click on commit to main. Now, if you

7:13:26

don't understand what main refers to,

7:13:28

don't worry about it. It's something

7:13:29

called a branch, and you'll learn more

7:13:31

about it later. So, I'm going to click

7:13:33

on this. And now that we've committed

7:13:35

our changes, we are ready to publish to

7:13:38

GitHub. As you can see, GitHub Desktop

7:13:40

has very helpfully highlighted this

7:13:42

option that says, "This repository is

7:13:45

currently only available on your local

7:13:47

machine. By publishing it to GitHub, you

7:13:49

can share it and collaborate with

7:13:50

others." So, that's exactly what we want

7:13:52

to do. Let's click on publish

7:13:54

repository. This will pop up a window

7:13:56

where I can give my remote repository,

7:13:59

meaning the repository that's up on

7:14:01

GitHub, a name and a description. So,

7:14:03

I'll go ahead and write those to match

7:14:05

my local repository. And then I

7:14:07

willclick this box that says keep this

7:14:10

code private because we don't want to

7:14:11

keep it private. We want to share it

7:14:13

with everybody. Then I can go ahead and

7:14:16

click publish repository. So now we've

7:14:18

created a repo for our project and we

7:14:20

have published that repo to GitHub. We

7:14:23

now have the option to view on GitHub.

7:14:25

So let's take a look. We now have this

7:14:27

lovely new repo up on GitHub and GitHub

7:14:30

Desktop is set up to track any changes

7:14:32

we make locally so that we can easily

7:14:34

update this repo with those changes. So

7:14:37

in the next scrim, we'll use Visual

7:14:39

Studio Code to edit project files and

7:14:41

put those changes on GitHub. I will see

7:14:44

you there.

7:14:47

Let's begin by downloading and

7:14:49

installing Visual Studio Code. You can

7:14:51

click on the link or the image to go to

7:14:53

code.visisualstudio.com.

7:14:55

Click on the arrow and choose the stable

7:14:57

version for your operating system. And

7:15:00

that will download the files and take

7:15:01

you to this getting started page where

7:15:03

you can read or watch some introductory

7:15:06

videos if that's what you would like to

7:15:07

do. So going back to the scenario that

7:15:10

we discussed earlier, I have another

7:15:12

challenge for you. Let's imagine that a

7:15:13

client or an employer would love to use

7:15:15

your scoreboard project, but instead of

7:15:17

the headers reading home and guest, they

7:15:19

want the headers to read home and away.

7:15:21

Keeping that in mind, here's what I'd

7:15:23

like you to do. Open your project in VS

7:15:25

Code. Change the guest header so that it

7:15:27

reads away instead. And then in GitHub

7:15:30

Desktop, write a commit message and

7:15:32

commit and publish your change to

7:15:33

GitHub. Again, I have a couple of hints.

7:15:35

GitHub Desktop provides another helpful

7:15:37

button to open your project in VS Code.

7:15:39

So, strongly suggest that you start

7:15:41

there. And your second hint is don't

7:15:43

forget to save your changes in VS Code.

7:15:45

This is something that I forget to do

7:15:47

all the time and then I waste a lot of

7:15:49

time trying to figure out what's going

7:15:50

on. So, don't be like me. Remember to

7:15:52

save your changes. Okay, go ahead and

7:15:55

pause this scrim and give this a try.

7:15:57

And I will be right back to walk you

7:15:59

through it.

7:16:03

Okay, we're back. Hopefully that went

7:16:05

well, but if you found this confusing,

7:16:07

please don't worry about it. Especially

7:16:08

if you haven't had a lot of experience

7:16:10

with GitHub or GitHub desktop or version

7:16:12

control. This is a lot of new stuff and

7:16:14

a lot of new terminology to wrap your

7:16:16

brain around. And it's also not super

7:16:18

important to understand all of this

7:16:21

conceptually quite yet. It's totally

7:16:23

okay this early in the game to see this

7:16:25

process as just a series of steps to

7:16:27

accomplish a task. So again, try not to

7:16:29

worry about it. You'll learn much more

7:16:31

later. So I'm going to go to GitHub

7:16:33

desktop and click on open in Visual

7:16:35

Studio Code. The first time that you

7:16:36

open files in Visual Studio Code, it

7:16:38

might ask you if you trust the authors.

7:16:40

I'm going to say yes, I trust the

7:16:41

authors. And then I can go to my

7:16:43

index.html file and make that change.

7:16:46

Now remembering to save, I will return

7:16:48

to GitHub desktop. And you can see that

7:16:50

it has automatically detected the change

7:16:52

that I made. You can see that the line

7:16:53

we deleted is recorded in red and the

7:16:56

line that we added is recorded in green.

7:16:58

Before I can publish this change to

7:17:00

GitHub, I will need to make a commit. So

7:17:02

I'm going to come down here and write a

7:17:03

nice descriptive message explaining the

7:17:06

change that we've made. So we've updated

7:17:08

the score header and now I can commit to

7:17:10

main. GitHub Desktop has very helpfully

7:17:13

highlighted our next step. It says you

7:17:15

have one local commit waiting to be

7:17:17

pushed to GitHub. So you may be

7:17:18

wondering what push origin means and

7:17:20

what the difference is between a commit

7:17:22

and a push. So while GitHub desktop will

7:17:25

automatically detect when you make a

7:17:27

change to a repo, in order to push it to

7:17:29

GitHub, you must say to GitHub, please

7:17:31

make an official record of these

7:17:33

changes. And the record of these changes

7:17:35

is called a commit. Push essentially

7:17:37

means publish the commits I've made to

7:17:40

GitHub. And don't worry too much about

7:17:41

what origin means. It's basically

7:17:43

another word for your remote repo. So I

7:17:45

will go ahead and push origin. And now

7:17:48

we have no local changes. There's

7:17:50

nothing left to do. We have pushed our

7:17:52

commit up to GitHub. And I would like to

7:17:54

quickly point out that if you click on

7:17:55

the history tab here, you can see a

7:17:57

record of all of the commits that I've

7:17:59

made so far. Now going back to the

7:18:01

changes tab, I can click on view on

7:18:03

GitHub. And if I click on our index.html

7:18:06

file, you see those changes are

7:18:08

reflected in our remote repo on GitHub.

7:18:11

So, awesome work today. You've learned a

7:18:13

ton about setting up a local environment

7:18:15

to manage your coding projects outside

7:18:17

of a scrim on your computer. There's

7:18:19

much more to learn about version control

7:18:20

and GitHub, and that will come later.

7:18:22

But for now, I'd encourage you to

7:18:24

celebrate your newfound knowledge by

7:18:25

posting a link to your scoreboard repo

7:18:28

in the I built this channel of the

7:18:29

Scribba Discord. I'll see you later, and

7:18:31

happy coding.

7:18:35

We've used GitHub Desktop to push our

7:18:37

project to GitHub. Now let's use Netlefi

7:18:39

to deploy our project to the web. Once

7:18:41

you log into Netlefi from your Netlefi

7:18:43

dashboard, you can click on add new site

7:18:46

and then import an existing project. Now

7:18:49

this might look a little familiar. We're

7:18:50

going to connect a Git provider and the

7:18:52

Git provider we're using is GitHub. Then

7:18:55

I will search for my repo and click on

7:18:58

it. And we come to a site setting page.

7:19:00

We can leave everything as it is. Scroll

7:19:02

down and click deploy site. Now Netlefi

7:19:05

will begin to deploy our project. And

7:19:07

once it's done, we can click on the link

7:19:09

and view our project up on the web. Now,

7:19:12

mine is not very pretty because I'm just

7:19:14

using example files. Yours should look a

7:19:17

lot better. Now, let me show you how

7:19:18

Netlefi will actually automatically

7:19:20

deploy whenever you commit a change to

7:19:22

your remote GitHub repo. I'm going to go

7:19:24

back to GitHub Desktop and open my

7:19:26

project in VS Code. And then I will go

7:19:29

into my index.html and change these

7:19:31

headers again to something else.

7:19:33

Returning to GitHub desktop, I can write

7:19:35

a descriptive commit message. Commit to

7:19:38

main. And once I have pushed that up to

7:19:41

GitHub, I can return to my Netlefi

7:19:43

dashboard, click on my project and its

7:19:45

link to see that it has changed. Pretty

7:19:48

awesome. Now that you've built and

7:19:50

deployed your project, I really

7:19:51

recommend that you share it. If you look

7:19:53

up in the header here, you will see a

7:19:55

share solution button. All you have to

7:19:57

do is click it to go to Twitter where

7:20:00

we've already created the message for

7:20:01

you. Just don't forget to copy and paste

7:20:03

your Netlefi URL here. Great work today.

7:20:06

Happy coding and I'll see you next time.

7:20:11

Hey, and welcome to building blackjack.

7:20:14

I'm so excited about this one because

7:20:16

you are going to learn JavaScript while

7:20:18

building one of the most iconic casino

7:20:20

games ever. Here is a sneak peek of the

7:20:23

app we are going to build. And while

7:20:24

it's not a full-blown blackjack app, of

7:20:27

course, it does share a lot of the

7:20:28

functionalities with blackjack apps you

7:20:30

can play on online casinos. Speaking of

7:20:33

that, that is actually a huge market.

7:20:35

People spend over $20 billion per year

7:20:38

gambling on online casinos. And

7:20:40

personally, I love playing poker and

7:20:42

blackjack. I think my life actually

7:20:45

peaked when I won €100 on a casino in

7:20:47

Prague in 2016. That made me feel like

7:20:50

such a gangster. I spent the rest of the

7:20:52

weekend squatting in front of fast cars

7:20:54

like this Mercedes, this Hummer, this

7:20:57

BMW, and this Bentley. So, my goal with

7:21:00

this section, of course, is to make you

7:21:02

feel as cool as I did in 2016.

7:21:06

And with that out of the way, let's just

7:21:08

get started.

7:21:13

Okay, so we're going to kick this off

7:21:14

with a challenge. You are going to

7:21:16

create two variables, the first card and

7:21:18

the second card. Then you're going to

7:21:20

set their values to a random number

7:21:22

between 2 and 11 as that's the values

7:21:24

you can draw from the deck of cards in

7:21:27

blackjack. Secondly, you are going to

7:21:28

create a variable sum and set it to the

7:21:31

sum of the two cards. So go ahead and do

7:21:34

this right now.

7:21:40

Okay, let's do this. Start with the

7:21:43

first card. I'm going to set it to six.

7:21:46

And the second card up to nine. Then the

7:21:49

sum of course equals first card plus

7:21:54

second card like that. Let control log

7:21:57

out the sum. Run the code and yes indeed

7:22:00

we get 15. Great job. Let's move on.

7:22:07

Okay. So we are ready to build the logic

7:22:09

of our blackjack game. Now let's have a

7:22:11

look at how blackjack works before we

7:22:13

try to formulate this in JavaScript. So,

7:22:16

the point with blackjack is to get a

7:22:18

hand that sums up to exactly 21. And if

7:22:21

you don't get 21, at least you want to

7:22:22

get as close to 21 as possible, but

7:22:25

never above 21 because if so, you're out

7:22:28

of the game. So, here are three

7:22:30

scenarios. One where you have two cards

7:22:32

on your hand, that's your starting hand,

7:22:33

and they amount to 15. So, you're still

7:22:36

in the game. No big reason to either cry

7:22:38

or celebrate. Then, there's the other

7:22:39

case where you have a king and an ace.

7:22:42

And since the ace here equals 11 and the

7:22:45

king equals 10, you've got blackjack.

7:22:48

So, woohoo. And the third scenario, you

7:22:50

started out with a 10 and a six and then

7:22:52

you ask for a new card, but damn, you

7:22:55

ended up at 22. So, you're over 21 and

7:22:57

sadly you've lost your money. So, now

7:23:00

the question is, how do we translate

7:23:02

these things into JavaScript? Sadly,

7:23:05

JavaScript isn't as smart as you are who

7:23:07

can understand this by just hearing me

7:23:09

talk about it. JavaScript is kind of

7:23:10

stupid and it needs you to describe the

7:23:12

logic 100% correct. So let's just do

7:23:16

that so you get to see it in action. We

7:23:18

start out with writing if and then open

7:23:21

and close parenthesis and then it's the

7:23:24

sum of our cards that we are going to

7:23:25

check. So we say if sum is less than 21

7:23:30

just like we were doing here. So this

7:23:32

crocodile mouth is something you might

7:23:34

recognize from your maths class at

7:23:36

school. And it kind of makes sense

7:23:37

because here on the right hand side you

7:23:38

can see that's where the gap between the

7:23:40

teeth of the alligator is the largest

7:23:42

whereas at the left hand side here the

7:23:44

gap between the teeth is the smallest.

7:23:46

So small value here large value here. If

7:23:50

this condition is true meaning that sum

7:23:52

is less than 21. Well then we add two

7:23:55

curly brackets and tell JavaScript that

7:23:57

we want to execute the piece of code

7:23:59

inside of those curly brackets. So we'll

7:24:01

do control log. Do you want to draw a

7:24:06

new

7:24:07

card? Since that's what you can do in

7:24:10

this scenario. You are still in the game

7:24:12

and you can draw another card if you

7:24:13

want to. But there are cases where this

7:24:15

isn't true and we need to account for

7:24:17

those as well. We do that by writing

7:24:20

else if and open and close parenthesis.

7:24:22

And here we write sum equal equal equal

7:24:27

21. This is else if sum equals 21 then

7:24:33

we want this code to be executed. And

7:24:36

this triple equal operator is different

7:24:39

from this one right here. Here we are

7:24:41

saying that we want the sum to become

7:24:43

first card plus second card. But here

7:24:45

we're asking is the sum strictly equal

7:24:48

to 21. And you say strictly equal when

7:24:50

you see three equal marks. And don't

7:24:52

worry about why it's three and not

7:24:54

necessarily two. We're going to get back

7:24:57

to that later. For now on just use three

7:24:59

equal marks when you write else if

7:25:01

statements where you are checking if a

7:25:02

variable is exactly some kind of value.

7:25:05

So if the sum is 21 what is the case

7:25:07

then? Well woohoo the player has

7:25:10

blackjack. So we'll do slog.

7:25:14

Woohoo you've got blackjack like that.

7:25:19

And then the third scenario we'll do

7:25:22

else if yet again sum. And what do you

7:25:25

think we'll use here? Of course, we'll

7:25:27

use this one right here because if the

7:25:29

sum is larger than 21, then the user has

7:25:31

lost. Sum is greater than 21. Open and

7:25:35

closed curly brackets console log.

7:25:38

You're out of the game. Like that.

7:25:43

Actually, let's add these emojis as

7:25:46

well. There we go. Now, one little thing

7:25:48

I want you to notice here is that here I

7:25:51

have to use double quotes to wrap this

7:25:54

as I'm using single quotes to create

7:25:56

this you've and your words. Cuz if I was

7:26:00

using single quotes here, it would be

7:26:03

completely off because JavaScript would

7:26:05

have thought that I was intending to

7:26:07

close off this string right here when

7:26:09

I'm not intending that. I was just

7:26:10

writing you've instead of you have. So,

7:26:13

just a little digression there. Now

7:26:15

let's run this code and see how it

7:26:17

works. We'll hit run and yes, do you

7:26:19

want to draw a new card? We triggered

7:26:21

this which seems correct since 9 + 6 is

7:26:24

15 and that is indeed less than 21.

7:26:26

Let's try to do 10 and 11. So this is

7:26:30

black deck. Yes, JavaScript triggered

7:26:34

line 8, which is what we wanted. And

7:26:36

finally, let's say that we got 17 on the

7:26:40

first two cards and we really wanted a

7:26:41

new card. If we wanted to take the

7:26:42

chant, got to be bummed out by getting

7:26:44

six. If so, our sum would be 23. And

7:26:48

what do you think will happen? Yes, this

7:26:50

line of code should be run. I'm going to

7:26:52

run the code. And boom, you're out of

7:26:54

the game. Now, a final thing I want to

7:26:56

tell you about before we move on is that

7:26:58

could actually skip all of this code if

7:27:01

we wanted to and do like that. Because

7:27:03

if sum is not less than 21 and it's not

7:27:07

exactly 21 either meaning we've jumped

7:27:10

to the third clause in our if else

7:27:12

clause then it must be over 21. I mean

7:27:15

there's no other alternative in the

7:27:18

entire universe. So there's no point

7:27:20

specifying that sum here should be over

7:27:24

21 for this block of code to be

7:27:26

executed. meaning we can just skip it.

7:27:29

So that we have if sum is less than 21

7:27:31

execute this. If sum is exactly 21

7:27:34

execute that and in all other cases

7:27:37

execute this. This will work as you see

7:27:40

by running the code in the exact same

7:27:42

way. Okay. Now that you know that let's

7:27:45

move on.

7:27:50

Now it is your turn to write an if else

7:27:52

statement. You are to check if a person

7:27:55

is old enough to enter the nightclub

7:27:57

which has a lower age limit at 21. And

7:28:00

then you are to log a suitable message

7:28:02

to the console in both cases. And by

7:28:04

that I mean if the user is less than 21

7:28:07

or if the user is 21 or older. So I've

7:28:10

defined the age variable here. And also

7:28:12

written pseudo code if less than 21 then

7:28:15

a suitable message would be for example

7:28:17

you cannot enter the club. else meaning

7:28:20

all other cases because if they're not

7:28:22

less than 21, well, they have to be 21

7:28:24

or above, then you are to log something

7:28:26

like welcome. Go ahead and give this a

7:28:28

shot. And if you have forgotten how to

7:28:30

write an if else statement, just go back

7:28:32

and rewatch the previous lesson. And

7:28:34

notice here that I don't have an else if

7:28:37

statement in between here. I only have

7:28:39

the first if and the final else, not the

7:28:43

else if which we had in the previous

7:28:45

lesson. And that is because I want you

7:28:47

to think for yourself and try to figure

7:28:49

out well how do you write this with only

7:28:51

an if and an else and not the if else in

7:28:54

between. Just give it a shot and I will

7:28:56

show you the solution as well when you

7:28:58

return back to this screencast.

7:29:05

Okay, hopefully that went well. Let's do

7:29:08

this. If less than 21, we have to do age

7:29:11

is less. Remember this alligator mouth

7:29:14

hair and 21 like that. This means the

7:29:19

person is maximum 20 years old.

7:29:22

Then we are to do following while

7:29:25

console.log

7:29:29

you cannot enter the club. And then we

7:29:32

simply do else and then the open and

7:29:36

close curly brackets. And here we can

7:29:38

console log welcome.

7:29:42

Running the code we get welcome. That's

7:29:44

correct. Trying to lower the age to 20.

7:29:47

We get you cannot enter the club. Now a

7:29:50

final thing I want to point out is that

7:29:52

you could also solve this by using

7:29:54

another comparison operator which is the

7:29:57

less than or equal to. That means a

7:30:00

slightly different thing though because

7:30:01

it checks that this value is less than

7:30:05

or equal to 21. So if we take this back

7:30:09

to 21 and run it, you can see we get you

7:30:12

cannot enter the club which obviously is

7:30:15

wrong. They should be able to enter the

7:30:16

club at this point. So if we're using

7:30:18

the smaller than or equal to operator,

7:30:21

we have to use 20 because then we

7:30:23

include 20. That is an upper range that

7:30:26

is inclusive of that number.

7:30:29

So now it works. Whether you prefer

7:30:32

using less than or equal to or just the

7:30:35

less than is up to you. You just need to

7:30:37

keep in mind how that changes the entire

7:30:39

expression. With that, let's move on.

7:30:44

Let's practice if else statements a bit

7:30:46

more. Because in Norway, we have this

7:30:48

super cool tradition where when you

7:30:51

reach 100 years old, you get a personal

7:30:53

birthday card from the king. This is the

7:30:56

king, King Harold V of Norway. And in

7:30:58

this challenge, we are going to code the

7:31:00

logic for this. So here it is in pseudo

7:31:03

code. If less than 100, and here I'm

7:31:07

talking about the age variable, of

7:31:09

course, then you are to log something

7:31:11

like not allegible to the console. Else

7:31:14

if the age variable is exactly 100, you

7:31:17

are to log something like here is your

7:31:18

birthday card from the king. And else,

7:31:20

in all other cases, meaning they're over

7:31:23

100 years old, you get not allegible.

7:31:25

You have already gotten one. because if

7:31:27

they're 105 years old, they got their

7:31:29

birthday card from the king 5 years ago.

7:31:32

Okay, go ahead and give this one a shot

7:31:34

and then I will show you the solution

7:31:35

afterwards as well.

7:31:41

Okay, let's do this. If age is less than

7:31:46

100,

7:31:48

we'll console log not legible and then

7:31:53

we have to do the else if and specify

7:31:55

the condition age is exactly 100. Then

7:32:00

we console log here is your birthday

7:32:02

card from the king. And else in all

7:32:05

other cases the person is over 100 years

7:32:08

old. They have already gotten their card

7:32:12

previous so not allegible. Let's run the

7:32:16

code. Yes, 100 you are getting the card.

7:32:19

At 45

7:32:21

you are not legible. At 145 you are not

7:32:26

allegible either. Finally, before you

7:32:29

leave, let's take a closer look at this

7:32:31

triple equals here because it might seem

7:32:33

like a little bit of an overkill to have

7:32:35

three equal signs after each other. And

7:32:38

that is a valid point. You could use

7:32:40

two. If we run the code, it still works

7:32:43

with 145. And actually with 100 as well,

7:32:46

it would still work. You are getting

7:32:48

your birthday card. However, the thing

7:32:50

with two equals, so-called double

7:32:52

equals, is that it's a little less

7:32:54

strict. So let's say that you by mistake

7:32:57

passed in a string here as well, which

7:33:00

has the same value of 100, but it's a

7:33:02

string and not a number. If we run the

7:33:04

code, you can see it still works.

7:33:06

However, with the triple equals running

7:33:09

the code, then it doesn't work. Now, it

7:33:11

says not alleible even though 100 is

7:33:13

here as a number and 100 is here as a

7:33:16

string. So, double equals ignores the

7:33:19

fact that this is a string and this is a

7:33:22

number. Basically converts this into a

7:33:25

number if it's a number on the left hand

7:33:27

side as well. So that this entire thing

7:33:29

would be true. However, that's not what

7:33:32

we want. We actually want to be strict

7:33:34

in our code, which is why I would

7:33:36

recommend you to only use triple equals.

7:33:39

Ignore double equals. This forces you as

7:33:42

a developer to be a bit more mindful

7:33:43

about how you are checking your

7:33:45

conditionals. You need to make sure that

7:33:47

if you're starting out with a number up

7:33:49

here, you're also comparing it with a

7:33:51

number down in the conditional. But

7:33:52

that's just good practice being

7:33:54

thoughtful as to what kind of data types

7:33:57

you are using in your code. just stick

7:34:00

with triple equals and you'll be just

7:34:02

fine. With that, let's move on.

7:34:09

Okay, so now we're back at our blackjack

7:34:10

game. And you might have noticed that

7:34:12

we've lost the code that we previously

7:34:14

had. Well, that's the point of Scribba.

7:34:16

You are going to write the code, not me.

7:34:18

So, I want you to rewrite the

7:34:20

conditional that I created previously,

7:34:23

but with a slightly different take. You

7:34:25

have to follow the logic that I lay out

7:34:27

in the pseudo code here. So you have to

7:34:30

use in the first if clause the less than

7:34:33

or equal to operator. So you have to set

7:34:35

it to less than or equal to 20. And then

7:34:38

in the else if clause you can use the

7:34:40

strictly equal to check if the sum is

7:34:42

exactly 21. And finally you're going to

7:34:44

use the else clause and not an else if

7:34:47

on the third conditional which I did

7:34:49

previously. So go ahead and do this. And

7:34:51

if you can't do it or want to see my

7:34:53

solution, just return back to this

7:34:55

screencast and I will show you how to do

7:34:56

it as well. Good luck.

7:35:03

Okay, let's do this. First, there's the

7:35:07

if sum is less than or equal to 20, then

7:35:12

we are console logging out this string

7:35:16

right here. And then we do else if the

7:35:20

same as we did last time. sum triple

7:35:22

equals 21.

7:35:24

That's the blackjack case. And here I'm

7:35:27

lazy. So I'll just copy paste this one

7:35:30

and then this one in here. And then

7:35:33

finally not doing else if and checking

7:35:36

for the condition but just doing the

7:35:38

else. So all other cases and then

7:35:41

pasting in this you are out of the game

7:35:44

string like that. Good stuff. Let's run

7:35:47

the code. And yes, we have 17 here. And

7:35:50

we rightfully so logged out. Do you want

7:35:53

to draw a new card? Good stuff. If we

7:35:56

try to hit one more time with another

7:35:58

10, we are out of the game. Good stuff.

7:36:02

And how about a four? Blackjack. Woohoo.

7:36:05

Great job. Let's move on.

7:36:09

You've already worked with some

7:36:11

different types of data in JavaScript.

7:36:13

You've seen numbers and you've seen

7:36:15

strings. Now, I want to add one more

7:36:18

data type to this list because often we

7:36:21

don't really need the almost infinite

7:36:23

possibilities of numbers and strings of

7:36:25

letters. We actually just need two

7:36:27

options like a light switch on or off,

7:36:30

yes or no, true or false. And that

7:36:33

brings us to the boolean. The boolean is

7:36:37

a value that can be either true or

7:36:39

false. Let's see one in action. Imagine

7:36:42

we're developing a site for an online

7:36:44

food retailer. We've collected some

7:36:45

information about our customers eating

7:36:47

habits so we know what food items to

7:36:49

show them. Oftent times when storing a

7:36:52

boolean, we will choose a name with a

7:36:54

verb. So let's come in here. I'm going

7:36:56

to delete all of this and I'm going to

7:36:58

set up a let with the name is vegan.

7:37:02

And I'm going to set that to true. So

7:37:04

the verb here is makes this read like a

7:37:08

question. Is the customer vegan? Yes,

7:37:11

that's true. And of course it could also

7:37:12

be false. Let's just log that out

7:37:15

quickly. And when we save down in the

7:37:18

console, we get false. Let's change this

7:37:20

to true. Okay, so that's working as

7:37:23

expected. And having a boolean that you

7:37:24

can flip to true or false is really,

7:37:26

really useful. And you're going to see

7:37:28

it a lot. Let's just dig a little bit

7:37:31

deeper. Our site could also allow users

7:37:33

to use a special code to get a discount

7:37:35

for their food order. Let's set up a

7:37:37

boolean to see if they've got a discount

7:37:39

code or not. And here the verb could be

7:37:42

has.

7:37:44

So the question here is, has the user

7:37:46

got a discount code? And at the moment,

7:37:48

the answer is yes. That is set to true.

7:37:50

Now, let's start to see the real power

7:37:52

of a boolean by using this in a

7:37:54

function. And I'm just going to delete

7:37:56

our earlier example. And I'm going to

7:37:58

set up a function here called process

7:38:00

order.

7:38:02

In the body of the function, let's use

7:38:04

an if to check if the user has a

7:38:06

discount code. And if they do, let's

7:38:09

just log out that the discount has been

7:38:10

applied.

7:38:13

Okay, now if I call this function and we

7:38:15

hit save down in the console, we get

7:38:18

discount applied to food order. So this

7:38:21

is working because the if is checking if

7:38:23

this is true and we know that it is

7:38:26

true. We've got it set to true right

7:38:27

here. If we set this to false, we hit

7:38:30

save and nothing happens. This code does

7:38:33

not run. And we can see that a little

7:38:35

bit better if we add an else. So if this

7:38:38

is false, this code doesn't run. This

7:38:40

code will run. Let's just log out. No

7:38:43

discount applied

7:38:45

again. We'll save. Oh, and I've

7:38:47

misspelled console. There we are. No

7:38:49

discount applied. Okay. Now, let's do

7:38:52

something a little bit more ingenious.

7:38:53

So, if this is set to true, then we

7:38:56

process an order. The discount is

7:38:58

applied. Now, the discount code has been

7:39:00

used. So, we should set this boolean to

7:39:03

false. Now, I'm going to call this

7:39:05

function not once but twice. Let's see

7:39:07

what happens. Okay. So the first time we

7:39:10

call the function we get discount

7:39:11

applied to food order. So what's

7:39:13

happening there is that has discount

7:39:15

code is true. The process order function

7:39:18

checks that it finds it's true. So it

7:39:20

logs out discount applied to food order.

7:39:23

Then it flips that boolean to false. The

7:39:26

second time we run process order has

7:39:28

discount code is false. So this code

7:39:31

here does not run but this code does

7:39:33

run. So we log out. No discount applied.

7:39:37

So the boolean is working like a kind of

7:39:39

gate. It's letting you through when it's

7:39:40

true and not when it's false. It's a

7:39:43

really really useful data type and I

7:39:45

think you're going to see it again very

7:39:47

very soon. Now just to clarify, it might

7:39:49

be a little bit strange that all we need

7:39:51

to do is put the variable has discount

7:39:53

code in here. You might have expected

7:39:56

that we need to ask if has discount code

7:39:58

is triple equals to true. But actually

7:40:03

that is not necessary in JavaScript. The

7:40:06

if statement evaluates the expression

7:40:08

inside these parentheses, i.e. all of

7:40:10

this code right here, and coerces it to

7:40:13

a boolean value. What does that mean? It

7:40:16

means it converts it to a boolean value,

7:40:18

true or false. It does this part for you

7:40:21

under the hood. And that is why this

7:40:23

works. So, actually, all we need in here

7:40:26

is the variable. And if we were to come

7:40:28

in here and replace it with something

7:40:30

like an empty string, well, in

7:40:33

JavaScript, an empty string is a falsy

7:40:35

value. And that means that the if

7:40:37

statement will coersse this to false.

7:40:40

And this code right here will never run.

7:40:43

Let's hit save. And we see no discount

7:40:46

has been applied twice. So this code

7:40:48

never ran. So just remember that

7:40:50

JavaScript is going to do that part for

7:40:52

you. It's going to take has discount

7:40:54

code and it's going to evaluate it to

7:40:57

true or false without you needing to do

7:41:00

anything else. Okay, hopefully that has

7:41:02

tidied up any confusion. Now, let's get

7:41:05

back to the project where you're going

7:41:06

to see a few more booleans and get a

7:41:08

chance to practice with them.

7:41:12

Okay, so our game is coming along really

7:41:14

nicely here. However, there's a big

7:41:17

problem and that is let's say that you

7:41:18

are playing this game and you get

7:41:20

blackjack. So you get a 10 and an ace

7:41:23

and boom, you've got blackjack. Down

7:41:26

here at line 13, you of course want to

7:41:28

cash out your money. Going to get the

7:41:29

pot on the table. However, at this point

7:41:31

down on line 13, JavaScript has no way

7:41:34

of knowing which console log it logged

7:41:37

out. It doesn't remember that. So what

7:41:39

we need to do then is introduce a new

7:41:41

variable that keeps track of this state.

7:41:44

You can call it the state of the game.

7:41:46

like has the user gotten blackjack or

7:41:48

maybe has the user lost or whatever it

7:41:50

is. So what we then want to do is for

7:41:53

this scenario have a variable that

7:41:56

reflects whether or not the player has

7:41:57

blackjack. And when I say whether or not

7:42:01

yes or no is there a data type in

7:42:03

JavaScript that you think might be

7:42:05

suitable for describing such a state. If

7:42:07

you guessed a boolean a true or false

7:42:10

that is correct. So what we'll do is

7:42:12

we'll do let has blackjack like that and

7:42:17

set that initial value of course to

7:42:18

false because by default you don't have

7:42:20

blackjack.

7:42:22

And then here inside of the else if

7:42:25

clause that describes the blackjack

7:42:28

case, we're simply going to reassign the

7:42:31

has blackjack value to true instead.

7:42:35

Now down at line 16, if we log this out,

7:42:40

he has blackjack value and then run this

7:42:43

code. Boom. You can see that we're both

7:42:46

logging out on line 9 and we have

7:42:49

persisted the state so that line 16, for

7:42:51

example, can start writing the code for

7:42:53

taking the cash that's on the table that

7:42:55

now is rightfully yours and then deposit

7:42:57

it into your account. So now we have an

7:42:59

app that keeps track of the data of the

7:43:01

state in a much more sensible way. Now,

7:43:04

I want you, of course, to write this

7:43:06

kind of logic yourself. So, in the next

7:43:08

cast, I'm going to give you another

7:43:10

challenge so that we can keep track of

7:43:12

even more of the state of this game.

7:43:14

I'll see you there.

7:43:19

Okay, so now it's your turn and you are

7:43:20

going to make the state of our game a

7:43:22

little bit more robust because at this

7:43:25

point, we're only tracking if the player

7:43:27

actually gets blackjack. If the player

7:43:29

busts out and gets 22 or more, we're not

7:43:32

tracking it. And obviously we have to do

7:43:34

that. So I want you to create a variable

7:43:36

called is alive and start by assigning

7:43:39

it to true. And then you're going to

7:43:40

flip that value to false inside of the

7:43:43

appropriate code block. So there's three

7:43:46

code blocks, the if block, the else if

7:43:50

block, and the else block. And you of

7:43:52

course then have to pick the correct

7:43:54

code block and then write that line of

7:43:56

code that flips the value to false. And

7:43:58

finally log it out to check that you're

7:44:00

doing everything correctly. So good

7:44:01

luck. go ahead and do this and then I

7:44:03

will show you the solution afterwards as

7:44:05

well.

7:44:10

Okay, let's do this. Starting up here,

7:44:13

we're going to create a let variable

7:44:14

called is alive and assign that to true

7:44:18

because when you're starting out, the

7:44:19

player is still alive. And at which

7:44:21

point is the player no longer alive,

7:44:23

meaning out of the game. Well, that's

7:44:26

obviously here in the else block because

7:44:27

that's the case if the sum is 22 or

7:44:30

more. So here we'll do is alive equals

7:44:33

false. And then finally we'll console

7:44:36

log is alive like that. We got true

7:44:40

because actually we had blackjack and

7:44:42

rightfully so the player is not dead.

7:44:45

How about if we pretend that we add a

7:44:47

third card here. It's really stupid

7:44:49

idea. Pick a third card after you've

7:44:52

gotten blackjack. But let's just pretend

7:44:53

that. We'll run the code and boom.

7:44:56

False. No longer alive. Great job

7:44:58

solving this challenge. Let's keep up

7:45:00

the pace and move on.

7:45:05

Now that you've learned about booleans,

7:45:07

let's take a look back at the

7:45:09

conditional you wrote. Because one thing

7:45:11

you probably didn't think too much about

7:45:14

when you wrote your conditionals is that

7:45:16

the expressions inside of the

7:45:18

parenthesis would be translated by

7:45:21

JavaScript eventually into a boolean. So

7:45:24

it would be either true

7:45:28

or false. That's always the case with

7:45:30

expressions passed into conditionals

7:45:33

because here we are comparing two

7:45:36

numbers and one of them are either

7:45:37

larger than the other or they are two

7:45:39

equal numbers. So the claim you come

7:45:42

with has to be either true or false.

7:45:45

Let's try to play this out using an

7:45:47

example. For example, when you've gotten

7:45:48

two cards, a 10 and an 11, meaning you

7:45:51

have blackjack. In that case, sum will

7:45:54

be 21. And the claim you come with

7:45:56

inside of the first if statement,

7:45:58

obviously that is a lie. Meaning it gets

7:46:02

evaluated to false. In the second

7:46:05

condition though, you're saying that sum

7:46:07

is equal to 21. And we know we are going

7:46:09

to translate sum into 21 because that's

7:46:13

what it is. So here you're saying 21

7:46:16

triple equals 21. Well, yes, that is a

7:46:20

true statement. So that becomes the true

7:46:22

boolean. And here you can read through

7:46:25

it. If false, well then we're going to

7:46:27

skip the body of this statement. Else if

7:46:30

true. Yes, we like true. Then we are

7:46:32

going to execute that piece of code. So

7:46:34

this is essentially what happens when

7:46:37

you run the code with specific values

7:46:39

for these variables.

7:46:42

Rewinding it back. What I want to do now

7:46:45

is stress test your comparison and

7:46:48

boolean skills. So, I'm going to paste

7:46:51

in a bunch of control logs here and then

7:46:54

comment out our black game. Now, your

7:46:58

job is to look at each of these

7:47:00

expressions and predict whether true or

7:47:03

false is logged to the console. So,

7:47:06

write either true or false after these

7:47:08

two slashes on each of the lines from 1

7:47:11

to 7. And then, of course, when you've

7:47:13

given it a shot, run the code and see

7:47:14

how it went. And then, I will do the

7:47:16

same thing afterwards as well. Go ahead

7:47:18

and do this right now.

7:47:25

Okay, let's do this. First, four triple

7:47:29

equals 3. Obviously, that's wrong. It's

7:47:32

going to log out false. 5 is greater

7:47:35

than 2. That is true.

7:47:39

And 12 is greater than 12. No, 12 is not

7:47:42

greater than 12. It's exactly the same.

7:47:44

So, this will be a false statement.

7:47:47

3 is less than zero. Again, that's also

7:47:50

false.

7:47:52

3 is larger than or equal to 3. Yes,

7:47:56

that would be a true statement because

7:47:58

it's not larger than, but it is equal

7:48:01

to. So, true.

7:48:04

11 is less or equal to 11. Again, it's

7:48:08

not less than 11, but it is equal to 11.

7:48:11

So, it's true. And 3 is less or equal to

7:48:15

2. No, three is actually larger than

7:48:17

two, meaning that this is going to be

7:48:18

false. So, this is my prediction. Let's

7:48:22

run the code. Bring up the console. And

7:48:25

yes, phew, I was right. Very good. Let's

7:48:29

move on.

7:48:33

Welcome back, my friend. I hope you are

7:48:35

ready for a new challenge because that

7:48:37

is exactly what I have in store for you

7:48:39

now. Actually, it's a three-part

7:48:40

challenge because you are going to make

7:48:42

our program a little bit more robust in

7:48:45

the sense that it might be that these

7:48:48

console logs here that we're just

7:48:49

throwing out into the void, logging to

7:48:51

the console and forgetting all about can

7:48:53

be used later on down the line or that

7:48:55

we of some reason want to keep track of

7:48:57

them. Maybe we want to render it out at

7:48:59

multiple locations in the app. Maybe

7:49:01

there's a notification and there's text,

7:49:03

there's a log of messages you've gotten.

7:49:06

Maybe we want to repeat it. I don't

7:49:07

know. There's tons of reasons for

7:49:09

keeping this data and very few reasons

7:49:11

for just logging it out. We want to keep

7:49:14

it in a variable just like we've done

7:49:16

here with the has blackjack and is

7:49:18

alive. So your three-part challenge is

7:49:21

to first declare a variable called

7:49:23

message and then assign its value to an

7:49:26

empty string and then you're going to

7:49:27

reassign the message variable to the

7:49:30

string we're logging out. Notice here

7:49:32

that I'm using some fancy words like I'm

7:49:33

saying declare instead of create a

7:49:35

variable. I'm saying assign instead of

7:49:38

set its value. That's because I think

7:49:39

you now are ready to hear some of these

7:49:41

fancy JavaScript words because there are

7:49:43

subtle differences between these words.

7:49:44

Like here we are actually declaring the

7:49:47

variable and then we are assigning it

7:49:50

when we set the value to true. This is

7:49:53

after all called the assignment operator

7:49:55

in JavaScript. And then naturally so

7:49:57

when we change a variable or assign it

7:50:00

yet again we reassign it. So, I just

7:50:04

want to use the correct terminology

7:50:05

here, but I think it's important that

7:50:08

you don't get put off by all of these

7:50:09

words and think that you have to

7:50:10

remember them all. You do not. It's

7:50:13

perfectly fine to talk about this using

7:50:15

your own words. Create, change, set the

7:50:18

value, whatever. I just want you to also

7:50:20

be exposed to these technically correct

7:50:23

ways of expressing it. Anyway, enough

7:50:25

talk. As I said, step two, you are going

7:50:27

to reassign the message variable to the

7:50:31

string that we're logging out. So, I

7:50:33

don't want any more console logs inside

7:50:35

of these three code blocks because the

7:50:37

only code block is the one you're going

7:50:39

to create in part three of the challenge

7:50:41

when you are going to log out the

7:50:43

message variable. So, go ahead and give

7:50:45

this your best shot and then return back

7:50:46

to this screencast when you want to see

7:50:48

my solution.

7:50:54

Okay, hopefully that went well. If not,

7:50:57

no worries. Let's do this together.

7:51:00

First, we'll start by declaring this let

7:51:03

variable. We'll call it message and

7:51:05

we'll set it to an empty string. Then on

7:51:07

line 11, 13, and 16, we need to replace

7:51:11

the console log with a message equals

7:51:14

like that. And also remove this close

7:51:17

parenthesis. Do the same thing here.

7:51:19

Remove this one and the closed

7:51:21

parenthesis. And then write message

7:51:23

equals finally here as well. And then we

7:51:28

are ready to log it out down here at

7:51:30

line 21. So I'll log out the message,

7:51:33

run the code, and as you can see, we're

7:51:35

logging. You are out of the game. That

7:51:37

is correct because we had this really

7:51:39

stupid move where we got blackjack, but

7:51:41

we asked for a new card. So let's remove

7:51:43

this. Uh run the code. Yes, you have

7:51:46

blackjack. Try again with for example

7:51:48

14. And yes, I can now draw a new card.

7:51:51

So great job reaching this far. Let's

7:51:54

move on.

7:51:58

Okay, now it's time to fix our biggest

7:52:00

flaw in our blackjack game, which is

7:52:02

that it has no user interface. If we

7:52:04

want this to be a hugely successful

7:52:06

online blackjack game, it has to use

7:52:09

HTML and CSS so that users can play it

7:52:12

via a browser. And I've actually set up

7:52:15

the basics for you here. You can see an

7:52:17

HTML file with a head and a body. And

7:52:20

then inside of the body, we have an H1

7:52:22

with a text blackjack. And also we are

7:52:24

linking to the JavaScript file here on

7:52:26

line 8. And as you can see, if we bring

7:52:28

up the mini browser, this just renders

7:52:30

out the H1 tag. So your job now is to

7:52:34

link this HTML file to the CSS file. You

7:52:38

can see I've created just one CSS rule

7:52:40

in this file and it will be applied

7:52:42

changing the color of the title when you

7:52:45

manage to add a link to the CSS file

7:52:48

here on line five. So I almost every

7:52:50

single time have to search on Google for

7:52:52

how to link to CSS from HTML. I end up

7:52:55

at something like this. So I want you to

7:52:58

do the same thing. And one tip would be

7:53:00

to find this W3 schools right here as

7:53:03

they often pop up on Google and contain

7:53:05

the necessary information. So go ahead

7:53:07

and figure this out on your own and then

7:53:09

I will show you the solution afterwards

7:53:11

as well.

7:53:16

Okay. Hopefully you nailed that one. If

7:53:18

not, no worries. Let's first check out

7:53:20

Google. Then, if we click into the W3

7:53:24

Schools site, you'll see the following.

7:53:26

And it tells us that there are three

7:53:27

ways to insert CSS: external, internal,

7:53:30

and inline. And we are using an external

7:53:32

CSS file. So, we want to scroll down to

7:53:34

external CSS. If we do that, we see the

7:53:37

code here. And the line we're looking

7:53:38

for is this one. Link re equals

7:53:41

stylesheet href equals my style.css.

7:53:45

Okay, good. So let's do link real well

7:53:49

and that is short for relation. So what

7:53:51

is the relation between this HTML file

7:53:54

and the current file you're going to

7:53:55

point to now? Well, it is that the file

7:53:57

you are pointing to is a stylesheet cuz

7:54:00

as you remember CSS is short for

7:54:02

cascading stylesheets. And then it is

7:54:04

the href which in our case is index.css.

7:54:09

We are in the same directory so we don't

7:54:11

need to navigate into a folder or

7:54:12

anything like that. We'll just write

7:54:14

index.css CSS and the href attribute is

7:54:17

something you should be familiar with by

7:54:19

now as that's also what we use when we

7:54:21

are creating links. Now let's run this

7:54:23

code. Boom. You can see the color has

7:54:26

changed meaning we are indeed importing

7:54:28

this stylesheet. Great job.

7:54:34

Okay, now it's time for you to style

7:54:36

this app because as you can see it looks

7:54:38

kind of bad. I've added a few more

7:54:41

paragraphs here as you can see. one

7:54:42

which says want to play around and has

7:54:44

an ID of message shell and then just two

7:54:46

other paragraphs that will display the

7:54:48

cards and the sum eventually. And your

7:54:51

job now is to take this HTML and make it

7:54:53

look like this. If we head into the

7:54:56

index.css file, you can see it says

7:54:58

complete the CSS styling according to

7:55:00

the provided design. And here I've

7:55:02

created two new selectors for you, the

7:55:04

body and the message shell. And the

7:55:06

thing is you can create this entire

7:55:08

design by only using these two

7:55:11

selectors. So that's why I have them

7:55:13

here for you. I've also added a

7:55:15

table.png inside of an images folder.

7:55:18

That is for the casino background that

7:55:20

we are using here. And you've learned

7:55:22

all about how to do this styling in

7:55:24

previous modules of the career path. So

7:55:25

if you struggle, you can go back and

7:55:27

rewatch some of those lectures if you

7:55:29

want. Now, before you start solving this

7:55:31

challenge, I'm going to add the font

7:55:33

family for you because we're using the

7:55:36

trebushche font here and you haven't

7:55:38

really learned how to do that. So, I'm

7:55:39

going to do it for you. We do font

7:55:41

family up in the body and there I

7:55:43

specify trebushche. And as you noticed,

7:55:46

what happened now was that the editor

7:55:48

gave me a bunch of other fonts as well.

7:55:51

And this is called a font stack. And the

7:55:54

reason we use font stacks is because if

7:55:56

your operating system doesn't have

7:55:58

trebuchems installed, well then your

7:56:01

browser can't show that font unless

7:56:03

you've also imported from Google fonts

7:56:05

for example or included it in your

7:56:07

project, neither of which we have done

7:56:08

right now. So if your operating system

7:56:11

can't show trebushchems, then we're

7:56:14

telling it to look for Lucia Sans

7:56:15

Unicode then. And if you don't have that

7:56:17

either, well, look for Lucia Grande and

7:56:19

so on and so on. So it kind of ensures

7:56:21

that at least we'll find a somewhat

7:56:23

similar font as it moves downwards in

7:56:25

the stack. It at least find a sans serif

7:56:28

font here which is our final choice. But

7:56:30

let's stop with fonts there. I don't

7:56:32

want to get deeper into it. Now we have

7:56:34

the trebushche font visible and

7:56:36

hopefully it's visible on your end as

7:56:38

well because trebushche is one of those

7:56:40

fonts that are so-called web meaning

7:56:42

that almost all operating systems have

7:56:44

them installed so it's safe to use. Now,

7:56:47

I want you to take a look at this design

7:56:50

and and add whatever CSS you need to the

7:56:52

body and the message shell so that you

7:56:55

turn this boring page into what looks

7:56:57

much more like a real blackjack game.

7:57:00

So, go ahead and do this right now.

7:57:06

Okay, hopefully that went well. I'm

7:57:08

going to start with the background

7:57:09

image. So, I'm going to write background

7:57:12

image. And then to fetch this table.png

7:57:15

png. Here I can do URL open and close

7:57:18

parenthesis. Then navigate into the

7:57:20

images folder, grab a hold of the

7:57:22

table.png

7:57:24

like that. Now you can see we have the

7:57:26

nice background. However, if I drag this

7:57:29

wide, you can see that at some point we

7:57:32

reach the end of the image and CSS adds

7:57:34

the image yet again after that and we

7:57:36

get this ugly looking line which we

7:57:39

don't want. We instead want to use the

7:57:41

background size property and set that to

7:57:43

cover. Now, no matter how wide you make

7:57:46

it, the image still covers the full

7:57:48

width.

7:57:50

Okay, next step is to center this text

7:57:53

and make it white. So, we can do text

7:57:58

align center to center everything and

7:58:02

color white like that. So, with this we

7:58:06

are turning everything into white except

7:58:09

for the H1 which you can see here. I

7:58:11

have specifically specified that the H1

7:58:14

should be color golden rod and that

7:58:16

overwrites the color white on the body

7:58:19

element. Next up, you can see here the

7:58:22

text is a bit bolder. So, we want to do

7:58:25

that as well. We want to do font weight

7:58:27

bold like that.

7:58:30

Starting to look good.

7:58:33

There's just one final thing just that

7:58:34

you can see the message element which is

7:58:36

the message for the user is in italic

7:58:39

here. It's still just normal. So in the

7:58:42

message gel, we'll do font style and set

7:58:45

that to itallic like that. And there we

7:58:49

have a neat looking blackjack game. So

7:58:51

with that, let's move on.

7:58:56

Okay, so now we need to enable our user

7:58:58

to click a button to play the game. And

7:59:01

you are going to do this through a

7:59:02

challenge, of course. And I'm really

7:59:04

excited about this one because it

7:59:06

includes both HTML, CSS, and JavaScript.

7:59:10

So, this is the first time where you'll

7:59:11

use all three languages to solve a

7:59:14

problem. And the reason that this is so

7:59:16

cool is because this is how it works in

7:59:19

real life when you get a job as a

7:59:20

professional developer. You'll juggle

7:59:22

between HTML, CSS, and JavaScript all

7:59:25

the time. And this is an opportunity to

7:59:27

start practicing exactly that. So, it's

7:59:30

a three-part challenge starting here in

7:59:33

the HTML where you are going to create a

7:59:35

button that says start game and it

7:59:38

should call a start game function when

7:59:40

it's clicked. So, obviously then you

7:59:42

also need to create that start game

7:59:44

function. You'll do that in the

7:59:46

index.js. Here we are to create the

7:59:48

start game function and move the

7:59:51

conditional below line 11 to 20 that's

7:59:54

these lines into the body of the

7:59:56

function so that this code is run when

8:00:00

the button is clicked and then finally

8:00:02

you have to make the button look good

8:00:04

for the user. You are going to style it

8:00:06

according to the provided design and

8:00:09

that is exactly here you can see the

8:00:10

start button. So just click to open this

8:00:13

slide whenever you need to take another

8:00:14

look at it. And doing this translating a

8:00:17

design into CSS is something the front-

8:00:19

end developers do every single day. So

8:00:22

it's great practice. I've given you

8:00:24

three values for properties here.

8:00:26

There's the color of the text that

8:00:28

should have this hex value. The width

8:00:30

should be 150 pixels and the background

8:00:33

should be golden rod. Same as the text

8:00:36

color on the H1. This is a big one, so I

8:00:39

can totally understand if you'll

8:00:40

struggle a bit going through this one,

8:00:42

but give it your best shot and then

8:00:44

return to this screencast when you want

8:00:45

to see my solution. Good luck.

8:00:53

Okay, hopefully that went well. Now,

8:00:56

let's do this here. We'll do button like

8:01:00

that, opening tag. And then I'll do the

8:01:02

closing tag as well. And inside we'll

8:01:05

write start game like that. Let's run

8:01:08

the code. And it looks not particularly

8:01:11

good, but it's at least there. And it's

8:01:12

actually centered. The reason for that

8:01:14

is because here on the body, we are

8:01:18

centering all of our text. And that also

8:01:20

centers the button. Next up, we need to

8:01:24

call the start game function when it's

8:01:26

clicked. And if you remember how that

8:01:28

was, then you'd write on click equals

8:01:31

and then the start game with open and

8:01:34

close parenthesis inside of a string

8:01:37

right here. So when the button is

8:01:38

clicked, we're going to call or invoke

8:01:40

the start game function. Then we need to

8:01:43

create that function. And if you

8:01:46

remember how to do that, it is through

8:01:47

the function keyword function and start

8:01:50

game open and close parenthesis and then

8:01:53

curly brackets for the body of the

8:01:55

function. Inside of here, we are going

8:01:58

to take this code, copy it, paste it in.

8:02:01

I'm going to give it a tab so that it

8:02:03

looks better like that and remove the

8:02:06

empty lines. Now we have this. Let's

8:02:09

rerun the code and see if it works. Yes,

8:02:12

previously we got this console log just

8:02:14

by refreshing the page. But that doesn't

8:02:17

happen now. I have to actually click the

8:02:19

start game. Then we run this. Then we

8:02:21

console log out the message. Great job.

8:02:23

Now let's move on to the CSS. Okay, this

8:02:26

is how we want it to look. Let's take

8:02:29

the first three provided design hints

8:02:31

and see how close we get just by

8:02:33

implementing them. Text color that is

8:02:35

the color property

8:02:39

like that. hardly see it since the text

8:02:42

is so thin, but that's okay for now.

8:02:44

Let's just set the width. Width 150

8:02:48

pixels like that. Okay, looks a little

8:02:50

bit better. And the background

8:02:53

that should be golden rod. Okay, so hm

8:02:57

looking a little bit better, but not

8:02:59

quite this design here. As you can see,

8:03:01

it has some space above and below the

8:03:04

text, whereas this one is much more

8:03:06

crammed. So, let's add that. And if you

8:03:09

remember from the CSS section, you could

8:03:11

add that space by using the padding. So

8:03:13

that's padding top and padding bottom.

8:03:16

I'm going to set five pixels. Looks

8:03:18

about right. Padding bottom. And do five

8:03:22

pixels there as well. Yeah, not too bad.

8:03:24

However, as I mentioned, this text is

8:03:27

really thin. And here it's much thicker.

8:03:30

So let's actually do font weight bold.

8:03:36

Yes, that looks much better.

8:03:38

Now, the next thing I want to fix is the

8:03:40

border around the button. Because you

8:03:42

can see it's totally clean here. It has

8:03:44

no border, but the default styling that

8:03:47

our browser provides has this little

8:03:49

border. So, we want to do border none.

8:03:54

Okay. Now, it actually pretty similar.

8:03:56

They're almost identical, but only one

8:04:00

thing separates them, and that is that

8:04:01

you can see the edges are sharp on this

8:04:04

one, whereas the edges are a bit rounder

8:04:07

on our provided design. So that is the

8:04:10

border radius and pretty subtle. So I'm

8:04:14

going to try two pixels. And yes, that

8:04:18

looks, as far as I can see, identical.

8:04:21

So this was a huge challenge. and you

8:04:24

had to context switch between HTML, CSS,

8:04:27

and JavaScript. So, be really proud of

8:04:29

yourself for reaching this far. If you

8:04:31

struggled and didn't really manage to

8:04:33

get to the finish line on your own, I

8:04:35

think you should just go back and try it

8:04:36

again now that you've seen my solution.

8:04:38

That's a great thing to do to reinforce

8:04:40

what you've just learned. Whatever you

8:04:42

do, I will see you in the next lesson.

8:04:48

Okay, so now our player can click the

8:04:50

start game button like this. However,

8:04:52

we're only logging out the message.

8:04:54

Obviously, we don't want to do that. We

8:04:56

want to display that info on the page

8:04:59

along with, of course, information about

8:05:00

the cards and the sum. But starting with

8:05:03

the message, I want you to solve a

8:05:05

two-part challenge. First, you are going

8:05:07

to store the message L paragraph, that

8:05:10

is this one right here, in a variable

8:05:14

called message L using the camel case

8:05:17

naming convention. And then you're going

8:05:20

to display the message using message

8:05:22

l.ext content. Then of course you can

8:05:25

remove the console log right here since

8:05:27

we don't need it anymore as the message

8:05:29

will pop up here in our app instead. So

8:05:32

go ahead and give this a shot and return

8:05:34

back to me when you want to see my

8:05:35

solution.

8:05:41

Okay. So the way to do this is if you

8:05:44

remember first by creating a variable

8:05:46

with let message L and then using the

8:05:50

document keyword dot get element by id

8:05:56

passing in the ID which we can see from

8:05:59

the HTML and just copy from there

8:06:03

actually and paste then in here as

8:06:06

always control logging to see that we

8:06:08

are on the right track

8:06:11

running this code and yes there we can

8:06:13

see we are logging out that element

8:06:17

now it's just a matter of deleting this

8:06:18

line

8:06:20

doing message Lext

8:06:23

content and what do we want to set the

8:06:25

text content to we want to set it to

8:06:28

message like that if we now run the code

8:06:31

hit the start game button yes there we

8:06:34

got do you want to draw a new card job

8:06:37

now there's one thing I want to do

8:06:38

before we round off and that is actually

8:06:40

to remove these emojis because when they

8:06:42

are italicized, they don't look that

8:06:44

good. And while that isn't the most

8:06:47

complicated thing to fix, it's not

8:06:48

something I think you should learn right

8:06:50

now. I want to keep up the pace. And

8:06:52

also, when we see this text here

8:06:53

rendered on the page, it's kind of our

8:06:55

dealer speaking to us in italic text.

8:06:58

And I don't think our dealer should show

8:06:59

that much emotion. So, it makes sense to

8:07:01

remove these emojis like this. Also,

8:07:05

maybe make it a bit more neutral. The

8:07:07

dealer will just tell us that we have

8:07:08

blackjack. won't shout out. Woohoo. So,

8:07:11

makes more sense. Run your card. Yeah,

8:07:13

looks good. If we get blackjack. Yeah, I

8:07:16

think that looks good. So, with that,

8:07:18

let's move on.

8:07:22

Okay, so let's make our game a little

8:07:24

bit more useful because now you can

8:07:25

click the start game button and indeed

8:07:27

we get the message from the dealer, but

8:07:29

we have no idea what our sum and our

8:07:31

cards are. So, we obviously need to

8:07:33

render that out and we're going to start

8:07:35

with the sum. So, it's a three-part

8:07:37

challenge where you first have to head

8:07:39

into the HTML and there give the sum

8:07:42

paragraph that is this one an ID of

8:07:45

sum-l

8:07:47

then you are to store the sum paragraph

8:07:49

in a variable called sum L like this in

8:07:52

camel case and finally render the sum

8:07:55

out so here I'm talking about the actual

8:07:57

numeric sum on the page using this

8:08:01

format so sum colon and then the given

8:08:04

sum you have up here. So here you have

8:08:07

to keep this text which is already in

8:08:10

the DOM intact. But we have done that

8:08:13

before. So hopefully you'll manage it.

8:08:15

If not, no worries. You can just revert

8:08:17

back to this screencast and I will show

8:08:19

you how to do it as well. But go ahead

8:08:21

and give this your best shot right now.

8:08:28

Okay, let's do this. First, we'll give

8:08:31

this an ID of sum-l.

8:08:35

Moving over to the JavaScript, we'll do

8:08:37

let some l with the camel case this time

8:08:42

and document.getelement

8:08:45

by id open and close parenthesis and the

8:08:49

quotes passing in the ID that we just

8:08:52

added to the HTML element sum-l.

8:08:56

Now just to be certain let's just

8:08:58

console log the sum l run the code. Yes

8:09:02

indeed we are grabbing the element and

8:09:05

then we need to render out the string of

8:09:08

sum and then the actual sum which in

8:09:11

this case is 14 from this variable up

8:09:14

here into the element itself. And the

8:09:17

way I'll do that is I'll use sum L and

8:09:21

then text content which you should have

8:09:23

seen a few times by now and set that

8:09:26

equal to not only the sum because if we

8:09:29

do that let's rerun the code and start

8:09:32

the game. Then we simply just clear out

8:09:34

the existing text where we want to keep

8:09:37

the sum there. And we can do that in

8:09:39

multiple ways. But the way I'll do it is

8:09:41

simply just write sum colon a space and

8:09:45

then plus here. So that we just

8:09:48

reconstruct the default text as well in

8:09:50

addition to the sum. I think this is a

8:09:52

nice way of doing it. So if we run the

8:09:54

code, start the game. Yes, there we go.

8:09:58

Now, before we move on, I want to teach

8:10:00

you about another way of grabbing

8:10:02

elements from the DOM because we've used

8:10:05

get element by ID a few times now. So,

8:10:08

I'm assuming you're comfortable with

8:10:09

this technique and are ready to learn

8:10:11

another one. And that is something

8:10:13

called the query selector. And to learn

8:10:16

that, let's comment out this one and

8:10:19

copy it to a new line where we can

8:10:20

change it.

8:10:22

And here instead of get element by ID,

8:10:25

we'll do query

8:10:27

selector like that. Since this is a more

8:10:30

dynamic method, we have to be a bit more

8:10:33

specific in the value we pass into it.

8:10:36

So here we actually have to pass in a

8:10:37

hashtag in front of the sum to tell the

8:10:40

query selector that it's actually the

8:10:42

element with the ID of suml that we're

8:10:45

looking for. Because unlike the get

8:10:47

element by ID, we're not specifying that

8:10:50

it's an ID in the method name. It's just

8:10:53

called query selector which is kind of a

8:10:56

broader expression. So query, that's

8:10:58

another word for question and selector

8:11:01

that refers to CSS selectors. So we're

8:11:04

kind of asking for an element by its

8:11:07

selector. And then we specify the given

8:11:09

selector inside of the parenthesis. So

8:11:11

here if we run this start game, the

8:11:14

exact same thing happens. Now, if you've

8:11:16

forgotten what a CSS selector is, we can

8:11:19

head over to the CSS and it's these guys

8:11:22

right here. The body that's just

8:11:23

selecting the body element, this one.

8:11:27

And then there's the ID selector right

8:11:30

here. You can see we are using the

8:11:31

hashtag to grab the message L because

8:11:35

this paragraph has an ID of message-l.

8:11:39

Likewise, sum has an ID as well. So

8:11:42

we're using the hashtag to tell query

8:11:44

selector that this sum-l comes in the

8:11:47

form of an ID. Now this means that we

8:11:51

could change this to a class instead.

8:11:56

However, then we also have to change

8:11:58

this hashtag and replace it with a dot.

8:12:00

Hopefully you remember that the way to

8:12:02

select CSS classes is by using the dot.

8:12:05

If we run this, it still works. And

8:12:09

actually we could even pass in just the

8:12:11

element name as well. So we could do

8:12:13

body right here. However, it would break

8:12:16

our app since we're now okay just

8:12:20

clearing out the entire body when we are

8:12:23

running this piece of code down here on

8:12:24

line 11 because now suml actually refers

8:12:28

to this entire body.

8:12:32

So, as you probably understand, query

8:12:33

selecture is very powerful and you will

8:12:36

see it used in a lot of tutorials here

8:12:37

on Scribba. But as for right now, I just

8:12:40

wanted to show it to you so that you are

8:12:42

prepared once you see it in other

8:12:43

tutorials and out in the wild. In the

8:12:46

near future, I am going to stick with

8:12:49

the document.getelement by ID as that

8:12:52

does the job for us and it's also a very

8:12:55

simple method to understand. So, I'd

8:12:57

like to avoid the added complexity of

8:12:59

jumping between get element by ID and

8:13:01

query selector if we can.

8:13:04

With that, let's just move on.

8:13:10

Okay, let's continue building that

8:13:11

muscle memory of yours. You are going to

8:13:14

do almost the exact same thing as you

8:13:15

did with the sum, but this time with the

8:13:17

cards because obviously when you start

8:13:19

the game, you can see your sum now, but

8:13:21

you can't see your cards. That has to be

8:13:23

fixed. So, it's the same three-part

8:13:25

challenge starting in the HTML where you

8:13:28

are to give the cards paragraph an ID of

8:13:30

card cell. Then in the JavaScript, you

8:13:32

are to store the cards paragraph in a

8:13:34

variable called card cell with camel

8:13:37

case. And then finally render it out in

8:13:39

this format right here. So go ahead and

8:13:42

do this right now and then I will show

8:13:44

you how I would do it when you revert

8:13:46

back to the screencast as well.

8:13:53

Okay, let's do this. First giving this

8:13:56

an ID of

8:13:58

cards L.

8:14:01

Then storing the card paragraph in a

8:14:03

variable called also cardel. Let cards L

8:14:08

in camel case this time

8:14:10

document.getelement

8:14:12

by id passing in cards-l

8:14:17

like that. Now, I'm just going to jump

8:14:19

straight to this line here and do cards

8:14:22

L.ext

8:14:24

content equals constructing the entire

8:14:28

contents of the paragraph this time. So,

8:14:30

we're clearing out the text that's

8:14:31

already there and replacing it with a

8:14:34

new cards colon.

8:14:38

This will be actually cleared out and

8:14:40

replaced using JavaScript. and then plus

8:14:42

the first card and then I have to add a

8:14:46

space between the first card and the

8:14:48

second card and then the second card

8:14:52

like that. If I run this code, start the

8:14:55

game and there we go. We have both of

8:14:58

the cards rendered out. Great job. Let's

8:15:00

move on.

8:15:04

So, our game really starts taking shape

8:15:07

now. We hit the start game button and we

8:15:08

get the message, the cards, and the sum.

8:15:10

However, a critical part of blackjack is

8:15:13

the ability to draw a new card from the

8:15:14

deck. So, we need to start building that

8:15:16

feature and we are going to first begin

8:15:19

with creating the new card button that

8:15:21

you can see on the slide here. So, in

8:15:23

this three-part challenge, you are going

8:15:25

to first head into the HTML and create

8:15:27

that new card button and then make it

8:15:29

run a new card function when it's

8:15:32

clicked. And then in the JavaScript, you

8:15:34

have to create that new card function.

8:15:36

And for now, it should just log out

8:15:38

drawing a new card from the deck.

8:15:40

Then in the CSS, you need to make sure

8:15:43

that when these two buttons are rendered

8:15:46

out vertically like this, so above each

8:15:49

other, you'll need to make sure that

8:15:50

this small space between them is added

8:15:53

because it won't be added by default.

8:15:55

Now, if you enlarge this browser and

8:15:57

make it wider, they will render out

8:15:58

besides each other, but you are not to

8:16:01

worry about that layout. So, make sure

8:16:03

you keep this browser window a little

8:16:05

bit narrow so that they are rendered out

8:16:07

under each other. and then make sure

8:16:09

that you get this little gap here. So

8:16:13

this is again a very holistic challenge.

8:16:16

You are to write JavaScript, HTML, and

8:16:19

CSS just like it is out in the real

8:16:21

world. So go ahead and give this your

8:16:23

best shot right now.

8:16:30

Okay, hopefully that went well. If not,

8:16:32

no worries. Let's do this together.

8:16:35

In the HTML, we are starting with the

8:16:38

button

8:16:40

open and closing tag. New card like

8:16:44

that. I'll just render it out. Oo, there

8:16:46

we got it. Actually got them beside each

8:16:49

other. We want them vertically like

8:16:51

this. So there we can already see that

8:16:54

we are missing the gap that we wanted.

8:16:56

But that's the CSS part of the

8:16:58

challenge. Let's continue on with the

8:16:59

HTML and get that wrapped up. We'll do

8:17:02

on click equals and then run this new

8:17:06

card function which we haven't created

8:17:08

yet which we are going to create right

8:17:10

now down here function new card open and

8:17:15

close parenthesis and then the curly

8:17:17

brackets for the body of the function

8:17:19

inside here logging out this string we

8:17:23

got provided in the comment like that

8:17:26

I'll run this code hit new card and

8:17:29

indeed we are logging it

8:17:31

Now final step is to add this gap right

8:17:34

here. We need to head into the CSS and

8:17:37

there are multiple ways to do this. One

8:17:39

way is to just say that we want any

8:17:41

button to have a little bit of margin

8:17:43

below them. So this is about four

8:17:45

pixels. So we could do

8:17:48

margin bottom four pixels like that.

8:17:53

There we see that our button works.

8:17:55

Alternatively, let's say that we in some

8:17:57

case end up with a situation where

8:17:59

something comes too close to the button

8:18:00

on the top side of it. Well, maybe we

8:18:03

need some margin on top of it as well.

8:18:05

But if I now add margin bottom and

8:18:07

margin top or four pixels here, margin

8:18:10

top four pixels, what you'll see is that

8:18:13

the gap here became twice as wide

8:18:14

because that has the top margin that

8:18:16

pushes it down and also the start game

8:18:18

button that uses its margin bottom to

8:18:20

get the gap even larger. So what we then

8:18:23

instead can do is take two pixels on

8:18:26

each. Now we have something that looks

8:18:30

very much like this. And we have created

8:18:32

our buttons so that they always have

8:18:34

some space below and above themselves.

8:18:36

And I think that makes a lot of sense as

8:18:38

buttons usually want a little bit of

8:18:40

space around them. With that, let's move

8:18:42

on.

8:18:46

Okay, let's make our new card function a

8:18:49

bit more useful because now it's just

8:18:50

rendering out this string. What we

8:18:52

wanted to do is to actually draw a new

8:18:55

card and then add that new card to the

8:18:58

sum and then rerun the code that is

8:19:00

inside of the start game function so

8:19:02

that the sum is added to the page. And

8:19:05

actually later down the line, we also

8:19:07

want to show the new card of course, but

8:19:09

as for now, we're just going to worry

8:19:10

about the sum. So, this is a three-part

8:19:13

challenge where you are to first create

8:19:15

a card variable, and we're still just

8:19:18

working with hard-coded card variables.

8:19:20

You're just going to code it to a number

8:19:22

between 2 and 11. Then, you are going to

8:19:25

add this new card to the sum variable.

8:19:28

And the sum variable is the one up here,

8:19:30

of course, which currently is the first

8:19:32

card plus the second card. And in this

8:19:34

case, it'll be plus the third card as

8:19:36

well. So, you need to plus equal the sum

8:19:39

variable. And then finally you are going

8:19:41

to just call the start game function

8:19:44

because what does the start game

8:19:45

function actually do? Well, first it

8:19:48

renders out the two cards. In our case

8:19:50

now we'll have added the third card. So

8:19:52

this will still be wrong but line 13

8:19:56

will render out actually the new sum

8:19:58

because at this point sum will have

8:20:00

changed since we'll have modified it

8:20:01

down here. And then it'll show the

8:20:04

message based upon the new updated sum.

8:20:07

So actually it seems that we can use

8:20:09

this start game function even after

8:20:11

we've drawn a new card and thus we're

8:20:13

going to rename it a bit later. But as

8:20:15

for now let's just keep it how it is and

8:20:17

your job is just to call the start game

8:20:18

function here on line 33. So go ahead

8:20:22

and give this challenge your best shot

8:20:23

and then I will show you the solution as

8:20:25

well afterwards.

8:20:31

Okay, let's do this. So we do let card

8:20:35

here. We'll set that to a random number

8:20:37

between 2 and 11. I'll do seven. And

8:20:39

then we're going to add the new card to

8:20:41

the sum variable. If you remember how we

8:20:44

add numbers to an existing variable,

8:20:46

it's via the plus equal operator. So

8:20:48

we'll do sum plus equal card. And then

8:20:50

we'll call start game. So start game

8:20:54

like that. Let's rerun the code. First

8:20:56

do start game. Okay. Do you want to draw

8:20:58

a new card? I happen to want to do that.

8:21:00

So I'll hit new card. And boom. I drew

8:21:02

the seven card which then made the sum

8:21:04

reach 21 which then again made our

8:21:06

dealer tell us that we got blackjack. So

8:21:08

that is exactly what we want. Now let's

8:21:11

see what happens if we instead of a

8:21:13

seven got an eight. If I now rerun the

8:21:16

entire code, start game and then hit new

8:21:18

card. Bam. Then we're out of the game

8:21:20

since we have sum equals 22. And if we

8:21:23

got a six instead I'll rerun the code.

8:21:26

Start game. New card. Then we still get

8:21:28

the do you want to draw a new card text

8:21:30

since we're still below 21. Now I can

8:21:33

actually hit the new card yet again and

8:21:35

then we are out of the game. Now we're

8:21:37

at 26. So this works for multiple cards.

8:21:40

Of course it's only the sum that's

8:21:41

reflected right now, not the cards. So

8:21:43

we'll have to fix that in a bit. But for

8:21:45

now, let's just move on and first fix

8:21:48

this little problem that the start game

8:21:50

function name doesn't really make sense

8:21:52

anymore since we're calling start game

8:21:55

here at a point where the game has

8:21:57

already started. So, semantically it

8:21:59

doesn't really add up. So, let's move on

8:22:01

to the next cast.

8:22:05

So the problem now is that the start

8:22:08

game function is triggered both when we

8:22:10

hit the start game button, which makes a

8:22:12

lot of sense, but also when we click the

8:22:14

new card button because even though the

8:22:17

new card button triggers the new card

8:22:20

function, which is this one right here,

8:22:23

that function itself calls start game as

8:22:26

well. And while this makes sense because

8:22:28

we want to run this code, the fact that

8:22:31

start game still is called start game

8:22:33

doesn't really make sense because if

8:22:35

another developer comes in here and

8:22:37

looks at that code, he'll be like, um,

8:22:39

why are we starting the game all over

8:22:41

again when clicking a new card, that

8:22:43

doesn't semantically add up. So, what we

8:22:45

want to do here is actually just change

8:22:47

the name of the start game function, for

8:22:50

example, to render game because that's

8:22:53

essentially what we're doing. We're

8:22:54

rendering out the current state of the

8:22:56

game. So we can do render game just

8:22:58

rename this one and this one to that. So

8:23:01

far so good. But then the problem

8:23:03

becomes that we're actually calling

8:23:05

start game here. And we could do render

8:23:09

game like this. But actually I want to

8:23:11

keep this start game function intact

8:23:14

because down the line there might be

8:23:15

some other things you want to do in this

8:23:17

game initialization function. So I want

8:23:19

you now to create a function that uses

8:23:22

the name start game and then just calls

8:23:25

or invokes render game. That's all it

8:23:27

should do. So that this start game

8:23:30

button will work. Because now you can

8:23:32

see it doesn't work. When I click it,

8:23:34

we're actually getting a reference error

8:23:36

saying that start game is not defined

8:23:37

because we're trying to call a function

8:23:39

that no longer exists. So go ahead and

8:23:42

create the start game function here on

8:23:44

line 12 and make it just call this

8:23:46

render game function right here. Go

8:23:48

ahead and do this right now.

8:23:55

Okay, hopefully that went well. The way

8:23:57

to do it is through function and then

8:24:01

start game open and close parenthesis

8:24:04

open and close curly brackets and inside

8:24:06

here just call render game like that.

8:24:10

Let's rerun the project. Hit start game.

8:24:13

And yes, now it works again. Great job.

8:24:20

Okay, so now we need to fix up the

8:24:21

rendering of the cards because if I hit

8:24:24

start game and I get the two cards out

8:24:26

and then hit new card, indeed our sum

8:24:29

increases, but our cards paragraph are

8:24:31

displaying only two of the three cards

8:24:33

we've pulled from the deck cuz we have a

8:24:35

10 and a four and a six. whereas we're

8:24:38

only showing the 10 and the four in the

8:24:41

browser because that is hardcoded here

8:24:43

to only do that no matter how many cards

8:24:46

we pulled from the deck. This line 16

8:24:48

will always just render out the first

8:24:50

card and the second card. So this line

8:24:53

here in pseudo code says render out

8:24:57

first card and second card. But what we

8:25:01

instead need is something that says

8:25:04

render out

8:25:06

all the cards we have regardless of how

8:25:10

many cards. If we have five cards, it

8:25:12

should render out five cards. If we have

8:25:13

two cards, it should render out two

8:25:14

cards. But that's not possible with the

8:25:17

current implementation. And what we need

8:25:19

is a central way of storing all of our

8:25:21

cards. We need to store all of our cards

8:25:23

in one variable regardless of how many

8:25:25

cards it is. And the way to do this is

8:25:28

actually to use what's called an array,

8:25:30

which is essentially a list of items.

8:25:33

And I'm going to create an array here.

8:25:36

And it's totally okay if you now feel

8:25:37

confused. I just want to give you a

8:25:39

little sneak peek at it before we take a

8:25:41

deep dive and give you some practice on

8:25:42

it. I'm going to do let cards equals and

8:25:45

then open and closed square brackets.

8:25:48

That's the notation for creating arrays.

8:25:50

And inside of these square brackets, I'm

8:25:53

going to paste the first card, then a

8:25:55

comma, and then the second card. So,

8:25:58

this is now a cards array that includes

8:26:01

both cards, ordered by the first card

8:26:04

first and the second card second. You

8:26:06

can call this an ordered list of items.

8:26:11

Now, we down at what's line 18 now. and

8:26:14

replace the first card by referring to

8:26:17

the array instead and doing open and

8:26:21

close square bracket and zero. Don't

8:26:23

worry about that. You'll understand that

8:26:25

in a minute. Let's just now do the same

8:26:27

things for the second card. Then we'll

8:26:29

do cards open and closed square brackets

8:26:32

and one.

8:26:34

So this is referring to this one right

8:26:37

here. And one is referring to this item

8:26:42

right here. And that is because arrays

8:26:44

are so-called zero indexed. They start

8:26:46

at zero and one. And if we add a third

8:26:50

card here, that would be index number

8:26:52

two. But we don't have a third card. So

8:26:55

let's remove that.

8:26:57

Now, even though you might feel a little

8:26:59

bit confused now, let's just run the

8:27:01

code, hit the start game, and see yes,

8:27:03

that it still works. So this way of

8:27:06

doing it was the exact same as what we

8:27:07

had previously when we just hardcoded in

8:27:09

first card and second card like this.

8:27:11

Now, this opens the possibility later

8:27:14

down the line to render out all of our

8:27:17

cards in a dynamic way inside of the

8:27:19

cards element regardless of how many

8:27:22

cards we have inside of our cards array.

8:27:24

So, that was a lot of information. Now,

8:27:27

we're going to take a step back, work

8:27:28

with arrays, get your hands dirty. So,

8:27:30

don't worry if you didn't quite

8:27:32

understand this as you will surely do

8:27:34

that after the next few lessons.

8:27:39

Okay, so arrays are ordered lists of

8:27:42

items. However, that's a little bit

8:27:44

abstract. So, let's instead look at a

8:27:46

real world product and see if we can

8:27:49

recognize any components that most

8:27:51

likely use arrays as a data structure.

8:27:54

So, here we have a LinkedIn profile.

8:27:57

This is Justin. He's a previous Scribba

8:27:59

student. And looking at this, there's

8:28:01

immediately multiple components that

8:28:03

most likely use arrays to render stuff

8:28:05

out. You can see here on the right hand

8:28:07

side there are some promotions actually

8:28:10

three of them and that's basically a

8:28:12

list of items and while their order

8:28:14

might be a little bit random they still

8:28:16

have a specific order. Likewise with the

8:28:19

people also viewed here that's a list of

8:28:21

four people. Let's also scroll a bit

8:28:23

down here. We can see even in the main

8:28:26

section there's this component that says

8:28:28

featured. That is featured posts and

8:28:30

that's basically just a list of items.

8:28:33

So, LinkedIn probably uses an array to

8:28:36

describe this data in JavaScript. So,

8:28:38

actually, let's just create that array.

8:28:41

Lette featured posts like that and then

8:28:45

equals open and closed square brackets.

8:28:48

The first one is actually Justin sharing

8:28:50

the Netflix clone he built through a

8:28:53

course here on Scribba and he actually

8:28:54

deployed it as well. So, he's going

8:28:56

above and beyond. So, check out my

8:28:59

Netflix

8:29:01

clone like that. The second one is

8:29:03

actually a link Justin has shared to

8:29:05

source code he's pushed to GitHub, which

8:29:07

is also a great thing to do if you want

8:29:09

to track employers. So here's code for

8:29:14

my project.

8:29:16

I'm simplifying, of course, the data

8:29:19

here because there are multiple parts of

8:29:22

this. There's an image, there's text,

8:29:24

there's comments and so forth. But as

8:29:25

for now, we're just simplifying it into

8:29:27

strings. The third item here is actually

8:29:29

Justin sharing the portfolio he has

8:29:31

built through a scribble course as well.

8:29:33

So I've

8:29:36

relaunched my portfolio like that. There

8:29:39

we have an array with three items. Now

8:29:42

this line is pretty long. So sometimes

8:29:44

you'll see an array formatted like this

8:29:48

as it makes it easier to see that it is

8:29:50

indeed three items. And a key thing to

8:29:53

observe here is that we add commas after

8:29:55

the items but not after the final item.

8:29:59

So only between items basically. So

8:30:02

going back to LinkedIn, there are tons

8:30:05

of components here that's probably

8:30:07

utilized as arrays. For example, the

8:30:09

work experience, that's a list of

8:30:12

previous jobs or licenses and

8:30:14

certifications. That's a list of

8:30:16

licenses. You can see the front-end path

8:30:18

right here. And skills and endorsements.

8:30:21

So, a ton of examples. And now what I

8:30:23

want you to do is to create an array

8:30:25

that lists your experience or education

8:30:29

or licenses or skills or something

8:30:31

similar. You are to choose what you want

8:30:33

this array to contain. But try to think

8:30:36

how can you best describe your either

8:30:37

experience, education, skills or

8:30:39

whatever in a way that would make your

8:30:41

LinkedIn profile look tempting for

8:30:44

recruiters as that's a smart thing to

8:30:46

think a little bit about already even

8:30:48

though you're very early in your coding

8:30:50

journey. So go ahead and do that. And

8:30:52

remember that the items should just be

8:30:54

strings just as I've done up here. Go

8:30:57

ahead and do this right now.

8:31:03

Okay, hopefully that went well. Now I'm

8:31:05

going to do it as well. So I'll do let

8:31:07

and then experience. That's what I want

8:31:10

to create my array about, my work

8:31:11

experience. And I'm currently the CEO at

8:31:14

Scribba. Before that, I was a front- end

8:31:18

developer at Sinetta. That's a Oslo

8:31:21

based company for seaf freight analytics

8:31:23

and also as you probably remember from

8:31:25

our subway counter app I worked as a

8:31:28

people counter out in the cold a company

8:31:31

called Norstat. So that is my

8:31:34

experience. Now before you move on to

8:31:37

the next cast I want to highlight the

8:31:39

importance of actually being able to

8:31:41

describe your background and your skills

8:31:43

in a good way on LinkedIn. Justin here,

8:31:45

the person behind the LinkedIn profile

8:31:47

we looked at, he actually lost his job

8:31:49

in the petroleum industry due to the

8:31:51

coronavirus pandemic. And less than one

8:31:53

year later, he now works as a

8:31:55

professional software developer. And as

8:31:57

I said, he did that mostly through

8:31:59

Scribba and was a super engaged student

8:32:02

at our Discord channel. And what's so

8:32:03

cool about how he did it is that he sent

8:32:05

out over 100 job applications without

8:32:08

getting much luck. but then went into

8:32:11

optimizing his LinkedIn and then

8:32:13

suddenly he got two job offers and the

8:32:16

job he got actually came through a

8:32:18

recruiter that found his LinkedIn

8:32:20

profile as a result of keyword searches.

8:32:24

Actually, he ended up tweaking his

8:32:26

LinkedIn profile so that he attracted

8:32:28

the right recruiter who got him an

8:32:30

amazing job as a developer. So, I wanted

8:32:33

to share this with you. And if you click

8:32:35

on this image, you'll be taken to the

8:32:36

page for the podcast interview we did

8:32:39

with Justin so that you can listen to

8:32:41

his story if you want to. For example,

8:32:43

when you're riding the bus or out

8:32:45

walking or cleaning or whatever, I don't

8:32:47

want you to interrupt the course and

8:32:49

listen to this instead of coding. It's

8:32:51

more important that you code, but you

8:32:53

can keep it in mind for the next time

8:32:54

that you have half an hour or something

8:32:56

because I think you'll learn a ton about

8:32:58

Justin who at the age of 33 did his

8:33:01

career shift. So, with that little plug

8:33:03

out of the way, let's move on.

8:33:08

An important thing to know about arrays

8:33:10

is that they are so-called zero indexed.

8:33:13

And that means that you want to grab the

8:33:16

first item of the array, you do it

8:33:18

through using the zero index, not the

8:33:22

first index. And let me show you what

8:33:24

that means in practice. Featured posts,

8:33:27

that's our array. And I want to grab the

8:33:29

first item, the check out my Netflix

8:33:32

clone. I'll do that through open and

8:33:34

close square brackets and then passing

8:33:36

in the number zero. If I now console log

8:33:38

this

8:33:40

and we run the code, you can see yes

8:33:42

that we are indeed logging out that

8:33:45

string. So this isn't entirely intuitive

8:33:47

since we as humans normally start

8:33:49

counting at one. But in arrays you start

8:33:52

counting at zero. So if this is the

8:33:55

zeroth index,

8:33:57

which index does this item have? Take a

8:34:01

guess.

8:34:02

Well, it has the index of two even

8:34:05

though it is the third item. I run the

8:34:08

code to now see that passing in two logs

8:34:11

out. I've just relaunched my portfolio.

8:34:13

So, here is the zero index. This is the

8:34:17

first and here is the second. Now, with

8:34:21

this in mind, I want you to practice

8:34:23

this. So, you are to take my experience

8:34:25

array here and log out the following to

8:34:29

the console. and in this order. So you

8:34:32

are to start with the front- end

8:34:34

developer in Asanetta, then the people

8:34:36

counter and then CEO at Scribba. So

8:34:38

first this one, then this one, and then

8:34:41

the first one. So you have to write

8:34:43

three console logs and place them in

8:34:46

order here starting from line 18 so that

8:34:49

I'm sure that you actually understand

8:34:51

the concept of arrays being zero

8:34:53

indexed. I'm going to comment out this

8:34:55

one right here so it doesn't disturb

8:34:57

you. Now go ahead and solve this

8:34:59

challenge.

8:35:05

Okay, hopefully that went well. Let's do

8:35:08

this together.

8:35:10

I'm going to do control log. I want the

8:35:13

front-end developer at Seretta that is

8:35:16

not the first but the second item and in

8:35:19

terms of indexes, it's the zeroth and

8:35:22

then the first index. So then I need to

8:35:24

do experience

8:35:27

one. Okay, I'm going to copy this one,

8:35:29

paste it in again. Now I'm going to log

8:35:31

out the third item, which is the second

8:35:34

index. So that is experience 2. And

8:35:38

finally, I'm going to log out this item

8:35:41

right here that has the index of zero.

8:35:44

If I run this code, you can see in the

8:35:46

console that we are indeed logging out

8:35:48

the items in this order. Now, before we

8:35:51

move on, I'm going to confuse you a

8:35:53

little bit because let's actually delete

8:35:55

all of this this remove the console and

8:35:58

and just go back to this featured posts.

8:36:01

If I now do featured posts dot length

8:36:07

and then console.log

8:36:09

this out, which number do you think

8:36:12

we'll see printed to the console? Take a

8:36:15

guess. Well, the answer is three. And

8:36:18

that might be a little bit confusing

8:36:20

because I've just taught you that arrays

8:36:22

are zero index. So the first is zero,

8:36:24

the second is one, the third is two. So

8:36:27

it would be natural to believe that

8:36:28

thelength property of this feature posts

8:36:32

is two because the final index is two.

8:36:35

But whereas indexes are zero indexed,

8:36:39

the length is not zero indexed. We count

8:36:42

the length of an array in just the same

8:36:44

way you would count anything in life,

8:36:46

which is starting at the number one. So

8:36:49

that also means that the length property

8:36:51

of an array is always one larger than

8:36:54

the final index. So this is one of those

8:36:57

things that are a little bit unintuitive

8:36:58

and confusing when learning JavaScript

8:37:00

and you probably will mix it up a couple

8:37:02

times. That's not a problem. Just trust

8:37:05

me when I say that eventually this will

8:37:07

become second nature for you. So let's

8:37:10

move on.

8:37:14

Okay, up until now, our arrays have

8:37:17

either included only strings or only

8:37:20

numbers. However, they're not limited to

8:37:23

that. Actually, put any data type you

8:37:25

want into an array. And you can mix as

8:37:27

much as you want. So, you can think of

8:37:29

an arrays as kind of a composition of

8:37:32

multiple data types and their values.

8:37:34

So, this is why arrays are what we call

8:37:37

a composite data type. You can say it's

8:37:39

composed by its items if you needed to

8:37:41

make semantically sense. And you'll

8:37:44

often hear this also referred to as

8:37:46

complex data types. That is arrays and

8:37:48

also for example objects which you are

8:37:50

going to learn about later. They stand

8:37:52

in contrast to the primitive data types

8:37:55

you have worked with up until now. The

8:37:58

three primitives you have learned are

8:38:00

strings, numbers, and booleans because

8:38:03

they are more primitive than arrays.

8:38:05

They're not composed of many other data

8:38:07

types which arrays often are. So one

8:38:10

analogy you can use is that the

8:38:13

primitive data types are the Lego blocks

8:38:16

whereas the array the composite data

8:38:18

types is kind of like the full Lego

8:38:20

model. For example, after you've built a

8:38:22

little house with your Lego blocks. But

8:38:24

anyway, you shouldn't worry too much

8:38:26

about this if you find it a little bit

8:38:27

abstract and complex. As a developer,

8:38:30

you don't go around thinking about, oh,

8:38:32

is this a primitive data type or a

8:38:34

complex data type. it just becomes

8:38:35

second nature and you don't even think

8:38:37

about it. So you shouldn't be put off by

8:38:39

this even though it's a little bit

8:38:41

theoretical. Instead, I think you should

8:38:43

just practice. Now, I want you to create

8:38:46

an array that describes yourself and use

8:38:49

all the three primitive data types that

8:38:51

you've learned so far. So, it should

8:38:53

contain your name, which is a string,

8:38:55

your age, which is a number, and whether

8:38:57

or not you like pizza, which should be a

8:38:59

boolean. So, go ahead and do this right

8:39:01

now.

8:39:07

Okay, hopefully that went well. Now,

8:39:09

let's do it together. I'm going to

8:39:11

create an array called pair

8:39:14

and my name is Pear Harold Borggan. I am

8:39:18

35 years old and I do happen to like

8:39:21

pizza and I especially like pizza with

8:39:23

pineapple.

8:39:25

It's the best. Though, I know that a lot

8:39:27

of you don't agree with me. So, let's

8:39:29

not get into a discussion about that.

8:39:30

Let's just move on with the course.

8:39:36

One of the most common operations you'll

8:39:38

perform on a race is adding items to the

8:39:41

end of it. That's for example what you

8:39:43

want to do in our blackjack game where

8:39:45

you start with two cards and then you

8:39:47

want to draw a new card. That'll

8:39:49

naturally then be put at the end of the

8:39:51

array. For example, six. However, the

8:39:54

way to do that is not through actually

8:39:55

changing it directly which I did. Now

8:39:58

you use a method which is called push

8:40:01

which allows you to well push things

8:40:03

into the array. So you do cards dot push

8:40:08

and then open and close parenthesis. And

8:40:11

inside of these parenthesis you place

8:40:12

whatever you want to push. So for

8:40:14

example six. If we now console log the

8:40:18

cards underneath our push operation

8:40:22

you can see we have added six to the

8:40:24

array. So this here is actually called a

8:40:26

method which is just a fancy way of

8:40:28

saying a function on an object. And you

8:40:31

haven't really learned about objects

8:40:32

yet. So don't worry about if you think

8:40:34

this sounds a little bit abstract. But

8:40:36

this operation here is pretty similar as

8:40:39

the console.log

8:40:41

then passing in for example hello. Don't

8:40:43

you think? We have the first object

8:40:46

cards or console. Then we have the

8:40:48

methods which is either log or push.

8:40:51

Then we have whatever we pass into these

8:40:54

methods when we call them. So this here

8:40:57

cards push is conceptually very similar

8:40:59

to what you've been doing all along.

8:41:02

Let's now make sure that you build

8:41:04

muscle memory on this by solving a

8:41:06

challenge.

8:41:08

So I want you to imagine that you are

8:41:10

building a chat application for example

8:41:12

the one I showed you here on LinkedIn.

8:41:14

And the data structure we'll use is of

8:41:16

course arrays. And we'll pretend that

8:41:18

each of these messages is an item in the

8:41:21

array. So when someone types in a new

8:41:24

message and sends it, well, you want to

8:41:26

push that new message to the array. So

8:41:29

here you are to push the new message

8:41:31

variable, that's this one down here,

8:41:33

into the messages array, that's this one

8:41:36

here. And then you are to log out the

8:41:38

array to just verify that you actually

8:41:41

succeeded in pushing the item. Go ahead

8:41:43

and do that right now. and then I will

8:41:45

show you the solution afterwards as

8:41:47

well.

8:41:52

Okay, hopefully that went well. Now

8:41:54

let's do this. We'll do messages dot

8:41:58

push and inside of the parenthesis we'll

8:42:00

pass in new message like that referring

8:42:03

to the variable and not the hard-coded

8:42:06

value which we did up here when we

8:42:08

passed in six. So a little bit different

8:42:10

but still the same concept. Now let's

8:42:12

console.log log messages and then run

8:42:16

this code. If we bring up the console,

8:42:19

we have pushed the new message to the

8:42:22

array because we're logging out the

8:42:23

array with same here at the end. Now, a

8:42:28

little mini challenge before you leave.

8:42:30

Let's say that you wanted to regret

8:42:32

sending this message same here and you

8:42:35

wanted to remove it from the messages

8:42:37

array. How can you do that?

8:42:40

You haven't learned this yet, but this

8:42:42

is a golden opportunity for you to

8:42:44

Google it out and try to figure out how

8:42:46

can you remove the last item in an

8:42:48

array. So just see if you can find the

8:42:50

answer on Google and then try to remove

8:42:53

the last item of the messages array here

8:42:56

on line 18. Go ahead and do that right

8:42:58

now.

8:43:04

Okay, maybe that worked, maybe not. If

8:43:06

not, no worries at all. This is just a

8:43:09

bonus. What you do is do messages

8:43:13

dot pop and then open and close

8:43:16

parenthesis. Now

8:43:19

if we log the messages again and then

8:43:23

run the code, open up the console, you

8:43:26

can see we are logging two versions of

8:43:29

this array. one from line 15 where the

8:43:32

same hair string is included as the last

8:43:35

item and once again from line 19 where

8:43:39

the array is back to how it originally

8:43:41

was like this. So pop is kind of the

8:43:45

opposite of push and not as commonly

8:43:48

used but I just wanted to give you a

8:43:50

sneak peek at it as you might come

8:43:52

across it here and there in your

8:43:53

development journey. With that let's

8:43:56

move on.

8:44:00

Okay, now it's time for some repetition.

8:44:02

You are going to do the exact same thing

8:44:04

as I did before we had our little arrays

8:44:06

deep dive. So, you're first going to

8:44:08

create a new array cards that contain

8:44:11

the first card and the second card. And

8:44:13

then in the render game, you are going

8:44:15

to change line 18 so that it refers to

8:44:18

the cards array when rendering them out.

8:44:20

So, not referring to first card and

8:44:23

second card this way, but doing it via

8:44:25

our freshly created cards array. So go

8:44:28

ahead and do this right now.

8:44:34

Okay, let's do this together. First,

8:44:36

we'll do let cards equals open and

8:44:40

closed square brackets. And then we'll

8:44:41

set the first card as the first item in

8:44:44

the array and the second card as the

8:44:47

second item. And as you hopefully

8:44:49

remember, we can now refer to these

8:44:51

values by doing cards zero and cards

8:44:56

one. Like that. We'll run the code, hit

8:44:59

start game, and yes, indeed, it works.

8:45:02

Great job. Let's move on.

8:45:06

Now that we have the first card and the

8:45:08

second card in the cards array, we also

8:45:10

have to, of course, add the new card to

8:45:13

the cards array. So, quick little

8:45:15

challenge. After this card has been

8:45:17

created and it has been added to the

8:45:19

sum, we also need to push the card to

8:45:22

the cards array. So go ahead and do this

8:45:25

right now.

8:45:31

All right. The way to do this is by

8:45:33

writing cards dot push open and close

8:45:37

parenthesis and then pass in the newly

8:45:40

created card like that. And in order to

8:45:43

verify that this actually works, we can

8:45:44

on the next line console log out the

8:45:49

cards array like that. Let's run this

8:45:51

again. Start game. Hit new card. And

8:45:54

there we can see in the console now the

8:45:57

cards array has been logged out with all

8:45:59

the three cards 10, four, and six. So we

8:46:02

still aren't rendering out the third

8:46:04

card though. And to achieve that, you

8:46:07

have to learn how to count in

8:46:08

JavaScript. or strictly speaking, you

8:46:10

have to learn how to write for loops. So

8:46:13

over the next few casts, we are going to

8:46:14

take a deep dive into for loops and then

8:46:17

later return back to the blackjack game

8:46:19

so that we can fix it up. Let's move on.

8:46:26

Okay, so now you're going to learn how

8:46:27

to count with JavaScript. That might

8:46:30

sound really silly. I mean counting is

8:46:32

so easy. If you ask a human to count,

8:46:33

for example, if you say pier, count to

8:46:35

10. I would go, yeah, sure. 1 2 3 4 5 6

8:46:38

7 8 9 10. However, JavaScript is like

8:46:41

that annoying person who then replies

8:46:43

and said, "Well, where exactly do you

8:46:45

want me to start counting?" And by

8:46:47

counting to 10, do you mean including 10

8:46:49

or should I stop before 10? And also,

8:46:52

should I count every single number or do

8:46:54

you want me to, for example, only count

8:46:56

the odd numbers or the even numbers or

8:46:58

whatever? So, JavaScript is really like

8:47:00

that annoying person that takes

8:47:02

everything you say 100% literal. So when

8:47:06

you ask JavaScript to count, you have to

8:47:08

be super specific. We need to specify

8:47:10

where we start counting, where the

8:47:12

finish line is, and what the step size

8:47:14

is. Here, I've already written the code

8:47:17

for you. So let's just dissect it. We

8:47:20

start with the for keyword. That's

8:47:23

because this is a so-called for loop,

8:47:25

but don't worry about that. Let's now

8:47:27

look at the things that are inside of

8:47:29

the parenthesis here. Here you can see

8:47:31

our starting condition. Let count equals

8:47:34

1. So, we're going to start our count at

8:47:36

one. Then we have a semicolon. And then

8:47:39

we specify our finish condition where it

8:47:42

says count is less than 11. So, we want

8:47:46

count to always be less than 11. So,

8:47:49

maximum 10. In other words, we're never

8:47:51

going to count over this number. And

8:47:55

finally, the step size is that for each

8:47:58

counting, you're going to increment with

8:48:00

one. So, count plus equals 1. Now these

8:48:04

three conditions together describe to

8:48:06

JavaScript how many times we want to run

8:48:09

the code inside of the curly brackets

8:48:12

and what the value of count will be at

8:48:16

every single iteration. So here we are

8:48:18

going to run this code 10 times and the

8:48:21

variable count will change its value in

8:48:24

every single iteration starting at one

8:48:27

and going up to 10 jumping one number at

8:48:30

a time. So we will count to 10. Let's

8:48:34

run this code. And there you can see in

8:48:35

the console we get the numbers from 1

8:48:37

and up to 10. If we now change this here

8:48:41

to 2, what do you think will happen?

8:48:43

Well, then we get 1 3 5 7 9 because we

8:48:48

still start at one. We're going to end

8:48:50

before 11. So maximum 10 and we're going

8:48:53

to jump with two. So in the first

8:48:56

iteration, count equals to one. It's

8:48:58

what we said we wanted to start with.

8:49:00

But then in the second iteration, we've

8:49:02

told JavaScript that we want to increase

8:49:04

by two every single time. So then it's

8:49:07

three, and then it's five, and then it's

8:49:09

seven, and then it's nine, and then at

8:49:11

the last iteration, it's like, okay, now

8:49:13

I'm going to be 11. But uh that doesn't

8:49:17

work. That violates our finish condition

8:49:20

here. So JavaScript stops the loop

8:49:22

before that happens and then continues

8:49:25

on with whatever it has to do underneath

8:49:28

the loop. So let's take this back to

8:49:30

one. Can you modify this one so that it

8:49:34

counts from 1 to 20? How would you do

8:49:38

that?

8:49:41

Hopefully you identified that what you

8:49:42

want to change is the finish condition

8:49:45

and set that to less than 21. We run

8:49:48

this. You can see in the console that

8:49:51

we're logging out 1 to 20. Now, how

8:49:54

would we change this if we want to count

8:49:56

from 10 to 20? Go ahead and try that

8:49:59

right now.

8:50:05

Okay, hopefully you figured out that it

8:50:07

is the starting condition you want to

8:50:09

modify. You want to write 10 here so

8:50:12

that it starts at 10, ends before 21,

8:50:15

and counts one at a time. We run the

8:50:18

code. You can see we get from 10 to 20

8:50:20

logged out to the console. So hopefully

8:50:23

you've gained a little bit of intuition

8:50:24

on this. Now let's move on to the next

8:50:27

cast.

8:50:30

Okay, let's first walk through how to

8:50:32

create a loop from scratch. And then I

8:50:35

want you to create your own loop or at

8:50:37

least try according to the

8:50:38

specifications here on line three and

8:50:40

four. But to begin with, we'll create a

8:50:42

loop that counts from zero to five. So

8:50:45

to do that, we'll do four open and close

8:50:48

parenthesis. And then inside of the

8:50:49

parenthesis, we have to define our

8:50:51

starting point, our finish line, and how

8:50:54

big our steps will be. This is done

8:50:56

through a counter variable. So we could

8:50:58

do let count equals zero and then

8:51:02

semicolon to end the starting statement

8:51:05

because zero is where we want to start.

8:51:08

However, where's count is a very

8:51:09

semantically good word for this

8:51:12

variable, a common convention in

8:51:14

JavaScript is to use the letter I

8:51:16

instead.

8:51:18

We could have named it whatever we want.

8:51:20

And you can use count if you think

8:51:21

that's easier, but I'm going to use I

8:51:23

from now on. Then there's the finish

8:51:26

line which we also need to define. We

8:51:28

want to count to five. So I should be

8:51:31

less than six and then semicolon again.

8:51:35

So this defines that I should always be

8:51:38

less than six. And obviously then the

8:51:40

last point where it will stop when

8:51:42

counting upwards is five. And then

8:51:44

finally, we have to define how big our

8:51:47

step should be. And I'm going to do I

8:51:49

plus equals 1. And here we don't have to

8:51:53

use a semicolon to end because this is

8:51:55

the last condition. Actually, I can

8:51:59

space it out a little bit. We follow the

8:52:00

same structure for all of our

8:52:02

conditions. And then the open and closed

8:52:05

square brackets for the body of our for

8:52:07

loop. Then inside of here, we'll do

8:52:09

console.log

8:52:11

log I from the code and we can see 0 1 2

8:52:15

3 4 5. Good. Okay. Now that you've seen

8:52:19

this, I want you to try to create a for

8:52:21

loop that counts from 10 up to 100 in

8:52:25

steps of 10. So it should count 10 20 30

8:52:29

40 50 and so on including 100. And I

8:52:33

want you to use control log as I am

8:52:34

doing here to log out the count at each

8:52:37

step of the iteration. So go ahead and

8:52:39

do this right now.

8:52:46

Okay, hopefully that went well. If not,

8:52:48

no worries. Let's do this together. Loop

8:52:51

four. Let And here you might wonder if

8:52:55

well, we've already used the I variable.

8:52:57

Can we reuse it down here? And the

8:52:59

answer is yes. I is only defined inside

8:53:02

of the curly brackets of the for loop

8:53:04

when you do it like this. So outside of

8:53:06

it, for example, down here at line 8,

8:53:09

JavaScript won't remember this i

8:53:11

variable. So whatever you've configured

8:53:13

it to mean up here inside of the curly

8:53:15

brackets doesn't affect whatever you set

8:53:18

I to down here. So we can do let I again

8:53:21

equals 10. That's where we want to

8:53:22

start. I should be this time less than

8:53:26

not 100 because then it'll stop at 99.

8:53:29

It needs to be less than 101. And

8:53:31

finally I should not be plus= 1. Well,

8:53:34

should be plus equals 10 because at each

8:53:37

step in the iteration, you want to

8:53:38

increase I with 10. Console log I. I'm

8:53:43

going to comment this one out. Run the

8:53:46

code. And there we see 10, 20, 30, 40,

8:53:49

50, and so on all the way up to 100. So,

8:53:53

great job.

8:53:56

Okay, now you're going to experience how

8:53:59

powerful for loops are when combining

8:54:02

them with arrays because let's say that

8:54:04

we are building a chat application like

8:54:06

the one that LinkedIn has which I showed

8:54:08

you earlier and these messages might

8:54:10

just well be items in arrays. Let's just

8:54:14

pretend that each of these messages are

8:54:16

exactly that and ignore all the metadata

8:54:18

around the messages like the time and

8:54:21

the profile picture and name and stuff

8:54:22

like that and just pretend that we have

8:54:24

the data structure which contains a

8:54:26

bunch of messages inside of an array.

8:54:28

Basically just what we have here the

8:54:30

exact same array we've worked with

8:54:31

earlier as well. Now pretend that this

8:54:34

is a consolebased array. So everything

8:54:36

basically need to do is log out these

8:54:38

messages to the console. But in order to

8:54:40

do that, we can't just console log out

8:54:44

messages because then we'll just get a

8:54:46

long array and that's not what we want.

8:54:47

We want each of the messages on its own

8:54:50

line and not with the square bracket and

8:54:52

stuff like that around. So the hard way

8:54:54

to do this is by doing like this

8:54:58

messages one, messages two, messages

8:55:01

three, like to take the index from zero

8:55:04

to three and log all of them out. There

8:55:07

we go. Now we have what looks like a

8:55:09

chat in the console. But this is a

8:55:12

really bad way of doing it. We are

8:55:14

repeating ourselves again and again and

8:55:16

that's a general anti-attern. There's

8:55:18

something called dry for don't repeat

8:55:23

yourself. So don't write more code than

8:55:26

you need to and especially not if you're

8:55:28

just repeating the same code. And also

8:55:29

this doesn't scale because if I add now

8:55:32

at the end of the array and run the

8:55:34

code, I'm not logging out the last one.

8:55:37

I have to manually update my code. So

8:55:39

what we instead want to do is combine

8:55:42

this array with a for loop. Now let's

8:55:46

comment out this and write four. Let I

8:55:51

equals zero semicolon.

8:55:54

Then we want I to stop before it reaches

8:55:58

five. Then we want I to increment by one

8:56:03

at every single iteration. Now inside of

8:56:05

this for loop we log the value of i

8:56:10

see in the console that we get from zero

8:56:13

to four and that actually resembles

8:56:16

quite a lot what we did here. However,

8:56:19

we've even added the index of the latest

8:56:21

item as well. So, how about we instead

8:56:24

of just logging out I simply do messages

8:56:28

open square brackets close square

8:56:30

brackets

8:56:31

use the I as the index and then run the

8:56:35

code and boom there we go. We have all

8:56:38

of the items logged out in order one

8:56:42

after another. Brilliant. However,

8:56:44

there's still a little problem here that

8:56:46

if I add yet another message here, maybe

8:56:48

an emoji, and I run the code, the emoji

8:56:51

isn't logged to the console. Then I have

8:56:53

to change this to six again. So, it's

8:56:55

still not fully like dynamic. However, I

8:56:58

have a trick because how can I get a

8:57:01

hold of the number six in a dynamic way?

8:57:05

Well, you might remember that arrays has

8:57:09

a property which is called length and

8:57:13

that will refer to the actual length of

8:57:15

the array. If we use that, we can be

8:57:18

sure that our loop counts up to the

8:57:21

final index all the way up to the end of

8:57:23

the array. If we now run the code, yes,

8:57:27

there we have all of our messages

8:57:29

regardless of how long the messages

8:57:32

array is. So this was a lot of typing

8:57:34

from my end though. So let's move on to

8:57:37

a challenge so that you get to practice

8:57:39

this as well.

8:57:43

Okay. So now let's return back to the

8:57:46

example of having cards in an array like

8:57:48

we have in our blackjack game. So here

8:57:50

I've created an array that has three

8:57:52

cards of the values 7, 3, and 9. And I

8:57:55

want you to create a for loop that logs

8:57:58

out all of these cards to the console.

8:58:00

However, not by hard coding where the

8:58:03

loop should stop counting, but using the

8:58:05

cards.length property. So, go ahead and

8:58:09

do this right now and then I will of

8:58:11

course show you the solution as well

8:58:12

afterwards.

8:58:18

Okay, hopefully this went well. Let's do

8:58:20

it. We'll do four open and close

8:58:23

parenthesis and then let I equal zero

8:58:26

because we're going to start at the zero

8:58:29

index.

8:58:30

I should be less than cards dot and I

8:58:36

should be increased with one at every

8:58:37

step in the iteration. Now here for this

8:58:40

last condition, I actually want to show

8:58:42

you another trick because what you can

8:58:44

do here is actually do I ++ that'll do

8:58:48

the exact same thing as this. It's just

8:58:51

syntactical sugar that JavaScript

8:58:53

provides us with to make our code a

8:58:55

little bit neater.

8:58:57

So I ++ increment I with one. So now we

8:59:01

can do console log cards then passing in

8:59:05

the I run the code and there we can see

8:59:08

7 3 and 9 printed to the console. Great

8:59:12

job.

8:59:16

Okay, this is so cool because now you

8:59:17

are going to combine what you've learned

8:59:19

about arrays and for loops with what you

8:59:22

know about manipulating the DOM. So,

8:59:24

we're going to pull the strings together

8:59:26

and have you render out this sentence

8:59:28

inside of this greeting L. So, you can

8:59:31

see we have in our HTML just an empty

8:59:34

paragraph which has the ID of greeting

8:59:36

L. We have fetched that element from the

8:59:38

HTML and stored it in this greeting L

8:59:41

variable. And your job is to render the

8:59:43

sentence that is the array here. So, you

8:59:46

are to render all of these items inside

8:59:48

of the array in the greeting L

8:59:50

paragraph. And the way to do that is to

8:59:53

use a for loop to loop through it and

8:59:55

render each of them into the greeting L

8:59:58

using text content. So a lot of stuff

9:00:01

you have to keep track of here, but give

9:00:03

it your best shot and then I of course

9:00:04

will show you the solution when you

9:00:06

return back to this screencast.

9:00:12

Okay, hopefully that went well. Now

9:00:14

let's do this. We do four. Let I equals

9:00:18

zero because we want to start at the

9:00:20

zero index in our array. We'll do I is

9:00:24

less than sentence.

9:00:26

[Music]

9:00:27

And then we do I ++ because we want to

9:00:30

increment one time. Here we need to grab

9:00:34

a hold of the greeting L and then do

9:00:36

text content. And here you might have

9:00:39

been tempted to do equal sentence open

9:00:42

and close square brackets and passing in

9:00:44

the index. That will just end up with

9:00:46

rendering pair because first it renders

9:00:48

hello and then it clears out all of the

9:00:51

text content and renders the second

9:00:53

word. But then for every single time in

9:00:56

this loop it clears out all the text

9:00:58

content and we end up with just the

9:01:01

result after the last iteration and that

9:01:03

was the last word in the array. So what

9:01:06

we have to do we have to keep the

9:01:07

previous content intact inside of the

9:01:10

paragraph and as you might remember we

9:01:11

do that with plus equals. So running the

9:01:14

code again. Yes, now it works. Now

9:01:16

though I have a bonus challenge for you,

9:01:18

which is the following. How do you keep

9:01:20

the spaces between the words if I remove

9:01:23

these spaces from the array? That is if

9:01:26

I do like this, like this, like this,

9:01:28

and like this. And we render it out. You

9:01:31

can say, ah, we have no more spaces. It

9:01:34

looks like one long weird word. How can

9:01:36

we on this line seven modify it so that

9:01:39

we get spaces between the words? Go

9:01:41

ahead and try that.

9:01:47

Okay, what we will do is we'll simply at

9:01:50

the end here add a plus and concatenate

9:01:54

our given item in the array with a

9:01:58

space. So now we add a space after each

9:02:01

of the words. If we render this, you can

9:02:03

see yes, we get now the sentence exactly

9:02:06

how we want it. Great job. Let's move

9:02:09

on.

9:02:13

Okay, back at our blackjack game. It's

9:02:15

time for you to create a for loop that

9:02:18

renders out all the cards in the cards

9:02:20

array instead of just the two first ones

9:02:22

which we are doing up here. So you are

9:02:25

going to start your for loop down here

9:02:27

at line 19. I'm going to help you out a

9:02:30

little bit because we are going to keep

9:02:32

this first setting of the text content

9:02:35

here so that we have the default text

9:02:37

inside of the paragraph. And then you

9:02:40

are going to render out the cards after

9:02:43

this text inside of the paragraph. Go

9:02:45

ahead and create that for loop so that

9:02:47

our black deck game supports any number

9:02:49

of cards inside of the cards array and

9:02:52

will render all of them out regardless

9:02:54

of how many it is. So give it your best

9:02:56

shot and return back to me when you want

9:02:58

to see my solution.

9:03:04

Okay, hopefully that went well. If not,

9:03:06

no worries. We'll do it together. We'll

9:03:09

start with four and then open and close

9:03:11

parenthesis. Of course, inside of the

9:03:12

parenthesis, we need to define that we

9:03:14

want to start our incrementer at zero

9:03:18

and we want to stop it before it reaches

9:03:20

the length of the cards array. How do we

9:03:23

do that? Well, by I is less than cards.

9:03:29

And then a semicolon and we want to

9:03:31

increment i at every iteration. The body

9:03:35

of the for loop with curly brackets.

9:03:37

Here we are going to plus equal onto

9:03:40

this paragraph. So we'll do cards l.ext

9:03:44

content plus equals. Let's start by just

9:03:47

adding the cards and then passing in the

9:03:50

current value of I our iterator which

9:03:53

will start at zero and to begin with end

9:03:57

before two. So it'll be 0 1 and then run

9:04:00

the code start game and yes it works.

9:04:03

However, it looks like it says 104 here

9:04:07

because we haven't added a space between

9:04:09

our numbers. So the way to do that is

9:04:11

simply by concatenating

9:04:14

a space after vin card. Now if we run

9:04:17

it, start game. Yes, we've got it. And

9:04:20

if we hit new card, now we can see both

9:04:23

the sum and the cards are now correct

9:04:25

according to the state of our game.

9:04:28

Great job. Let's move on.

9:04:33

Okay, so our blackjack game is actually

9:04:35

turning out pretty good now. Can start

9:04:37

the game. We can hit a new card. 20. I

9:04:40

can even hit yet another card. Boom. Ah,

9:04:42

I'm out of the game. It's It's almost

9:04:44

fun to play, though, you'll get pretty

9:04:46

tired of it as you play it multiple

9:04:48

times since you every single time get

9:04:50

the exact same cards. So, not exactly an

9:04:53

exciting blackjack game. And of course,

9:04:54

that is because we have hard-coded the

9:04:56

variables for our first card and second

9:04:58

card here and also hard-coded value for

9:05:02

our third and fourth and every preceding

9:05:04

card here on line 40. So we'll always

9:05:06

get 10 4 6 66 66 66 66 66 66 66 66 66 66

9:05:08

666 and so forth. So what we need to do

9:05:12

is instead create a function get random

9:05:14

card that returns a random number so

9:05:18

that we instead of hard- coding the

9:05:20

number 10 up here on line one, we can do

9:05:22

get random card and call that function.

9:05:26

This function will then return a random

9:05:28

card that the first card variable will

9:05:30

be set to. And we can do the same with

9:05:33

the second card. And also down here in

9:05:36

the new card function, we can do get

9:05:38

random card there as well. This way we'd

9:05:40

get a functional blackjack game.

9:05:43

However, there's a few things you

9:05:44

haven't learned yet which you need to

9:05:45

learn in order to create this get random

9:05:47

card function. So let's rewind a little

9:05:50

bit here. Get back to the hard-coded

9:05:52

numbers. And over the next few casts,

9:05:54

you're going to learn how to return

9:05:56

values in functions and also how to

9:05:59

generate random numbers inside of a

9:06:01

function. So let's go ahead and do

9:06:03

exactly that.

9:06:07

Okay, let's return back to our racing

9:06:10

game example in order to learn about

9:06:11

returning values in functions. So here

9:06:14

we have two players who've raced through

9:06:16

the game and player one got the time 102

9:06:19

and player two got the time 107. And our

9:06:22

job is to create a function that returns

9:06:24

the fastest race time. So in order to do

9:06:27

that, we first have to do function. I'm

9:06:29

going to call this get fastest

9:06:32

base time. Quite a long word, but at

9:06:35

least it's descriptive. And inside of

9:06:37

the body of the function, we have to

9:06:38

first check which of these times were

9:06:41

fastest. So we'll do an if statement and

9:06:43

say if player one time is less than

9:06:47

player two time well then we are going

9:06:50

to return

9:06:52

player one time

9:06:55

because if it's less than player two

9:06:57

then it's the fastest race time and we

9:06:59

are going to return it. Now this return

9:07:02

keyword here might now seem a bit weird

9:07:05

and you probably don't understand yet

9:07:06

what it means but don't worry about that

9:07:08

right now. It'll be clearer as we move

9:07:09

on. And then we're going to do else if.

9:07:13

The next condition is if player two was

9:07:15

faster than player one. That is player

9:07:17

two time is less than player one time.

9:07:22

If so, we are going to return player two

9:07:25

time like that.

9:07:27

Then an else if actually these two are

9:07:31

equal. So none of these expressions

9:07:34

evaluate to true. Well, then the fastest

9:07:37

time is any player's time because they

9:07:39

had the exact same time. We either

9:07:41

return player one time or player two

9:07:43

time. It doesn't matter. I'm just going

9:07:44

to return player one time. Okay. Now,

9:07:48

what we can do is we can do let fast as

9:07:52

race. I'm going to call this variable

9:07:53

that. And now I'm going to define that

9:07:56

declare that variable as the result of

9:08:00

invoking this function. So I'm going to

9:08:03

do get fastest race time like that.

9:08:07

Now the value of fastest race time will

9:08:10

be whatever this function has returned.

9:08:13

And if we console log as this race time

9:08:17

we can see we get 102. That's correct

9:08:21

because this function compared player

9:08:23

one and player two and rightfully

9:08:25

recognized that player one was faster

9:08:28

than player two and thus returned player

9:08:30

one time. What you might think now is,

9:08:32

well, we're just console logging out the

9:08:34

value here. What's the point? Why

9:08:36

couldn't we just instead of these

9:08:38

returns just do console

9:08:41

log and do that directly inside of the

9:08:44

function? Do that first and run it. You

9:08:48

can see yes, we are now indeed running

9:08:51

this line six here. We're console

9:08:52

logging out the value. But if we down

9:08:55

here try to see what is the value of

9:08:59

fastest race at this point and run the

9:09:01

code, you can see that we're getting 102

9:09:03

first from this line, but then we're

9:09:05

getting undefined from line 16 because

9:09:08

now the fastest race variable simply

9:09:11

isn't defined because this function

9:09:13

didn't return anything. And it's

9:09:15

actually quite valuable to have stored

9:09:17

the fastest race time inside of this

9:09:19

value as opposed to just having console

9:09:22

logged it out up here cuz now we can use

9:09:24

this variable for something else. So

9:09:27

let's do like this and return instead

9:09:31

and move over and remove the parenthesis

9:09:34

as well. Wondering how I got the cursor

9:09:36

to be on multiple lines at the same

9:09:38

time. It's a trick where you first

9:09:41

select a word and then do command D or

9:09:45

if you're not on a Mac control + D.

9:09:48

Select the word command D one two times.

9:09:51

And now I have selected all of the

9:09:53

return keywords so that I can delete

9:09:56

them or retype them. That was just a

9:09:59

quick little tip. Now it's time for a

9:10:01

challenge.

9:10:02

So you are going to write a function

9:10:04

that returns the total race time. Then

9:10:07

you are going to call or invoke the

9:10:09

function and then store the returned

9:10:10

value in a new variable. You have to

9:10:12

decide for yourself what you want to

9:10:14

call that variable and what you're going

9:10:15

to call this function. Then finally you

9:10:17

are going to log your variable out just

9:10:19

to check that everything has worked. So

9:10:21

go ahead and do this right now.

9:10:28

Okay. Hopefully this went well. Let's do

9:10:30

this. audio function get total race time

9:10:37

and the way to do that is simply to

9:10:39

return player one time plus player two

9:10:43

time. Then we can create a new variable

9:10:45

called let

9:10:47

total time equals get total race time.

9:10:54

And now we can console log total time

9:10:58

like that. Running the code and indeed

9:11:00

we get 209 in the console which sounds

9:11:03

just about right. So great job. Let's

9:11:06

move on.

9:11:10

Okay, it's time to take what you've

9:11:11

learned about returning values and

9:11:13

functions and implement that technique

9:11:15

into our app. This is a three-part

9:11:18

challenge. First, you're going to create

9:11:20

a function get random card that always

9:11:23

returns the number five. And then you're

9:11:25

going to use get random card to set the

9:11:28

values of the first card and the second

9:11:30

card. And then use it to set the value

9:11:33

of the card variable down here in the

9:11:35

new card function as well. So you are

9:11:37

going to write your function get random

9:11:39

card here starting on line 14. And now

9:11:43

you might think, well, that doesn't make

9:11:44

sense because we've previously learned

9:11:46

that if you defined a variable down here

9:11:48

on line 14, we can't use it up on line

9:11:51

two and three. That's at least how it is

9:11:54

with variables you define using the let

9:11:56

keyword. And that is exactly right. But

9:11:58

when you create functions in the way we

9:12:00

do, there's an exception. So I want you

9:12:02

to just try this and see if it works.

9:12:05

And then I'm going to explain afterwards

9:12:06

why it works. Go ahead and give this

9:12:08

your best shot. and then I will show you

9:12:10

the solution as well afterwards.

9:12:17

Okay, hopefully that went well. Now

9:12:19

let's do this. We'll do function get

9:12:22

random card like that. Then inside of

9:12:26

the body of the function, we'll simply

9:12:28

return five. We need to use this up here

9:12:32

at line two

9:12:34

get random card and on line three get

9:12:37

random card. So what's happening here is

9:12:40

that we're calling this function it will

9:12:43

return five and thus second card and

9:12:45

first card will be initialized with a

9:12:47

value five as will our card down here.

9:12:51

If we do get random card and call it

9:12:55

these two really important otherwise it

9:12:57

won't work but with them card will now

9:12:59

have the value five. So let's run our

9:13:03

blackjack game. Start the game. Ooh we

9:13:05

got two fives. Ah yet another five.

9:13:08

What's the chance? Obviously, it is 100%

9:13:11

at the moment, but that doesn't matter

9:13:13

because we now have the setup for inside

9:13:16

of this function writing the logic for

9:13:18

getting an actual random card back. So,

9:13:21

that's great. Finally, I promised to

9:13:24

talk a little bit about the fact that

9:13:25

we're creating the function down here on

9:13:27

line 14 and then using it up on line

9:13:29

two. That seems to go against what we

9:13:31

learned about variables early on.

9:13:33

However, when you write functions like

9:13:35

this, which is called function

9:13:36

declarations, the function gets

9:13:39

so-called hoisted to the top, meaning

9:13:41

that it's accessible even at line one.

9:13:43

Regardless of how far down you define

9:13:45

the function, we could have written this

9:13:47

function on line 10,000. It would still

9:13:50

be accessible on line one. Now, there

9:13:52

are other ways of creating functions

9:13:54

that don't give the function this extra

9:13:56

benefit. But as for now, we're only

9:13:58

going to write functions in this way. So

9:14:00

don't worry about that because now you

9:14:02

have another thing to worry about and

9:14:03

that is how do we actually modify this

9:14:06

get random function so that it actually

9:14:08

returns a random card. So from the next

9:14:11

lesson on we are going to dive into

9:14:13

exactly how to do that. I'll see you

9:14:15

there.

9:14:19

So I remember when I was learning this

9:14:21

slightly clunky way of generating random

9:14:23

numbers in JavaScript and thinking well

9:14:26

why do I really need to generate random

9:14:28

numbers? Is that really such a common

9:14:30

thing to do for developers? And

9:14:32

actually, it is. Of course, there's our

9:14:34

use case where we're building a card

9:14:36

game. Obviously, we need to have some

9:14:38

kind of randomness in which card you

9:14:39

get, otherwise it would be meaningless.

9:14:41

But also, imagine all games that use

9:14:43

dices. A dice is basically a physical

9:14:46

randomness function that gives you

9:14:48

random number between 1 and six. But

9:14:50

randomness isn't only important in these

9:14:52

kind of casino-ish games. I would say in

9:14:54

all computer games, randomness plays

9:14:56

some kind of role. For example, in this

9:14:59

popular iPhone game, Crossy Road, where

9:15:01

you are to cross a road as a duck

9:15:03

without getting hit by a car. Surely,

9:15:05

there's some randomness underneath here,

9:15:07

which decides which cars appear on the

9:15:09

road and also when they appear. But it

9:15:11

doesn't stop there with games. Actually,

9:15:13

in cyber security, random numbers is a

9:15:16

key component in order to authenticate

9:15:18

yourself and generate keys as within

9:15:20

cryptocurrencies. So, for example,

9:15:22

Bitcoin uses random numbers as well. So

9:15:24

random numbers plays a role in the

9:15:26

crypto economy as well. And most

9:15:28

importantly, we used random numbers in

9:15:30

order to generate the suggested tweet

9:15:32

text in our JavaScript advent calendar.

9:15:36

So as you can understand, random numbers

9:15:38

are everywhere and you need to learn the

9:15:41

most basic way of generating that in

9:15:43

JavaScript and that is through something

9:15:46

that we call the math object. That's

9:15:48

something that's already provided to you

9:15:50

in JavaScript or by the browser to be

9:15:53

specific. And you can type math wherever

9:15:56

you want with a capital M and then do

9:15:59

dot random and then open and close

9:16:01

parenthesis so that you call this

9:16:03

function or method. And don't worry if

9:16:05

you don't quite understand what's going

9:16:07

on under the hood here. You're not meant

9:16:08

to do that right now. All you're meant

9:16:10

to know is that that will return a

9:16:12

number to you which I've now stored in a

9:16:15

variable called random number. And then

9:16:17

I'm logging out this random number. What

9:16:20

I want you to do now is pause this

9:16:22

screencast and run this code a few times

9:16:24

so that you get to see a few of the

9:16:26

values that our random number variable

9:16:28

can take and then try to as succinctly

9:16:32

and specifically as possible. Write your

9:16:34

answer at what you think math.random

9:16:37

does. So what does it return? Try to

9:16:40

formulate that and write it down and

9:16:42

then return back to the screencast when

9:16:44

you think you have the answer.

9:16:50

So the way I would write this is that it

9:16:54

generates

9:16:56

a random number between zero and one and

9:17:02

then parenthesis

9:17:03

not inclusive of one. So it generates a

9:17:06

random number including zero and one but

9:17:09

not including one. So from 0

9:17:13

0 to 0.9999999999

9:17:16

and a bunch of nines after that. So if

9:17:19

we were to visualize this slightly say

9:17:22

that math.random gives you a number from

9:17:24

0.0000 and a bunch of zeros after that.

9:17:28

I just didn't couldn't bother writing

9:17:29

all of them to 0.999999999.

9:17:33

Basically a bunch of nines as well. That

9:17:35

is the range you are given when you give

9:17:38

JavaScript this command. So if we run

9:17:41

this,

9:17:43

you can see we get 0.68 and a bunch of

9:17:46

numbers. 0.95 and a bunch of numbers.

9:17:49

0.88 0.001. Yeah, as you can see, we've

9:17:53

already been almost from very close to

9:17:55

zero to very close to one. Now before we

9:17:59

go, there's one thing I need to point

9:18:00

out, which is that the randomness here,

9:18:02

while it looks completely random for us

9:18:05

humans, it's not truly random. There is

9:18:08

some deterministic variables going on

9:18:11

under the hood here. And it's actually a

9:18:12

really hard problem in computer science

9:18:15

to generate truly random numbers. But

9:18:18

for our use cases, we're not going to

9:18:19

worry about that. As far as weak here,

9:18:21

these numbers that we generate with

9:18:22

math.random are more than random enough

9:18:25

for our use case. This is not a PhD in

9:18:28

cyber security but but rather getting

9:18:30

you started with web development. So

9:18:32

with that let's move on.

9:18:37

Okay. So now we know how to create a

9:18:39

random number between zero and up to but

9:18:42

not including one. However, it's not

9:18:44

entirely clear how we utilize

9:18:46

math.random in order to create something

9:18:49

useful like for example a dice function.

9:18:52

So let's take this one step at a time

9:18:54

towards creating such a function. And

9:18:57

the first step we're going to take is

9:18:58

simply by multiplying

9:19:01

math.random with six. Now I want you to

9:19:04

do the same thing that you did

9:19:06

previously which is to pause the

9:19:08

screencast, run this code a few times

9:19:10

and see what we log to the console and

9:19:12

then answer the following question. In

9:19:14

which range will our random number be

9:19:17

now? So from which number to which other

9:19:21

number? It used to be from 0 to 0.99999.

9:19:25

Now it's something else and you have to

9:19:27

figure that out. So go ahead and do that

9:19:29

right now.

9:19:35

Okay, the answer is that it still starts

9:19:38

at zero. It now goes all the way up to

9:19:41

5.99999

9:19:43

and a bunch of nines. I'm not going to

9:19:45

type all of them. So if math.random gave

9:19:48

us a number from 0 to 0.999, math.random

9:19:52

* 6 will give us a number from 0 because

9:19:55

0 * 6 is still 0 to 5.999

9:20:00

because 0 bunch of 9 * 6 is not entirely

9:20:05

six, but it's almost six. So it's 5 a

9:20:08

bunch of nines. So now we have kind of

9:20:10

expanded our range roughly speaking from

9:20:12

being between 0 and 1 to being between 0

9:20:15

and six. We did that by multiplying it

9:20:18

with six. Let's move on to the next

9:20:20

step.

9:20:24

Okay. So now we need to learn another

9:20:26

method on the math object and that is

9:20:29

math.f floor. floor does is it takes

9:20:33

some input a number and then does

9:20:35

something with that number and returns

9:20:37

it so that you can store that in a new

9:20:39

variable for example like floored number

9:20:41

right here that is the floored version

9:20:43

of this number so I want you to pause

9:20:46

the screencast run this code a few times

9:20:49

and answer the question what does math

9:20:51

floor do to positive numbers and the

9:20:54

reason I'm saying positive numbers is I

9:20:56

don't want you to add negative numbers

9:20:57

in here because the mental model is

9:20:59

slightly easier if you only think about

9:21:01

positive numbers and it's a bit easier

9:21:02

to write a concise answer to it in my

9:21:05

opinion. And finally, I've never used

9:21:06

math floor on negative numbers anyway.

9:21:09

It's usually used on positive numbers.

9:21:11

So try this. Feel free to add a few

9:21:13

different numbers in here and run the

9:21:15

code. And once you're ready, just type

9:21:17

out your personal explanation of what

9:21:19

you think math floor does. Go ahead and

9:21:21

do this right now.

9:21:26

Now the way I think of math floor is

9:21:28

that it simply removes

9:21:31

the decimals because if we run this you

9:21:34

can see it returns three. If we have

9:21:36

12.4

9:21:38

12 even 12.99999

9:21:42

still 12. Okay. So great job. With that

9:21:45

knowledge in mind let's move on to the

9:21:47

next lesson.

9:21:51

Okay. So just as a quick recap,

9:21:54

math.random gave us a number between 0

9:21:56

and almost 1. And math random * 6 then

9:22:00

gave us a number between 0 and almost

9:22:03

six. And now we are going to combine

9:22:05

this with math.f floor which you learned

9:22:08

in the previous lesson. I'm going to add

9:22:10

it here. I'm going to write math.f floor

9:22:13

and then wrap our entire previous

9:22:16

expression inside the parenthesis of

9:22:18

math floor. Now, what I want you to do

9:22:21

is run this code a few times and then

9:22:24

write down possible values that random

9:22:27

number now can hold. So, there's a

9:22:30

limited number of them and your job is

9:22:32

to figure out exactly which ones. So, go

9:22:34

ahead and do this right now.

9:22:41

Okay, hopefully that went well. Now,

9:22:43

let's run this together. You can see we

9:22:46

got four four 0 1 4 0 2 5 H. Okay. So it

9:22:55

seems we are getting the numbers between

9:22:57

0 and five. That actually makes a lot of

9:23:00

sense because if we take this range here

9:23:03

between 0 and almost six and shove it

9:23:06

into the math.f floor function then it

9:23:09

will basically remove all of the

9:23:10

decimals. And if we remove the decimals

9:23:13

from from this entire range, which

9:23:15

numbers are we then left with? That's

9:23:17

just the whole numbers from zero all the

9:23:19

way up to five. So the right answer was

9:23:23

0 1 2 3 4 5 like that. Okay, hopefully

9:23:26

you're still hanging on. Let's move on

9:23:28

to the final step of our dice function.

9:23:34

Okay, now we are going to complete our

9:23:36

dice feature because we know that with

9:23:38

this expression currently get a whole

9:23:41

number from 0 up to 5. So the question

9:23:44

then remains how do we turn this range

9:23:46

into rather a range between 1 and six

9:23:49

which is essentially the same as a dice.

9:23:51

And I want you to try this for yourself.

9:23:53

Try to modify the expression so that we

9:23:56

get a range from 1 to 6 instead of 0 to

9:23:59

5. Go ahead and give that a shot right

9:24:01

now.

9:24:07

Okay, hopefully that went well. To

9:24:10

understand what we need to do, we can

9:24:11

compare each of the numbers here. We can

9:24:13

see that the first number here is one

9:24:16

and the first number there is zero. And

9:24:18

how do we go from 0 to one? We add one.

9:24:22

And the same goes for all of the numbers

9:24:24

here. How do we go from 1 to two? Well,

9:24:26

we add one. And from 5 to 6, we add one.

9:24:29

So basically what we can do is just do

9:24:31

plus one at the very end. Then if we run

9:24:34

the code you see we get two we get six 3

9:24:39

5 6 2 1. Yes, we indeed get the entire

9:24:44

range of a dice. So really good job

9:24:47

reaching this far. Now I only have one

9:24:49

last challenge for you and that is to

9:24:53

create a function called roll dice that

9:24:55

returns a random number between 1 and

9:24:57

six. So basically, you're going to take

9:24:59

what we've done here and wrap it into a

9:25:02

function and then return the result. Go

9:25:04

ahead and do that.

9:25:09

Okay. To do this, I'll do function roll

9:25:13

dice open and close parenthesis open and

9:25:16

close brackets. And inside of here, I'm

9:25:18

just going to copy this line,

9:25:21

paste it in, and then return

9:25:25

random number like that.

9:25:27

Now I have to remove it from up here

9:25:29

because out here on line two random

9:25:31

number isn't even defined. So we can't

9:25:33

log it out. Random number is now only

9:25:36

defined inside of the roll dice function

9:25:38

and the value of it gets returned. So if

9:25:41

we console log and inside of the

9:25:45

parenthesis we call the roll dice

9:25:47

function like that should get yes a

9:25:52

random number between 1 and six. really

9:25:56

good job reaching this far. This was

9:25:58

complicated stuff. So, if you feel a

9:26:00

little bit shaky with this, that's

9:26:01

totally okay. You can go back and

9:26:03

rewatch it and retry all of the

9:26:04

challenges if you want to. And then when

9:26:06

you feel ready, we'll move on and use

9:26:08

this knowledge to make our blackjack

9:26:09

game much better.

9:26:14

Okay, we're back at our blackjack game

9:26:16

and we are going to fix up this get

9:26:18

random card function, but we'll do it

9:26:20

step by step. So to begin with I want

9:26:23

you to make it return a random number

9:26:25

between 1 and 13. So here you can

9:26:29

pretend that we are working with the

9:26:30

regular values that a deck of cards

9:26:32

usually has. So with the ace being the

9:26:35

one, the numbers from 2 to 10 of course

9:26:38

being their respective numbers and then

9:26:40

the jack being 11, queen being 12 and

9:26:42

king being 13. So from 1 to 13 like

9:26:46

this. Go ahead and give this your best

9:26:49

shot and then of course I will show you

9:26:51

how to do it afterwards as well.

9:26:59

Okay, now let's do this. We know that if

9:27:01

we do math random, we are going to

9:27:04

generate a number between 0.0000

9:27:07

and a bunch of decimals after that up

9:27:10

until 0.999 and a bunch of nines after

9:27:13

that as well. So the first thing we need

9:27:15

to do in order to get this range to look

9:27:18

more like this one is to multiply this

9:27:21

entire thing with 13. 0

9:27:24

* 13 is still 0

9:27:28

is still 0 and 0.999 * 13 is actually

9:27:32

just 12.99

9:27:35

or we have a bunch of nines after that

9:27:36

as well. So we're getting to something

9:27:38

remotely similar. It's just a matter of

9:27:40

how many nines we have after the dot.

9:27:42

that this is roughly the range we're

9:27:44

working with with this expression right

9:27:46

here. So, we want to remove the

9:27:49

decimals. And how do we do that? Well,

9:27:51

if you remember from previously, we can

9:27:52

use the math.f floor function and wrap

9:27:56

the entire thing inside of the

9:27:58

parenthesis of math.f floor. So, now we

9:28:01

take this expression here, this one, and

9:28:04

we then floor it, which gives you like

9:28:07

that and like that. So 0 to 12, that's

9:28:12

what we're returning here. Now the

9:28:14

question remains, how do we go from 0 to

9:28:16

12 to 1 to 13? Well, that's only a

9:28:19

matter of adding a 1 to any given

9:28:21

number. We just do like that. And that

9:28:24

should return a number between 1 and 13.

9:28:26

Let's try to start this game and pull a

9:28:28

bunch of cards to see if we actually get

9:28:30

the entire range. 7. Four. Looking good

9:28:32

so far. 10. Okay. 13. Yes. Five. A bunch

9:28:36

of other numbers. Getting way too many

9:28:39

numbers here. Let's get that one. Yes,

9:28:41

there we got it. A one. So, we have the

9:28:43

entire range from 13 to one and just

9:28:46

about everything in between. This was

9:28:48

not a normal blackjack round, but at

9:28:50

least prove the point that this

9:28:52

generates random number between 1 and

9:28:55

13. So, great job reaching this far, but

9:28:57

of course, we have to modify it because

9:28:59

in blackjack, we're not following the

9:29:01

usual value sequence for cards. So, we

9:29:04

need to modify our function a little

9:29:05

bit, but we'll do that in the next cast.

9:29:11

Now, we need to change our get random

9:29:13

card function because in blackjack, the

9:29:15

jack, queen, and king are all worth 10,

9:29:18

and the ace is worth 11. Or strictly

9:29:20

speaking, the ace can be worth both 1

9:29:23

and 11. You get to choose as a player.

9:29:25

What suits you best is the value you

9:29:27

use. However, for the sake of

9:29:29

simplicity, we are just going to treat

9:29:31

the ace as 11 in our case as having a

9:29:35

dual value for this card would add a lot

9:29:37

of complexity to our game and it's not

9:29:39

something I want to focus on. It's

9:29:40

rather something you can for example do

9:29:42

as a stretch goal later if you want to

9:29:44

modify the game at the end of this

9:29:46

course. So, for now, we're going to

9:29:48

treat our ace as 11. So, this means we

9:29:50

need to modify our get random card

9:29:52

function. If the number it returns is 1,

9:29:55

then we should change it to 11. And

9:29:56

likewise, if the number it returns is

9:29:58

either 11, 12, or 13, we should rather

9:30:01

return 10. So go ahead and modify this

9:30:04

function so that these exceptions are

9:30:06

followed.

9:30:12

You're going to have to define a

9:30:13

variable that this random number is

9:30:15

stored in and also have some kind of

9:30:17

conditional that checks for these

9:30:19

conditions and returns the appropriate

9:30:22

value. So go ahead and give this a shot

9:30:24

and then I will of course show you the

9:30:25

solution afterwards as well.

9:30:32

Okay, hopefully that went well. If not,

9:30:34

no worries. We'll do it together. First,

9:30:36

I'm going to instead of returning this

9:30:38

directly, turn it into our random number

9:30:42

like that. Then we need to write our

9:30:44

conditional to account for these special

9:30:46

cases. I'm going to start from the very

9:30:49

top and check if random number is more

9:30:52

than 10 meaning that card is either the

9:30:54

jack, queen or the king. So if random

9:30:58

number is more than 10, what are we

9:31:01

going to return then? Well then we are

9:31:03

going to return 10 because that is the

9:31:06

value of the jack, queen and king. Then

9:31:08

I'm going to do else if and now I'm

9:31:11

going to count for the ace itself and

9:31:13

for that I'm going to use the triple

9:31:15

equals. So I'll do random number triple

9:31:18

equals 1 and I'm going to return 11.

9:31:22

Then in all other cases just do else

9:31:25

like that. In all other cases it must

9:31:27

mean that we have drawn either 2 3 4 5 6

9:31:30

7 8 9 or 10. And if so we're just going

9:31:33

to return that value. So then we're just

9:31:35

going to return the random number

9:31:38

directly like that. Let's run the code.

9:31:41

Hit start game. Okay 55. I'm going to

9:31:44

just hit a bunch of cards to see that we

9:31:46

get the entire range. And indeed, it

9:31:47

seems that we does. We have a two here.

9:31:49

We have an 11 here. And have almost

9:31:51

every single word in between. I'm 100%

9:31:54

sure that if we continue hitting the new

9:31:56

card, in the long run, we'll just get

9:31:57

random numbers across our entire defined

9:32:00

range. So, great job. We're almost

9:32:03

reaching the end of our blackjack game.

9:32:05

You should really be proud of yourselves

9:32:06

for reaching this far. This is starting

9:32:08

to get advanced. There's even more to

9:32:10

learn. So, let's just keep up the pace

9:32:12

and move on.

9:32:15

Okay, there's one really weird thing

9:32:17

with our blackjack game, and that's

9:32:19

easily exposed. If we console log out

9:32:22

the cards here at line 12, and then

9:32:25

refresh the page, there we can see I got

9:32:27

two and seven. And the reason that's

9:32:29

weird is because I haven't even clicked

9:32:31

the start game button. I've kind of just

9:32:33

entered the casino and the casino has

9:32:35

already decided what cards I am to be

9:32:37

dealt. That's fishy. We don't want that.

9:32:39

I want the cards to be generated as I

9:32:41

click on the start game button. So the

9:32:44

first card and the second card should be

9:32:46

generated inside of the start game

9:32:48

function. And thus the cards and the sum

9:32:51

also needs to be reassigned inside of

9:32:53

the start game function. And also the is

9:32:55

alive shouldn't be set to true by

9:32:57

default before I've even clicked the

9:32:59

start game button. I'm not alive. I'm

9:33:01

not even playing the game. I'm going to

9:33:03

use that as an example and set it to

9:33:05

false first. Then inside of the start

9:33:07

game function, I'm going to do is alive

9:33:11

equals true. So now we have the correct

9:33:14

starting state before I've entered the

9:33:16

game up here on line six and the correct

9:33:18

value once I've started the game down on

9:33:21

line 26. So what I want you to do is

9:33:24

make it so that the same thing happens

9:33:26

with cards array because it should not

9:33:28

be set here and the first and second

9:33:31

card shouldn't even be defined up here

9:33:33

and the sum should be zero by default.

9:33:37

So this is how the state of the game is

9:33:39

before I've started playing the game.

9:33:41

Now, what you need to do down here at

9:33:43

line 23 and 24 is generate the two

9:33:46

random numbers, then reassign the cards

9:33:49

and some variables so that the game can

9:33:51

start. So, you might find this a bit

9:33:53

tricky, but do your best. There's no

9:33:55

shame in trying and failing cuz I will

9:33:58

of course also show you how to do it

9:33:59

when you return back to this cast. Good

9:34:02

luck.

9:34:07

Okay, let's do this.

9:34:09

We'll start by defining first card and

9:34:11

second card. And they should be defined

9:34:14

by running the get random card function.

9:34:16

That'll give them the get random card

9:34:18

function. Second card equals card as

9:34:22

well. Now we can set the cards array to

9:34:25

first card

9:34:29

and second card and the sum to first

9:34:33

card plus second card like that. And

9:34:38

also actually

9:34:39

get this console logged back in again

9:34:43

and rerun the browser. You can see now

9:34:45

it's empty. The casino hasn't decided

9:34:47

which cards I am to get. Very good. So,

9:34:49

we hit start game and there I got my

9:34:51

black sack. Oh my god, that's amazing.

9:34:53

And with that, I have nothing more to

9:34:55

say. I'll see you in the next cast.

9:35:01

The next thing I want to fix is our new

9:35:03

card button because it's kind of broken.

9:35:05

Let's see why. If I now start the game

9:35:08

and I get two cards and I draw a third

9:35:10

card and a fourth card and oh, I'm out

9:35:12

of the game. At this point, I shouldn't

9:35:14

be able to draw more cards. But

9:35:15

actually, I am. I can hit it. And I got

9:35:17

another 10. So, I'm at 34. Shouldn't be

9:35:20

possible to get to that number in

9:35:22

blackjack. So, we need to stop it when

9:35:24

the game is over. And also, if we

9:35:27

refresh the browser able to I shouldn't

9:35:29

be able to start with just one card

9:35:31

either, but I actually can. So, there's

9:35:33

two conditions we need to check. both if

9:35:36

I'm still in the game basically if the

9:35:38

is alive is true and also I can't have

9:35:41

blackjack either. Now this requires us

9:35:43

to learn something called logical

9:35:45

operators which lets you combine

9:35:48

multiple conditions inside of an if

9:35:50

statement. So that a piece of code

9:35:51

should only be run if multiple

9:35:53

conditions are satisfied. So let's take

9:35:55

a little detour and learn about logical

9:35:58

operators in the next casts.

9:36:02

Okay, let's learn about logical

9:36:04

operators. Here we have a little bit of

9:36:07

boilerplate code, namely two variables

9:36:09

and a function. And the imagined

9:36:12

scenario here is a course platform much

9:36:14

like Scrimbo. And what we're trying to

9:36:15

solve is to figure out whether or not

9:36:17

user should get a certificate. that is

9:36:20

whether or not we should call this get

9:36:23

certificate function because the deal is

9:36:25

we only want to call this function if

9:36:27

two conditions are true and that is has

9:36:30

completed course in other words the user

9:36:33

has completed 100% of the course and

9:36:36

secondly gives certificate that is

9:36:38

whether or not this is the type of

9:36:40

course makes the user elleible for a

9:36:43

certificate because you can imagine that

9:36:45

very short courses doesn't give you a

9:36:47

certificate the course has to be of a

9:36:48

certain device to award you with a

9:36:51

certificate. So what we need to do is

9:36:54

figure out how we can check if both of

9:36:56

these conditions are true because then

9:36:59

and only then do we want to call this

9:37:02

generate certificate function. You could

9:37:04

actually achieve this with the concepts

9:37:06

you've learned so far by simply nesting

9:37:09

if statements. For example, you could do

9:37:12

if has completed course equals to true

9:37:16

and then add the body of the if

9:37:18

statement and then inside of the body

9:37:20

you could nest another if statement. If

9:37:24

gives certificate equals true and then

9:37:29

so you get two ifs inside of each other

9:37:32

and then inside of the inner if you do

9:37:35

generate certificate.

9:37:38

Now if we run this code, you can see

9:37:40

yes, we are indeed generating the

9:37:42

certificate. And if we flip one of them

9:37:44

to false, we are not generating the

9:37:48

certificate because here this condition

9:37:50

was not fulfilled. So neither of the

9:37:53

code lines inside of the body was run.

9:37:56

JavaScript just jumped over the entire

9:37:58

if statement. However, this is a very

9:38:01

clunky way of doing it. Better way would

9:38:04

be to actually remove the inner if

9:38:06

statement. For now, let's just comment

9:38:08

it out. And then inside of the

9:38:11

parentheses here, we can add another

9:38:14

condition by writing a double amperand.

9:38:17

And then the next condition gives

9:38:21

certificate equals true. We now move

9:38:26

this line, this line, and uncomment this

9:38:29

one. Run this code. We see nothing

9:38:32

happens because this condition here is

9:38:35

false. And with the and operator, both

9:38:40

of the expressions before and after the

9:38:43

operator need to evaluate to true for

9:38:46

this entire expression to evaluate to

9:38:49

true. So if we flip this to true and run

9:38:53

this, now it works, but it's much better

9:38:56

to have it on one line. And a little

9:38:59

extra thing we can do is actually omit

9:39:02

these equals true. Because now

9:39:06

what does this and this evaluate to?

9:39:09

Well, it's simply true and

9:39:14

true and true equals well true. But as

9:39:17

for now, in order to be explicit about

9:39:20

the condition we are checking for, I

9:39:22

actually want to keep these triple

9:39:24

equals here as well.

9:39:26

So one way to read this in plain English

9:39:28

is if

9:39:31

this is true and this is true then run

9:39:36

this code. Hopefully that makes sense

9:39:39

because in the next cast I'm going to

9:39:40

give you a challenge so that you get

9:39:42

your hands dirty with this as well.

9:39:47

Okay, let's continue on with our course

9:39:49

platform example. So in this challenge,

9:39:52

you are to imagine that you are writing

9:39:54

the code that is to be run after the

9:39:56

student has struggled with the challenge

9:39:58

for a little while or maybe the student

9:40:00

has clicked a button and signaled to the

9:40:02

platform that that she is stuck. And we

9:40:05

first want to check has the student

9:40:07

solved the challenge she's trying to

9:40:09

solve and has the students any hints

9:40:12

left? Because if the student has any

9:40:14

hints left, she can go and open those

9:40:16

hints. But if she's used all of our

9:40:18

hints and she hasn't solved the

9:40:20

challenge yet, then we are to run this

9:40:23

show solution function and just show her

9:40:26

the solution. Obviously, it just logs

9:40:28

out a string, but you can imagine that

9:40:30

it would show the solution. So, your job

9:40:33

is to create an if statement that checks

9:40:35

that both variables are false. I mean,

9:40:38

these two variables and then if so, run

9:40:41

the show solution function. Go ahead and

9:40:44

give this a shot and then I will of

9:40:45

course show you the solution when you

9:40:47

return back to this screencast.

9:40:53

Okay, the way to solve this is almost

9:40:56

similar to what we did in the previous

9:40:57

cast. We'll do if and then open and

9:41:00

close parenthesis. And here we need to

9:41:02

use a logical and operator because we're

9:41:05

going to check if both has solved the

9:41:08

challenge. triple equals false and the

9:41:13

double amperand pass hints left is also

9:41:18

false.

9:41:20

Then if the user hasn't solved the

9:41:22

challenge and has no hints left, it's

9:41:25

time to give her some slack and show

9:41:28

this solution. So then we'll trigger

9:41:30

show solution like that. Let's run the

9:41:33

code. And indeed this triggers the code

9:41:36

because both of them are false. If we

9:41:39

try to flip one to true, then the code

9:41:42

is not triggered. We're not logging

9:41:44

anything to the console, meaning that

9:41:45

our logical operator that governs our if

9:41:48

statement actually works. Great job.

9:41:54

So, now that you've learned the AND

9:41:57

operator, let's take a look at its close

9:41:59

relative, the or operator. What does

9:42:02

that do? Well, it allows you to check if

9:42:05

either this condition is true or this

9:42:08

condition is true. And if so, the body

9:42:11

of the if statement will be executed.

9:42:14

So, if you're in a situation where we

9:42:16

only need one of two cases to be valid,

9:42:19

well, then you want to use the or

9:42:20

operator. As for this example, it

9:42:22

doesn't really make sense. It will now

9:42:25

run since actually both of these are

9:42:27

true. But if the give certificate is

9:42:30

false, it will also run. But that

9:42:33

doesn't make any sense because if the

9:42:35

course doesn't give any certificates at

9:42:37

all, you're not supposed to generate any

9:42:38

certificates regardless of the user

9:42:40

having completed the course. So let's

9:42:42

use another example instead. Imagine

9:42:45

here that you're building Netflix and

9:42:47

you've just launched this amazing new

9:42:49

documentary, The Fire Festival. I don't

9:42:51

know if you've seen this, but it's truly

9:42:53

amazing about a guy who creates a

9:42:55

festival that aims to be the celebrity

9:42:58

hotshot festival of the world, but just

9:43:00

becomes a disaster. It's really good.

9:43:02

After this has been launched, you

9:43:04

probably want to recommend it to a ton

9:43:06

of your users. And what you want to do

9:43:08

is you want to check if the user likes

9:43:10

documentaries or if the user likes

9:43:13

startups. They don't have to like both,

9:43:15

but if they like one of these themes,

9:43:17

then most likely they will enjoy the

9:43:19

fire festival documentary. So, I want

9:43:22

you now to try to use the or statement,

9:43:25

that is the two lines you can see here.

9:43:27

You can copy them if you want if you

9:43:29

don't know how to get them from your

9:43:30

keyboard. And you're going to use this

9:43:31

to call recommend movie if either of the

9:43:34

variables that is the likes documentary

9:43:36

or like startups are true. I'm cruing

9:43:39

you out on thin ice here. I haven't

9:43:41

written a complete or statement for you,

9:43:43

but it works in just the same way as the

9:43:45

and statement. So, I think you can do it

9:43:47

if you just give it a shot. And if you

9:43:49

don't, no worries. I will show you the

9:43:50

solution afterwards as well.

9:43:57

Okay, let's do this. We'll do let likes

9:44:01

documentaries.

9:44:04

Set that to true. And we'll do let likes

9:44:08

startups. Set that to false for example.

9:44:12

And if likes documentaries, if that is

9:44:16

true or if likes startups is true, well

9:44:23

then we want to recommend this movie.

9:44:25

Like that. Running the code, we can see

9:44:28

we are recommending the movie even

9:44:30

though this one is false. Flipping both

9:44:33

of them to false. Now if I run the code,

9:44:36

nothing happens because at least one of

9:44:38

them needs to be true. This or this. And

9:44:42

if we make both true

9:44:45

and run the code, then of course if both

9:44:48

are true, then one or the other is also

9:44:50

true. So that would satisfy the

9:44:52

condition. Great job doing this

9:44:54

challenge. Let's keep up the pace and

9:44:56

move on.

9:45:00

Now you are going to take what you've

9:45:01

learned about the logical and operator

9:45:04

and modify this new card function so

9:45:07

that you only allow the player to get a

9:45:09

new card if she is alive and does not

9:45:14

have blackjack. So those are the two

9:45:16

condition that need to be filled for you

9:45:19

to actually run this code. So give this

9:45:21

a shot and I will of course show you the

9:45:24

solution afterwards as well.

9:45:30

Okay, so the way to do this is if open

9:45:33

and close parenthesis and then I'm going

9:45:35

to actually just open the body of the

9:45:38

conditional and paste in this code. And

9:45:41

when are we going to run this code?

9:45:43

Well, she has to be alive. I'm going to

9:45:46

do is alive. And then if that equals to

9:45:49

true, that's the first condition. And

9:45:52

the second condition which we also want

9:45:55

to be true since we're using this

9:45:57

logical and operator should be that the

9:46:00

has blackjack

9:46:03

should equal to false like that. If is

9:46:06

alive is true and has blackjack is false

9:46:09

then the dealer should be willing to

9:46:11

give the player a new card. So let's try

9:46:13

this. We'll start the game. 15 new card

9:46:17

25. You're out of the game. Let's try to

9:46:19

ask the dealer if we can please get one

9:46:21

more card. Oh, nothing happens. It

9:46:23

works. Brilliant. Really good job doing

9:46:26

this challenge.

9:46:30

Okay, so our blackjack game is almost

9:46:32

complete. There's just a tiny little

9:46:34

feature I would like to add as well

9:46:35

because if you've ever played online

9:46:37

blackjack or poker, what you normally

9:46:39

see is your own name and your credits or

9:46:43

your chips somewhere on the screen. So,

9:46:45

what I mean by that is something along

9:46:46

the lines of this,

9:46:49

like that. So you see your name and how

9:46:52

many credits you have or chips or

9:46:53

whatever. And this is nice because then

9:46:55

it's possible to later implement the

9:46:57

concept of winning, of increasing your

9:46:59

chips and of losing as you are betting

9:47:02

or playing rounds are critical

9:47:04

components of any blackjack game.

9:47:06

However, I wouldn't want to hardcode it

9:47:07

in the HTML like this. We of course want

9:47:09

to represent this data in our JavaScript

9:47:12

as that gives us the ability to change

9:47:14

it. Now I'm going to just show you how

9:47:15

we could do this to begin with by first

9:47:18

giving this an ID of player dashl

9:47:23

and removing the contents of it.

9:47:27

And then in the JavaScript we could do

9:47:29

let player name equals pair and let

9:47:35

player chips

9:47:38

equals

9:47:40

145 for example. And then we could grab

9:47:42

the element player L equals

9:47:46

document.getelement

9:47:48

by ID passing in the ID we just created.

9:47:52

Then do the player.ext content which you

9:47:55

know by now

9:47:57

your name colon and a space and then a

9:48:00

dollar sign and then plus the player

9:48:04

tips like that. If we now run this you

9:48:07

can see yes that we render it in the

9:48:09

exact same way. However, now we've come

9:48:12

into a situation where two values that

9:48:14

are inherently connected together like

9:48:17

the player and his chips which currently

9:48:20

live in two different variables. What

9:48:23

would make more sense in this situation

9:48:25

would be to somehow combine this into a

9:48:28

single unity and that is where so-called

9:48:31

objects come into play. That is another

9:48:34

data type which resembles arrays a

9:48:36

little bit but they are also different

9:48:38

in some fundamental ways but they are

9:48:40

kind of also buckets where you store

9:48:42

data. So in our case we would perhaps

9:48:44

want to create a player object in which

9:48:47

we can store both the players name and

9:48:49

the chips. So I'm going to show you how

9:48:52

to do this. You might feel a little bit

9:48:53

confused as you see it but over the next

9:48:56

few cast you're going to practice

9:48:57

objects yourself. So what I'll do, I'll

9:49:00

write let player equals open and close

9:49:05

curly brackets. You've seen these

9:49:06

before. They're used often in

9:49:08

JavaScript, but when you see them in a

9:49:10

context like this after the assignment

9:49:12

operator, they mean that we are creating

9:49:14

an object. And inside of here, what I

9:49:17

essentially want to do is add this data

9:49:21

right here. However, you can see that

9:49:23

something is wrong here with all these

9:49:24

red lines. And that's because the syntax

9:49:27

for creating items inside of our object

9:49:30

is different from how we define

9:49:32

variables. First of all, we don't use

9:49:36

the let keyword in front of the names.

9:49:38

And secondly, we replace the assignment

9:49:42

with colon. And thirdly, just as we have

9:49:46

in arrays, we separate the items with

9:49:50

commas. But we don't do that on the last

9:49:52

item. Finally, here it would make sense

9:49:55

to omit the player as we've already used

9:49:58

that name as the name of the entire

9:49:59

object. So, we can just rather do name

9:50:04

and I'm not going to capitalize it and

9:50:06

chips like that. Now, we have taken our

9:50:09

two variables and group them together in

9:50:12

this little bucket which we are calling

9:50:14

player. And the way we now can refer to

9:50:17

these values pair and 145 is by using

9:50:21

the first the object name player and

9:50:23

then the given key that is the name as

9:50:27

this is called a key and its value. So

9:50:30

name is the key and pair is the value.

9:50:33

Also chips is a key and 145 is a value.

9:50:37

So to replace player chips with

9:50:39

reference to the chips inside of the

9:50:40

player object we'll instead do player.

9:50:44

chips. If I run this code, you can see

9:50:47

we get the exact same result. You're

9:50:50

probably a little bit confused now, so

9:50:53

don't worry if you think this was hard.

9:50:55

Over the next few casts, you are going

9:50:56

to practice objects for yourself so that

9:50:59

this becomes muscle memory and second

9:51:01

nature to you. Let's move on.

9:51:07

One way to think of objects is that they

9:51:09

give you the ability to store data in

9:51:11

depth. And with that in mind, we'll know

9:51:13

that objects are so-called complex data

9:51:16

types or also called composite data

9:51:18

types because we use numbers, strings,

9:51:21

booleans, even arrays in order to

9:51:23

compose objects. So they often store

9:51:25

quite a lot of data and they can even

9:51:27

store objects within objects. That kind

9:51:30

of nested data structure is not

9:51:31

something you're going to think about

9:51:33

now. For now, just think of it as key

9:51:35

value pairs. And let's look this through

9:51:38

the lens of a real world example. That's

9:51:40

always easier. So here on Scribba, we

9:51:43

represent our courses as objects cuz

9:51:46

here you can see the CSS grid course

9:51:48

actually the very first course we

9:51:50

launched back in the days and it has a

9:51:52

bunch of different data. For example, it

9:51:53

has the title, the number of lessons,

9:51:56

and the creator of the course, the

9:51:58

length of the course, and the level of

9:52:00

it. So let's actually translate this

9:52:02

course into JavaScript into how the data

9:52:04

structure actually looks. So, roulette

9:52:07

course equals open and closed curly

9:52:10

brackets. Start with a title like that.

9:52:13

Title colon learn CSS grid for free. Now

9:52:18

we have one key value pair. Title is the

9:52:21

key and the string here is the value.

9:52:23

Then the lessons that is natural to

9:52:26

represent as a number. So it was 16

9:52:28

lessons. the creator which again is a

9:52:31

string that and then we have the length

9:52:34

which while it says 1 hour here that's

9:52:36

actually not how we represent that data

9:52:38

in our database and thus in this object

9:52:42

break it down into minutes. So perhaps

9:52:44

this course is actually 63 minutes. But

9:52:47

as for the user interface, we don't want

9:52:49

to go into detail that much. We round it

9:52:51

to the closest hour. And finally,

9:52:53

there's the level. And here it says

9:52:55

intermediate. That's also one of those

9:52:56

cases where the data in the user

9:52:58

interface differs slightly from the data

9:53:00

in the database. So our levels are

9:53:03

represented from 0 to three where zero

9:53:06

is complete noobs and three are the

9:53:08

advanced courses. So the intermediate

9:53:10

course you can see here, we type out

9:53:12

intermediate here. If this value is set

9:53:14

to two, now you don't have to worry

9:53:16

about how our design and what we say to

9:53:19

the user differs from the underlying

9:53:21

data. It's just something I wanted to

9:53:22

give you a little heads up about because

9:53:24

it's very normal in real world code

9:53:26

bases.

9:53:27

Now, it looks like we're kind of done

9:53:29

here, but we're actually not because

9:53:30

there's a lot more data for a course

9:53:32

actually than what's represented here.

9:53:34

For example, whether or not it's free or

9:53:37

paid. That's a boolean. So, it's either

9:53:38

true or false like that is free. True.

9:53:41

And this course is indeed free. And we

9:53:43

also have tags for courses. And that's

9:53:46

an array because we want to have the

9:53:47

ability to add multiple tags to one

9:53:50

course. So, we need a complex data type

9:53:52

here as well as the value of this tags

9:53:55

key. So, for example, this CSS grid

9:53:57

course has the tags HTML and CSS. So,

9:54:01

this is a very real world example of an

9:54:04

object. Now if we want to access any of

9:54:07

these values here for example the length

9:54:09

we do that through something we call the

9:54:11

dot notation course dot length like that

9:54:17

console log out this and run the code

9:54:19

you can see that we log out 63 so

9:54:22

course.length length gives us back 63.

9:54:25

And you've used this dot notation quite

9:54:27

a lot actually up until now. And even

9:54:29

though you probably haven't been aware

9:54:30

of it, you have been using objects all

9:54:32

along. Like what are we doing here?

9:54:35

Console.log.

9:54:37

What kind of data type do you think the

9:54:38

console is? Well, it's an object. And

9:54:41

just to give you one more example, let's

9:54:43

say we want to log out this array here.

9:54:45

Well, then we simply do course tags on

9:54:48

the code. And when we open the control,

9:54:50

we can see that we are logging out an

9:54:52

array because this entire array is the

9:54:54

value that we get back when we ask for

9:54:57

the tags. Now, one thing I want to point

9:54:59

out before we move on that you can

9:55:01

replace this dot with an open square

9:55:04

bracket and then add a closing square

9:55:06

bracket and then turn the key name into

9:55:10

a string. This is called bracket

9:55:12

notation. If we run the code, we get the

9:55:14

exact same thing back. Now, there are

9:55:16

reasons for why you sometimes want to

9:55:18

use bracket notation, but we're not

9:55:20

going to get into that right now because

9:55:22

in the foreseeable future, you are not

9:55:24

going to end up in a situation where you

9:55:26

have to do that. So, I'm just going to

9:55:28

tell you now to use the dot notation.

9:55:31

It's simpler, it's shorter, less code to

9:55:33

read, less code to write. It's very

9:55:34

understandable, and it's actually what

9:55:36

most developers prefer to use if they

9:55:38

get to choose. So, now I've been talking

9:55:40

for far too long. I want you to write

9:55:42

code, of course. This is Scrimbot.

9:55:44

That's what we're all about. So, in the

9:55:45

next cast, you are going to write your

9:55:47

own object. I'll see you there.

9:55:52

One thing I like to do if I'm bored is

9:55:54

to search for epic places to live on

9:55:56

Airbnb. For example, castles. Like this

9:55:58

wish list I came across right here,

9:56:00

which contains a bunch of more or less

9:56:02

affordable castles to rent across

9:56:04

Europe. So, for example, this really

9:56:06

neat looking castle right here only cost

9:56:08

$190.

9:56:10

I mean, that's what people pay for like

9:56:12

10 square meters in a hotel room in

9:56:14

central London. So, pretty cool that you

9:56:16

can rent a castle for that same price.

9:56:18

But anyway, the point being that these

9:56:20

listings here on Airbnb most likely take

9:56:23

advantage of the object data structure

9:56:25

in order to store all of the data that

9:56:27

they need to present to the user. So,

9:56:29

this can also be a great exercise for

9:56:30

you so that we can build up that object

9:56:32

muscle memory of yours. I want you to

9:56:35

basically create an object that

9:56:37

represents an Airbnb castle listing. It

9:56:40

should contain at least one boolean, one

9:56:42

string, one number, and one array. It

9:56:44

can contain a bunch more if you want to

9:56:46

if you want to go above and beyond.

9:56:48

However, that's the minimum requirement.

9:56:50

And at the end, I want you to log out at

9:56:52

least two of the keys using the dot

9:56:54

notation. So, go ahead and do this right

9:56:57

now.

9:57:02

Okay, hopefully that went well. Let's do

9:57:04

this together. I'll do let h castle

9:57:07

equals open and close brackets. We can

9:57:10

use the title. Live like a king in my

9:57:15

castle like that. As for the number, I

9:57:18

think the price is very natural to use.

9:57:20

Price $190. And what about the boolean?

9:57:24

Which components here naturally lend

9:57:26

themselves well to be using a boolean

9:57:28

data type under the hood? Well, I think

9:57:30

the fact that two of these are

9:57:31

superhosts and the third is not points

9:57:34

to this being a suitable piece of data

9:57:36

for the boolean data type because you're

9:57:38

either a superhost or you're not. So, is

9:57:42

superhost

9:57:43

and this one happened to be true. And

9:57:45

then finally, there's the array. What

9:57:47

kind of data here would it make sense to

9:57:49

place inside of an array? Well, it could

9:57:52

be that these kind of bullet points here

9:57:54

are arrays that are pulled out of the

9:57:57

underlying data and are kind of the

9:57:59

featured selling points that Airbnb

9:58:01

wants to list out or actually you can

9:58:03

see that there's multiple images here.

9:58:05

If you see this carousel indicator so

9:58:07

the images is very natural to have

9:58:09

inside of an array and also the reviews

9:58:12

that's definitely a list of many items.

9:58:14

So, doesn't matter what you choose or if

9:58:16

you choose something completely

9:58:18

different. The point is just that I

9:58:19

wanted you to write an array inside of

9:58:21

an object. So I'm going to choose images

9:58:23

like that. Make that an array. And here

9:58:26

we probably have URLs to the specific

9:58:29

images. So it might be img/castl1.png

9:58:36

img/castl2.png

9:58:39

and so on and so on. I won't bother

9:58:41

writing anymore. Now let's log out to

9:58:44

this using the dot notation console log

9:58:48

castel.pric

9:58:51

console log castel

9:58:55

s superhost.

9:58:57

We'll run this and indeed we print out

9:59:01

190 and true to the console meaning we

9:59:04

have completed the challenge. Great jobs

9:59:07

holding this one. Let's move on.

9:59:12

Okay. Welcome back. Now, it's your time

9:59:14

to render out the player's name and his

9:59:16

or her chips on the page. So, it's a

9:59:19

four-part challenge. First, you are to

9:59:21

create a paragraph with an ID of player

9:59:23

L. Then, you are to move over to the

9:59:26

JavaScript and create the player object

9:59:28

here at the very top, and you are to

9:59:30

give it two keys, name and chips. Then

9:59:33

you are to move down to where you are

9:59:35

grabbing elements from the DOM and then

9:59:37

grab hold of the player L paragraph and

9:59:39

store it in a variable called player L.

9:59:42

Then you are to render the player's name

9:59:44

and chips inside of player L. So pretty

9:59:48

big challenge, but you've seen me do it

9:59:50

before and you've practiced how to work

9:59:51

with objects, so I think you're going to

9:59:53

nail this one. Give it your best shot

9:59:55

and then I will show you how to do it as

9:59:56

well afterwards.

10:00:02

Okay, hopefully that went well. If not,

10:00:05

no worries. Let's do it together. First,

10:00:07

we'll do a paragraph here and we'll give

10:00:10

it the ID of player-l

10:00:13

like that. Nothing happens because it's

10:00:16

empty.

10:00:17

Moving over to the JavaScript, we are to

10:00:19

create the player object. Let player

10:00:22

equals open and close curly brackets are

10:00:26

to define its name.

10:00:29

In my case, pair. Use a comma to

10:00:31

separate the items. And then chips.

10:00:34

Let's say I have $200 in chips right

10:00:37

now.

10:00:38

Three. Grab a hold of the player L

10:00:41

paragraph and store it in a variable

10:00:43

called player L. Okay, we know how to do

10:00:45

that. Let player L equals

10:00:48

document.getelement get element by id

10:00:53

passing in the player-l

10:00:56

which is what we created right here.

10:01:00

At this point, let's console log out

10:01:03

player L.

10:01:05

And indeed, we are fetching it from the

10:01:07

DOM. Finally, we are to render the

10:01:10

player's name and chips inside of player

10:01:12

L. We know how to do that as well.

10:01:15

Player L.ext text content equals and

10:01:18

here we have to concatenate a string and

10:01:21

dig into the object to find the correct

10:01:24

values. So we'll start with the player

10:01:27

doame plus going to have a colon and a

10:01:31

space and then the dollar sign in front

10:01:34

of the chips and then do plus again

10:01:36

player.ips.

10:01:40

Now this is all set up. Let's run the

10:01:43

project. And there we go. We have

10:01:46

rendered it out. Great job solving this

10:01:48

challenge.

10:01:52

Now that you've learned about objects, I

10:01:54

want to tell you about a specific coding

10:01:56

pattern that we've actually been using

10:01:58

quite a lot here, but that we aren't

10:02:00

going to implement from scratch

10:02:02

ourselves in this module. But since we

10:02:04

still are exposed to it, I want you to

10:02:06

understand what's going on under the

10:02:08

hood. And that pattern is to create

10:02:10

functions inside of objects. Something

10:02:12

which we also call methods. Because

10:02:14

let's say that for example we create

10:02:17

another key here which is say hello and

10:02:20

then a colon and then as the value we'll

10:02:22

actually write a function like this. We

10:02:26

won't give it a name. It'll just be an

10:02:27

anonymous function. And inside we'll

10:02:30

console log JSON. That's howdy in our

10:02:33

region. And now if we want to invoke

10:02:36

this function we'll do player do say

10:02:39

hello and then open and close

10:02:41

parenthesis. If we run the code now, you

10:02:44

can see that indeed we are logging

10:02:46

Heisson to the console. And now the

10:02:48

reason I wanted to show this to you is

10:02:50

because don't you think this syntax

10:02:52

looks a little bit familiar? Like first

10:02:54

a variable then a dot and then a

10:02:58

function that you are calling with the

10:03:00

parenthesis at the end because actually

10:03:03

that's the exact same thing we're doing

10:03:05

here when we're saying document dot

10:03:07

getelement by ID and the parenthesis.

10:03:11

And here we're also passing in a value,

10:03:12

but it's essentially the same thing. And

10:03:14

also here down at math dot random also

10:03:19

the same thing. Math is an object and

10:03:21

random is a function on that object also

10:03:24

called a method.

10:03:27

And even our good old friend console.log

10:03:30

is the exact same thing. Object with a

10:03:33

method. So this is not something we are

10:03:37

going to implement ourselves in this

10:03:39

module but I just wanted you to be aware

10:03:41

of that so that when I speak about

10:03:43

methods you know that they are simply

10:03:45

functions that are attached to objects.

10:03:48

So with that let's move on.

10:03:53

Hey Tom here and I'm just dropping by to

10:03:56

talk about AI. AI tools like chat GPT

10:04:00

have taken the world by storm. At the

10:04:02

peak of the hype, AI was going to

10:04:04

replace humans in many skilled jobs. And

10:04:07

there were even lurid clickbaity claims

10:04:10

that humans could disappear altogether

10:04:13

from the face of the earth. So certainly

10:04:16

no point in learning to be a web

10:04:17

developer then. Well, you're still

10:04:19

watching this, so you didn't believe

10:04:21

that any more than I did. But AI is here

10:04:24

to stay and it does have implications

10:04:26

for the industry and for you as a

10:04:28

learner. In this scrim, I want to

10:04:30

investigate what AI means to the coding

10:04:32

student because there are some good uses

10:04:34

of AI for you as a coder, but also some

10:04:37

potential missteps and problems. Take

10:04:40

this fairly typical Scriber challenge.

10:04:42

In fact, it's one you've already seen. I

10:04:44

could solve this myself, but I can't be

10:04:46

bothered. So, I'm going to copy it and

10:04:49

paste it into chat GPT. I'll hit the

10:04:52

magic button. And look, we've got an

10:04:54

answer. And it's given me some

10:04:56

explanation. And explanation is good. if

10:04:59

I read it. But the temptation is strong

10:05:01

just to take the code it's prepared for

10:05:03

me right here and paste it in to the

10:05:06

editor and solve the challenge. And when

10:05:09

I save that and we open up the console,

10:05:12

well, I can see that it is working. But

10:05:14

obviously if I were a new aspiring

10:05:16

developer that couldn't solve this

10:05:18

challenge in the first place in 5

10:05:20

minutes time I would have absolutely no

10:05:23

idea what this code does or how it works

10:05:26

because all I've done is glanced at the

10:05:28

bit of explanation and then copied and

10:05:30

pasted some code from chat GPT. I

10:05:33

haven't really progressed myself at all.

10:05:35

I'm no more knowledgeable and that is

10:05:38

pretty silly. So remember, when learning

10:05:40

to code, you need to understand what a

10:05:43

piece of code does. You need to know its

10:05:45

use cases. So what it's good for and

10:05:48

what its limitations are. And you need

10:05:49

to be building muscle memory. You'll

10:05:52

hear teachers and instructors talking a

10:05:53

lot about muscle memory. That only comes

10:05:55

with the practice of actually writing

10:05:57

code, not looking at it, not watching

10:05:59

somebody else write it on YouTube, and

10:06:02

of course, not watching AI churn it out.

10:06:04

And although theory and explanation are

10:06:06

great, with code you're not really

10:06:08

learning until you're doing. So going

10:06:10

back to our previous example, unless you

10:06:12

read the explanation thoroughly, write

10:06:15

this code out yourself, and perhaps

10:06:17

experiment with it a bit to verify that

10:06:19

what the AI told you is true, you're

10:06:21

actually doing yourself a disservice.

10:06:24

And yes, I said verify what the AI told

10:06:27

you is true. And that brings us to a key

10:06:29

fact and chat GPT is honest about it

10:06:33

right here in its footer. AI is not

10:06:36

always right. Chat GPT can make

10:06:38

mistakes. Check important info. And you

10:06:41

need to know that. Remember how AI is

10:06:43

trained. It learns in most cases from

10:06:46

code which is openly available on the

10:06:47

internet. And there is a lot of bad code

10:06:50

on the internet. If you blindly use AI

10:06:53

generated code without understanding

10:06:55

what it does, sooner or later things

10:06:57

will go horribly wrong. You will not

10:06:59

make it far as a professional developer

10:07:02

if you don't understand the code you're

10:07:03

writing. But if you choose to use AI to

10:07:06

generate code, there are several

10:07:08

takehomes I want you to know about. Make

10:07:10

sure you understand the code that's been

10:07:12

generated. Verify that it's true from

10:07:15

nonAI sources if at all possible. And

10:07:17

whenever you use code that came from AI

10:07:19

or indeed from Stack Overflow or any

10:07:22

other source, write out the code

10:07:23

yourself. This will build muscle memory.

10:07:26

And lastly, keep asking yourself why.

10:07:29

Why does this code work? Following these

10:07:32

rules will help you grow as a developer

10:07:34

much faster. And remember, AI should

10:07:37

enhance your skills and not replace

10:07:39

them. So my last bit of friendly advice

10:07:42

on this topic is that at this stage in

10:07:44

your learning where you are right now,

10:07:46

it's probably best to avoid using AI to

10:07:49

simply generate code for you. But I'm

10:07:51

not saying never use AI. So let's

10:07:54

examine some of the use cases for AI and

10:07:56

highlight some pitfalls to avoid. You

10:07:59

can use AI as a code explainer. If you

10:08:02

don't understand what some code does and

10:08:04

why, you can drop it into your AI

10:08:06

helper. This can certainly be very

10:08:08

useful, but it does come with a caveat.

10:08:10

And this is basically a continuation of

10:08:12

what I was just saying about accuracy.

10:08:15

AI always sounds confident in its reply,

10:08:18

but don't let that fool you. It can be

10:08:20

misleading or just plain wrong. This is

10:08:23

what is known as hallucinating and it

10:08:26

can sound very plausible. We all know

10:08:28

that person, right? Or perhaps a

10:08:30

politician we've seen interviewed.

10:08:32

They've got all of the confidence in the

10:08:33

world, but that doesn't mean that

10:08:35

they're not speaking rubbish. So, while

10:08:38

AI can be great for explaining code,

10:08:40

think of it as a friendly, helpful

10:08:42

colleague who potentially knows more

10:08:44

than you, but is not infallible, not

10:08:47

perfect. I also want to add that while

10:08:49

the more traditional ways of finding

10:08:51

answers are more timeconuming, they are

10:08:53

time well spent. Reading blog posts or

10:08:56

discussions on the problem or asking a

10:08:58

question on Scribb's Discord and forum

10:09:00

might well give you a more rounded

10:09:02

understanding of the problem than AI

10:09:04

does. And if you find a solution that

10:09:06

someone else has implemented for their

10:09:08

own problem, which you then have to

10:09:09

customize to apply to your code, you're

10:09:12

fine-tuning your coding skills even

10:09:14

more. So, while AI is a good explainer,

10:09:17

it should really be considered a last

10:09:19

resort. AI can be useful for debugging.

10:09:22

Again, if you're really stuck and if

10:09:24

you're working professionally and are

10:09:26

against the clock, then this is a great

10:09:28

time-saving tool. But this also comes

10:09:30

with a big caveat. As a new developer,

10:09:32

you should do everything you can to

10:09:34

debug the code yourself without relying

10:09:36

on AI. That means thinking for yourself,

10:09:39

re-watching scrims, searching online for

10:09:41

the meaning behind error codes. You do

10:09:43

have to be able to understand the

10:09:45

problem and the solution to consider it

10:09:47

a success. So don't get into the lazy

10:09:50

habit of relying on AI. Probably one of

10:09:53

the best uses is as a research tool. And

10:09:56

I'm thinking here more on the high

10:09:57

level. So you could ask it some pretty

10:09:59

general questions. For example, what are

10:10:02

the main considerations for making a

10:10:03

website accessible to users with visual

10:10:06

impairments? Or what is the best way to

10:10:09

empty an HTML element? Of course, you'll

10:10:11

still need to use background knowledge

10:10:13

and traditional research to weed out

10:10:15

responses that are inaccurate or wrong,

10:10:17

but it can really speed up the research

10:10:19

process and give you a ton of ideas. AI

10:10:22

can be a great timesaver. I want to

10:10:25

finish up with a word about ethics

10:10:26

because there are some downsides to AI

10:10:29

which don't get enough of a mention.

10:10:31

From an environmental perspective, AI is

10:10:34

a huge consumer of power. AI involves

10:10:37

crunching data and that means servers

10:10:38

are working hard using electricity and

10:10:41

needing to be cooled. We do need to be

10:10:43

cutting our carbon footprints and not

10:10:45

expanding them. Also, the source content

10:10:47

AI is trained on was made by real people

10:10:50

who have mostly not consented and are

10:10:52

not getting a cut of the profits. So,

10:10:54

these are two things to bear in mind,

10:10:56

not least because they will influence

10:10:58

the evolution of AI from here on in, and

10:11:00

you should definitely be keeping an eye

10:11:02

on this field. Okay, let's go back to

10:11:05

the course.

10:11:09

So, you have built your very first

10:11:12

JavaScript game. Congrats with that.

10:11:14

This is perhaps the first of many games

10:11:16

you're going to build. Perhaps the start

10:11:17

of a career as a game developer. I don't

10:11:20

know. Anyway, give yourself a pat on the

10:11:22

back. You have learned a ton. And

10:11:24

actually, let's do a little recap so

10:11:26

that we remind yourself about all the

10:11:28

awesome things you've learned throughout

10:11:29

this section. One thing which was key to

10:11:32

our app and is key to basically every

10:11:34

web app out there is the arrays. We

10:11:37

defined a card array and also you

10:11:40

reassign the array down in the start

10:11:41

game function where you defined it with

10:11:43

items and then all the way down at the

10:11:46

new card button you also pushed to the

10:11:48

array. So you are starting to get some

10:11:50

serious array skills. Also we worked

10:11:54

with objects up here. We created our

10:11:56

player object and the object as you

10:11:58

remember contains key value pairs and

10:12:01

it's also a data type that is used in

10:12:03

basically every single web app out

10:12:05

there.

10:12:06

The third data type you learned was

10:12:09

booleans namely the true and false for

10:12:11

the has blackjack and is alive

10:12:13

variables. We flip them around. So we

10:12:16

set is alive to true down here and has

10:12:20

blackjack set to true down here. And

10:12:22

thus creating kind of a state for our

10:12:24

game. This brings us to the next

10:12:26

important concept you learned which is

10:12:28

the if else statements that wrapped

10:12:31

these booleans and so many other things.

10:12:33

This is key. You cannot build apps

10:12:36

without these kinds of conditional

10:12:37

statements. Both the if, the else if and

10:12:41

the else are absolutely key in any

10:12:43

programming language. And in order to

10:12:45

make these if else statements work, we

10:12:47

used comparison operators. That's these

10:12:49

guys in here. Less than or equal to or

10:12:52

triple equal. They helped us define the

10:12:54

conditions as to when we wanted to

10:12:56

render the blocks of code in the if else

10:12:59

statement. Moving on, we also did

10:13:02

logical operators. The and operator

10:13:05

which checked that both this condition

10:13:08

and this condition was true in order for

10:13:11

us to run this code in the block of the

10:13:14

if statement. And something we also

10:13:16

learned was the for loops.

10:13:19

It was here in the render game function

10:13:21

where we used the for loop to loop

10:13:23

through our cards array and render out

10:13:25

each of the cards. Again, for loop is

10:13:28

just one of those foundational things in

10:13:30

programming because so much of

10:13:32

programming is evolved around looping

10:13:34

through data and doing things based upon

10:13:36

the data. Whether that's rendering it

10:13:38

out, making calculations, sending it off

10:13:40

from a server to a client, or just

10:13:42

summing it together, for example, it

10:13:44

doesn't matter. It's just something

10:13:45

you'll do again and again. So, I'm

10:13:47

really happy that you've learned it as

10:13:48

early as now. Another useful tool you've

10:13:51

learned is the math object that allowed

10:13:54

us to create this get random card

10:13:56

function by using math.random, which

10:13:59

gives us a number between 0 and one, and

10:14:01

math.f floor, which basically floors the

10:14:03

number to the nearest whole number

10:14:05

moving downwards.

10:14:08

And you built upon your further

10:14:09

knowledge of functions and learned how

10:14:11

to use return statements in functions

10:14:13

because in this get random card, we had

10:14:15

to return values. And that's something

10:14:17

you didn't know before this section.

10:14:19

There's still more things to learn about

10:14:20

functions. So, we'll definitely continue

10:14:22

on with functions in the Chrome

10:14:24

extension we're going to build a bit

10:14:25

later, but for now, just be proud about

10:14:27

the fact that you've at least come to

10:14:28

the point where you can return values in

10:14:30

functions. That's a big important step.

10:14:32

So, with all of these things learned, I

10:14:35

completely understand. If you feel that

10:14:37

you're a little bit on shaky ground here

10:14:39

and that all of these names basically

10:14:40

just confuse you even more, I don't

10:14:42

think you should worry about that. I

10:14:44

would have never remembered the

10:14:45

difference between comparison operators

10:14:46

and logical operators when I learned

10:14:48

JavaScript. What they are called doesn't

10:14:51

really matter. The important thing is

10:14:52

that you know how to compare two

10:14:54

variables, for example, or that you know

10:14:56

how to create a true or false variable.

10:14:59

Whether that you call them booleans or

10:15:01

true false isn't something you should be

10:15:02

too worried about right now. So even

10:15:04

though this might look scary, try to not

10:15:07

let it scare you. just focus on coding

10:15:09

as much as you can because over time

10:15:11

these concepts will mature in your mind

10:15:13

and become second nature. And actually

10:15:16

on that note, you are going to get some

10:15:17

practice right away because before we

10:15:20

jump on to the final project, the Chrome

10:15:22

extension, I'm going to throw a few

10:15:24

challenges on you just so that we're

10:15:26

sure that you really understand these

10:15:28

concepts and that you build out that

10:15:30

ever so important muscle memory. So

10:15:32

let's go ahead and do that right now.

10:15:37

Okay. In this challenge, you are going

10:15:38

to practice objects and functions. So,

10:15:41

first you are going to create a person

10:15:43

object that contains three keys, name,

10:15:46

age, and country. And the values of

10:15:49

those keys should be set by using

10:15:51

yourself as an example. So, your name,

10:15:53

your age, and your country. And then you

10:15:55

are to create a function called log data

10:15:58

that uses this person object. It just

10:16:00

grabs it from the global scope to then

10:16:02

create a string in the following format.

10:16:05

pair is 35 years old and lives in

10:16:07

Norway. Obviously, pair 35 and Norway

10:16:11

are pulled from the person object

10:16:13

directly, whereas the rest is a string

10:16:15

that is hard-coded inside of the

10:16:17

function. Finally, call log data in

10:16:20

order to verify that it works. So, go

10:16:22

ahead and do this right now and then I

10:16:24

will show you the solution as well when

10:16:25

you return back.

10:16:31

Okay, let's do this. We'll do let person

10:16:36

equals open and close curly brackets

10:16:39

name should be pair

10:16:43

age 35 and country

10:16:48

Norway like that and then the function

10:16:51

log data like that here we will

10:16:55

console.log

10:16:57

this string and you can see the first

10:16:59

value is actually pulled directly from

10:17:01

person.name name. So we'll do personname

10:17:05

plus and then s and then plus person do

10:17:11

age then plus again

10:17:15

years old and lives in plus

10:17:21

person dot

10:17:23

country like that. Now the final step is

10:17:26

to call the function log data

10:17:29

and run the code. And yes, we can see

10:17:32

Pier is 35 years old and lives in

10:17:34

Norway. Great job.

10:17:39

Okay. Now you are going to practice

10:17:41

conditional statements. So that is the

10:17:43

if, else if and else statements. And the

10:17:46

problem you are going to solve is a very

10:17:48

common one for train companies or a bus

10:17:50

service, which is that the price of the

10:17:53

ticket is based upon the passenger's

10:17:56

age. For example, if the passenger is

10:17:58

less than 6 years old, there's a free

10:18:00

pass. 6 to 17 gives a child discount. 18

10:18:04

to 26 gives a student discount. 27 and

10:18:07

up to 66, that's the age range that pays

10:18:10

the full price. And the people over 66

10:18:13

get get the senior citizen discount. So

10:18:16

your job is then to create a conditional

10:18:18

statement that accounts for all of these

10:18:20

scenarios and based upon the age

10:18:22

variable up here logs out which discount

10:18:25

the passenger will get. So go ahead and

10:18:28

give this a shot and return back to me

10:18:30

when you want to see my solution.

10:18:37

Okay, let's do this. I'll start with the

10:18:40

if and if h is less than six well then

10:18:45

console log

10:18:47

three else if next condition that is

10:18:52

that age is less than 18 because that

10:18:57

will in practice mean from 6 to 17 here

10:19:00

because it's less than 18. Yeah, that's

10:19:02

17 and below. However, we've already

10:19:05

accounted for up until five. So the code

10:19:09

here will be triggered from 6 to 17.

10:19:13

console.log

10:19:15

child discount.

10:19:17

Okay. Next one. Else if here we'll do

10:19:21

age is less than 27.

10:19:25

So log student discount because this one

10:19:29

kind of starts at 18 since this one

10:19:32

stopped right before 18 and it should be

10:19:34

up until including 26. that is in other

10:19:37

words less than 27.

10:19:40

Then we have the full price which is for

10:19:44

people now left in the group who are

10:19:47

less than 67 or in other words 266.

10:19:52

Control log full price. And finally then

10:19:57

we have the else. We don't need to

10:19:59

specify an if because in all other cases

10:20:02

the passenger should get the senior

10:20:04

citizen discount.

10:20:07

like that. Let's run the code. At 15,

10:20:11

yes, we're getting the child discount.

10:20:13

Correct. At 55, we're getting the full

10:20:16

price. Very good. 75, we are getting the

10:20:20

senior citizen discount. So, it seems to

10:20:22

be working for at least these three

10:20:24

scenarios, and I hope it works for the

10:20:25

rest. So, let's move on.

10:20:30

Okay, it's time to practice your for

10:20:32

loop skills and your geography skills

10:20:35

because I've created this large

10:20:37

countries array here which contains the

10:20:39

five largest countries in the world by

10:20:41

population size. So it's China, India,

10:20:43

USA, Indonesia and Pakistan. And what

10:20:46

you are to do is to use a for loop to

10:20:48

log out the following to the world.

10:20:50

First a sentence, the five largest

10:20:53

countries in the world, and then each of

10:20:55

the countries on a new line with a dash

10:20:57

and a space in front of the country

10:20:59

name. So you are to use a for loop and

10:21:02

loop through this array here. You can't

10:21:04

simply hardcode out all of the console

10:21:06

logs. That wouldn't serve any purpose.

10:21:08

So try to remember how to use a for

10:21:10

loop. If you can't remember it, you can

10:21:11

look back at previous casts as we surely

10:21:14

have gone through it. Or of course, I

10:21:16

will also show you the solution

10:21:17

afterwards as well.

10:21:23

Okay, let's do this. I'll start with the

10:21:26

for loop because that's the meat of this

10:21:28

challenge for let I equals zero. We'll

10:21:32

start at zero because as you remember

10:21:35

raise our zero index and we want to use

10:21:37

the index in order to fetch out each of

10:21:39

the items. So starting there and

10:21:42

stopping before I reaches large

10:21:47

countries dolength

10:21:49

length of this is five. So before it

10:21:52

reaches five that is four and indeed

10:21:54

Pakistan is the fourth index. So that

10:21:57

should be right and we want to increment

10:21:59

upwards like that. Here we'll do console

10:22:03

log and then first the dash and the

10:22:06

space like that concatenating this with

10:22:10

large countries passing in in the square

10:22:14

brackets the iterator variable I and now

10:22:18

let's run this code and bring up the

10:22:20

console and indeed it looks to be

10:22:22

working. Now we only need to control log

10:22:24

out

10:22:26

the five largest countries in the world

10:22:28

like this. running the code and yes, it

10:22:32

works. Great job.

10:22:37

Okay, now I need your help because I

10:22:39

have messed up our large countries

10:22:41

array. As you can see, in first place I

10:22:44

have Tuvalu and in fifth place I have

10:22:46

Monaco. However, neither of those

10:22:49

countries are large enough to deserve a

10:22:51

spot in this large country's array.

10:22:53

Actually, Tuvalu is a tiny island state

10:22:56

far out in the Pacific Ocean with just

10:22:58

over 10,000 inhabitants. And Monaco is a

10:23:02

tiny state in Europe that's smaller than

10:23:04

Central Park in New York. So surely it

10:23:07

does not belong in this array. The first

10:23:10

and fifth place belongs to China and

10:23:13

Pakistan. So I need you to help me fix

10:23:16

up this large countries array so that

10:23:18

China and Pakistan are added back into

10:23:20

their respective places. And to solve

10:23:22

this, you are going to use the four

10:23:24

following tools. First, push and pop,

10:23:27

which you've learned earlier in this

10:23:29

course, and then their counterparts,

10:23:32

unshift and shift, which I haven't

10:23:34

taught you about, but this is

10:23:36

intentional because I want you to Google

10:23:39

how to use unshift and shift. And what I

10:23:41

will disclose to you is that they are

10:23:43

kind of a mirror image of push and pop.

10:23:47

Because whereas push and pop will work

10:23:50

with the end of the array, unshift and

10:23:52

shift works with the beginning of the

10:23:54

array. So pop will remove an item at the

10:23:59

end like this. Whereas push will push an

10:24:02

item into the end like that. And

10:24:05

likewise shift will remove an item from

10:24:09

the beginning of the array like this.

10:24:11

and unshift will shove an item into the

10:24:15

array at the start like that. So with

10:24:18

that short explanation and Google, you

10:24:20

should be able to I want you to try to

10:24:22

solve this challenge and of course I

10:24:24

will show you the solution when you

10:24:25

return back to this screencast. Good

10:24:27

luck.

10:24:33

Okay, hopefully that went well. Let's do

10:24:36

this. I'll start at the end. So I want

10:24:38

to replace Monaco with Pakistan. Then

10:24:41

I'll do large countries pop in order to

10:24:45

pop away Monaco. And then large

10:24:48

countries push

10:24:51

passing in Pakistan.

10:24:56

Let's now console log

10:24:59

large countries to see if this works.

10:25:02

Running the code. And yes, there we go.

10:25:05

Now to remove this first item here, I'm

10:25:09

going to have to use shift. And here I

10:25:12

completely understand if you're confused

10:25:13

as to why shift is named shift and

10:25:15

unshift is named unshift. It's about the

10:25:17

two most unintuitive method names in

10:25:20

JavaScript in my opinion. And one way to

10:25:22

think of this is that unshift is a

10:25:24

longer word than shift. So unshift makes

10:25:27

the array longer. That's just as push is

10:25:31

a longer word than pop. So push makes

10:25:34

the array longer. Anyway, let's just do

10:25:38

this. Large countries dot shift. Let's

10:25:43

see if we've removed to value by running

10:25:45

the code now. Yes, to value is gone.

10:25:48

That means I need to do large countries

10:25:51

do unshift and pass in China like that.

10:25:56

Running the code. Yes, we have fixed up

10:25:59

the large countries array. Great job.

10:26:04

Now, it's time for a scary challenge

10:26:06

because you are going to check if it is

10:26:09

Friday the 13th. And if so, you are

10:26:11

going to log out this spooky face

10:26:13

because, as you might know, Friday the

10:26:15

13th is kind of a scary date. If you've

10:26:18

seen the Friday the 13th horror movies.

10:26:22

So, you have two variables. day of

10:26:24

month, which is meant to be from either

10:26:26

1 through 31, depending on which day of

10:26:28

the month it is, and then a weekday

10:26:30

variable, which is meant to be Friday or

10:26:32

Tuesday or Wednesday or any other days

10:26:35

in the week. And if it is both Friday

10:26:38

and the 13th, and only if both of those

10:26:41

conditions are satisfied, you are to log

10:26:43

out the spooky face. So just to remind

10:26:45

you, you have to use the logical and

10:26:47

operator which we learned is symbolized

10:26:51

with these two amperands. So go ahead

10:26:54

and give this a shot right now.

10:27:01

Okay, let's do this. We'll do if open

10:27:03

and close parenthesis and here we'll do

10:27:05

day of month triple equals 13. If it is

10:27:10

the 13th day and if it is the week day

10:27:15

of triple equals Friday

10:27:19

then we are going to log out the spooky

10:27:22

emoji like that. Running the code

10:27:26

nothing happens because it's Friday the

10:27:28

31st.

10:27:30

Flipping this around. Friday the 13th.

10:27:32

Yes, we are logging out the spooky face.

10:27:34

And if we change this to Tuesday,

10:27:38

nothing logs out because this time the

10:27:40

first condition was satisfied. It

10:27:42

evaluated to true. But the second one

10:27:44

was not satisfied. So it evaluated to

10:27:47

false and the and operator requires that

10:27:50

both the first and the second evaluates

10:27:54

to true in order to execute the code in

10:27:57

the body of the if statement. So great

10:28:00

job.

10:28:03

Okay. Now you are going to practice

10:28:05

returning random numbers. And the

10:28:08

problem you are to solve is the rock,

10:28:10

paper, scissor game. If you try that,

10:28:12

it's a game where two people choose with

10:28:14

their hands either a rock, a paper, or a

10:28:16

scissor. And the way it works is that

10:28:19

the rock will beat the scissor, but the

10:28:22

paper will wrap itself around the rock

10:28:24

so that the rock loses. And if the match

10:28:27

is between the scissor and the paper,

10:28:28

the scissor will cut the paper into

10:28:30

pieces. So if those rules were a bit

10:28:33

confusing, don't worry about it. That's

10:28:34

not the point here. Your only job is

10:28:36

actually to create a function that

10:28:38

returns one of the random items in this

10:28:41

array when it's called. So you need to

10:28:43

work with math.random in order to

10:28:46

achieve this. Go back and watch previous

10:28:48

casts if you've forgotten about that or

10:28:50

search for it on Google. That's even

10:28:51

better. And finally, when you have coded

10:28:53

up your solution and want to see mine,

10:28:55

just revert back to this screencast and

10:28:56

I will of course show you how to do it

10:28:58

as well.

10:29:04

Okay, let's do this.

10:29:06

We'll call the function get hand

10:29:09

and inside of it first need to generate

10:29:12

a random index that we're going to use

10:29:14

in order to fetch out rock, paper, or

10:29:17

scissor. So we'll do let random index

10:29:20

like that equals first I'll just do

10:29:23

math.random like that and then actually

10:29:26

I'm going to return random index and

10:29:30

then debug along the way just to be sure

10:29:33

that I understand each step I'm taking.

10:29:36

So here I'll console log the result of

10:29:38

running the get hand function like that.

10:29:41

So now if we run this we're logging out

10:29:43

0.05

10:29:45

or 0.1 or 0.07 07 or 0.97. So a value

10:29:51

between 0 and one not including one. So

10:29:54

0.9999 is the top value. Okay. First

10:29:58

then what we need to do is multiply this

10:30:00

with three. Now if we run it, you see

10:30:03

that I'm getting a value between 0 and

10:30:08

2.9999.

10:30:10

0 to 2.999.

10:30:13

That's my current range. Now the value I

10:30:17

want is either a zero, one or a two. So

10:30:20

I'm not too far from this. And the way I

10:30:22

can get that is by stripping away the

10:30:25

decimals by flooring it. In other words,

10:30:29

math dot floor

10:30:32

like that. Here you can see two 0 2 one.

10:30:37

Yes. Now we are generating random

10:30:40

numbers between zero and two. How can we

10:30:42

use that to get back a random hand

10:30:46

either rock paper or scissor? Well, that

10:30:48

is simply by doing hands and then using

10:30:51

the random index as the index. Now,

10:30:55

let's run this. We're getting scissor,

10:30:58

we're getting paper, and we're getting

10:31:00

rock. Brilliant. Great job.

10:31:05

If you, like me, grew up in the '9s, you

10:31:08

might remember this game, Street Fighter

10:31:10

2 on Super Nintendo. It was really cool.

10:31:12

So now I want to create a copy of this

10:31:14

game called Emoji Fighter. Or actually,

10:31:16

we won't do any fighting here. We'll

10:31:18

just set the stage for two emojis to

10:31:21

challenge each other. So the way it

10:31:23

works is that when the user clicks on

10:31:25

the pick fighters button, I want two

10:31:27

random emojis to appear side by side

10:31:30

with a VS between them for versus. As

10:31:33

you can see, I've coded up the skeleton

10:31:35

for you here by creating this fighters

10:31:37

array, which contains all of our

10:31:39

different fighters and also fetching

10:31:40

references to the stage and to the

10:31:44

button. And the stage is where I want

10:31:46

you to render out the emojis. And the

10:31:48

button is the one right here. As you can

10:31:50

see in the index.js, I've hooked it up

10:31:53

with an event listener so that we listen

10:31:55

for clicks, which we can verify by

10:31:57

inside of this callback function trigger

10:31:59

out click. So that now if we run the

10:32:01

code and click on the button you can see

10:32:03

it is logged to the console. So your job

10:32:06

then is to inside of this function write

10:32:09

the code needed in order to pick two

10:32:12

random emojis from this array and then

10:32:14

display them in the stage l. Now, as a

10:32:17

little hint, if you don't know how to

10:32:19

pick a random item from this array, do

10:32:21

remember that you know how to generate a

10:32:23

random number in JavaScript and then you

10:32:26

can use that random number as an index

10:32:29

which you again use to fetch out one of

10:32:32

these emojis as you hopefully know how

10:32:34

to get a hold of items within arrays

10:32:36

using the items index. So, just do that

10:32:39

twice and then render it out. And if you

10:32:41

struggle, don't worry. As always, I will

10:32:44

show you the solution when you return

10:32:45

back to me. Good luck.

10:32:52

Okay, let's do this. So now what I want

10:32:54

to do first is generate a number that is

10:32:57

between zero and whatever length this

10:32:59

fighters array is. So let's just get

10:33:02

started and do some trial and error. You

10:33:04

let random

10:33:06

index equals math random like that. If

10:33:11

we now console log that out and see that

10:33:15

when we click on the pick fighters we

10:33:17

get random number between zero and one.

10:33:21

So this range is too narrow at the

10:33:23

moment. We need something between zero

10:33:25

and the final index here. So what I'll

10:33:27

do is I'll multiply math random with

10:33:30

fighters dolength like that. Now if we

10:33:34

run the code and click pick fighters you

10:33:36

can see we get 12 point something 2

10:33:37

point something 4 point something 3

10:33:39

point something. Yeah, it actually looks

10:33:41

pretty promising. However, we don't want

10:33:43

these decimals. So, what I'll actually

10:33:45

do, I'll floor this entire expression

10:33:47

down to the closest whole number by

10:33:50

doing math. Floor

10:33:53

and wrapping this entire expression

10:33:55

within the parenthesis of the floor

10:33:57

method. If we now run this again and

10:34:00

choose P fighters, we get 8 9 3 5. Yes,

10:34:04

this is actually really promising. So

10:34:06

now if I instead of logging out just the

10:34:08

random index actually log out fighters

10:34:11

square bracket and then random index.

10:34:14

What do you think will happen then? As

10:34:17

you can see we are logging out a random

10:34:19

emoji. So now what we need to do is

10:34:22

duplicate this line here because we want

10:34:25

two random emojis. We'll do random index

10:34:28

one and random index two like that. And

10:34:31

then let's actually console log out the

10:34:34

first mode plus vs

10:34:38

space before and after and then plus

10:34:41

fighters square brackets random index 2.

10:34:46

We run the code and pick fighters. Then

10:34:48

we get an error. I've done a mistake. It

10:34:50

says random index is not defined. That

10:34:53

is because I forgot to change this

10:34:56

variable into random index one when I

10:34:59

renamed this one because I wanted two of

10:35:01

them. So, a little live debugging

10:35:03

session right there. Let's run it again.

10:35:05

Pig fighters. Yes, now it works.

10:35:08

Dinosaur against a seal. We get to the

10:35:10

console. Meaning that the final thing we

10:35:12

need to do is just replace the console

10:35:13

log with stageel lext

10:35:18

content and then set that equal to the

10:35:21

same expression that we just logged to

10:35:23

the console. If we run the code, click

10:35:26

pick fighters. Yes, there we go. Robot

10:35:28

against crab. Click again, we get a

10:35:30

spider against a dragon. And finally, a

10:35:32

robot against a dragon. So, great job

10:35:35

solving this challenge.

10:35:39

Now, I have a fun little challenge for

10:35:42

you. Because you can see this fruits

10:35:43

array here, which contains emoji fruits.

10:35:46

Basically, three apples and two oranges

10:35:48

mixed together. You are going to take

10:35:50

these fruits and sort them onto the

10:35:52

apple shelf or the orange shelf. The

10:35:55

apple shelf is the one at the top here,

10:35:56

and the orange shelf is the one at the

10:35:58

bottom. They are just simply divs, but

10:36:01

I've given a little bit of styling. So

10:36:04

you are to create a function that when

10:36:06

called puts the apples onto the apple

10:36:08

shelf and the oranges onto the orange

10:36:11

shelf. And you should use a for loop, a

10:36:14

conditional statement, and the text

10:36:17

content property to achieve this. Now,

10:36:20

one thing you might be wondering is how

10:36:22

do you work with emojis in JavaScript?

10:36:24

And actually, you can treat these as

10:36:26

normal strings. It's just as if it said

10:36:28

orange here instead of having the emoji.

10:36:31

So with that, I wish you good luck and

10:36:33

I'll see you later when I'll show you my

10:36:35

solution.

10:36:41

Okay, hopefully that went well. Let's do

10:36:44

this function. I'm going to call it sort

10:36:47

fruit like that. And then inside of the

10:36:50

function, we first need to loop through

10:36:52

all of the fruits for let i equals zero.

10:36:56

I equals less than fruit.

10:37:00

length and I should be incremented

10:37:02

upwards.

10:37:04

Now, inside of this, we need to check

10:37:07

every step in the iteration. Are we

10:37:08

dealing with an apple or are we dealing

10:37:10

with an orange? So, I'll do if fruit i.

10:37:15

That's the current fruit triple equals.

10:37:18

And then I can just copy this apple

10:37:21

here. If it's an apple, well, then we

10:37:23

are going to do apple shelf.ext

10:37:28

text content.

10:37:30

And here we're not going to do just

10:37:33

equal the apple. We're going to plus

10:37:35

equal because we want to gather all of

10:37:37

our apples here and not wipe them out

10:37:39

every time we run this code. Then I'm

10:37:42

going to do an else if root i triple

10:37:47

equals this time an orange. Well, then

10:37:51

we are going to head over to the orange

10:37:54

shelf and do text content

10:37:58

plus equals the orange. Now, it would

10:38:01

have worked perfectly fine if we just

10:38:03

omitted this as well like that because

10:38:06

in our array, if it isn't an apple, we

10:38:08

know that it's an orange, but we might

10:38:11

be getting other arrays which have

10:38:12

bananas in them as well. And if so, we

10:38:14

don't want to put any bananas in the

10:38:16

orange shelf. We want to check

10:38:18

explicitly that we are dealing with an

10:38:19

orange before we put the fruit up on the

10:38:22

shelf. So finally, we just need to sort

10:38:25

fruit.

10:38:26

We run the code. Let's do that. And

10:38:29

there we go. We got three apples and two

10:38:31

oranges neatly sorted on both of the

10:38:34

shelves. So great job.

10:38:40

Okay, now it's time for you to do a new

10:38:43

solo project. And this time you're going

10:38:45

to create a random password generator

10:38:48

because in today's day and age it is

10:38:50

critically important that you have

10:38:52

secure passwords for all of the services

10:38:54

you use. If not, it'll be easy for

10:38:56

people to hack your accounts. So let's

10:38:58

have a look at the project you're going

10:39:00

to build. It has only one piece of

10:39:02

interactivity and that is that user can

10:39:04

click this generate passwords button and

10:39:06

then two different passwords will be

10:39:09

generated in the fields below here. And

10:39:11

you are going to build this from

10:39:13

scratch. And I'm putting that in quotes

10:39:15

because I've given you the characters

10:39:17

array that you can use in order to

10:39:19

generate these passwords here at the top

10:39:21

of the index.js file because it's a

10:39:23

hassle for you to find this online. So I

10:39:25

wanted to give you this so that you can

10:39:26

hit the ground running. And as I said,

10:39:28

you are to generate two random passwords

10:39:31

when the user clicks the button. And

10:39:32

each password should be 15 characters

10:39:35

long. Now, if that is too easy for you,

10:39:37

I also have some stretch goals, but you

10:39:39

should only try these stretch goals if

10:39:41

the rest of this challenge is a breeze

10:39:43

for you. So, if you struggle, don't do

10:39:46

these stretch goals. The first one would

10:39:48

be the ability to set a password length.

10:39:50

That would probably have to be some kind

10:39:51

of input field where the user can say

10:39:53

how many characters they want to have in

10:39:55

their passwords. And also a copy on

10:39:57

click feature would be really nice so

10:40:00

that when the user clicks on any of

10:40:01

these passwords they will be

10:40:03

automatically copied to their

10:40:04

clipboards. Also you could give a couple

10:40:07

of toggle options here where the user

10:40:09

gets to modify whether or not they want

10:40:11

symbols and or numbers in their

10:40:14

passwords or not. So here you'd probably

10:40:17

have to split out the numbers which you

10:40:19

can see here and the symbols which you

10:40:22

can see here and then use them or not

10:40:24

depending on what the user wants. As

10:40:27

always you can find the design in a

10:40:28

Figma file. Just click on this image

10:40:31

right here and you'll be taken to that

10:40:32

file and there you will actually see

10:40:34

that we provide a dark mode version and

10:40:36

a light mode version. So feel free to

10:40:39

choose the one you like best. Now you

10:40:41

might see other students being inside

10:40:43

this exact Figma file. So what you want

10:40:45

to do is click on this downward arrow

10:40:47

here and choose duplicate as that'll

10:40:50

give you your very own Figma file to

10:40:52

work with without getting disturbed by

10:40:54

cursors from other students. Now if

10:40:56

Figma confuses you a bit, don't worry.

10:40:58

Just click this link right here and

10:41:00

you'll be taken to a short Figma

10:41:02

tutorial. And if you get stuck, click on

10:41:04

the help section link right here and

10:41:06

you'll get some hints. Okay, I'll leave

10:41:08

you with the requirements here on the

10:41:10

lefth hand side and the design here on

10:41:11

the right hand side which you of course

10:41:13

can click at if you want to get to Figma

10:41:15

and also a link to the help section

10:41:17

below. So that should be everything you

10:41:19

need in order to get started. I wish you

10:41:21

the best of luck and happy coding.

10:41:27

Hey, and welcome to this section where

10:41:28

we are going to build a Chrome

10:41:30

extension, which is just so freaking

10:41:32

cool because Chrome extensions, if you

10:41:35

haven't seen them, are programs that can

10:41:38

enhance your browser experience in

10:41:40

Chrome. This is an example called Honey.

10:41:42

It's really brilliant because what it

10:41:44

does is gather coupons from all over the

10:41:47

web and when you visit a page where you

10:41:49

want to buy something, it gives you

10:41:50

whatever coupons it can find online so

10:41:53

that you can save money. And it was

10:41:55

acquired by PayPal for $4 billion. So

10:41:58

building Chrome extensions is huge

10:42:00

because I mean everyone uses browsers

10:42:03

and and surely what comes out of the box

10:42:05

when you use Chrome surely hasn't

10:42:07

thought of every single problem people

10:42:09

might encounter when they are using

10:42:11

browsers and browser extensions is our

10:42:13

way as developers to build solutions

10:42:15

around these problems. Here's another

10:42:17

one. Grammarly I use it all the time

10:42:19

here. So when I write for so for so for

10:42:22

example when I write tweets it sits on

10:42:24

top of Chrome and checks my spelling

10:42:26

because it has access to what I do on

10:42:28

the page and then suggests how I should

10:42:30

improve my spelling and my writing in

10:42:32

general. And this one right here is a

10:42:34

lifesaver. It's motion and it saves me

10:42:38

hours every single day by stopping me

10:42:40

right before I try to enter for example

10:42:42

Facebook. And it does this with a ton of

10:42:43

other distracting sites as well so that

10:42:45

I can focus on what matters like for

10:42:47

example creating courses on Scrimbo or

10:42:48

writing code or doing productive stuff.

10:42:50

So so cool. If you want to check out

10:42:53

more extensions, you can head over to

10:42:54

chrome.google.com/webstore.

10:42:57

There you can search through all of

10:42:59

them. And also if you want to open your

10:43:01

extensions in Chrome, just click this

10:43:02

puzzle icon in the top right corner and

10:43:04

you'll see all of your extensions. And

10:43:07

here you can see leads tracker. What's

10:43:09

that? Well, that is the one we are going

10:43:11

to build in this section. It is based on

10:43:13

an insight I had when I worked as a

10:43:15

developer in a company called Senetta,

10:43:17

which is a provider of price information

10:43:19

for people who are shipping containers.

10:43:22

Because what I saw there was that the

10:43:24

sales team at that company spent

10:43:26

countless hours tracking down leads or

10:43:29

sourcing leads as they also call it. And

10:43:31

that is looking for people online who

10:43:33

might be interested in your product. So

10:43:34

what they do is like browse through a

10:43:36

bunch of pages and look at people and

10:43:37

like no this guy is probably not

10:43:39

interested in our product. This one

10:43:41

neither. Ah yes, here we have a

10:43:42

potential customer. Let's save this one

10:43:44

to our system. Moving on. This person

10:43:46

does not look like a potential customer

10:43:47

but this one does. Yeah. And this one

10:43:49

does as well. But this one does not look

10:43:51

like a potential customer. So what they

10:43:53

then had to do is take these three

10:43:54

potential customers and store them

10:43:56

somewhere so that they could reach out

10:43:57

to them in the next phase. And this is

10:44:00

something that and this is something

10:44:01

that basically every single sales

10:44:03

representative does because I mean you

10:44:05

need people to sell to. So you need to

10:44:06

find them somewhere. So our leads

10:44:08

tracker will be a tool for these kinds

10:44:11

of people. The way it works is that you

10:44:13

visit a website, for example, a profile

10:44:14

on LinkedIn and then you open up the

10:44:17

extensions, click on the leads tracker

10:44:19

and there you can see you get the

10:44:21

ability to save input. That is any URL

10:44:24

that you pass into this input field or

10:44:26

hit save tab. If you hit save tab, our

10:44:29

extension heads over to this tab, grabs

10:44:31

the URL and saves it in a list. Then you

10:44:34

can move on to another page, for

10:44:36

example, my LinkedIn page, and then hit

10:44:38

save tab again. And boom, there we have

10:44:40

the URL to my profile. And then moving

10:44:42

on, this is Synindra, our CTO in

10:44:44

Scribba. Yet again, we click save tab

10:44:46

and his profile URL is saved. And this

10:44:49

data is persisted. So you can close down

10:44:51

the app or Chrome, turn off your

10:44:53

computer, and when you come back, it's

10:44:54

still there. So that you as a sales

10:44:56

representative can then grab these leads

10:44:58

and do something else with it. So this

10:45:00

is actually a pretty useful tool for

10:45:02

sales representatives. And it's actually

10:45:04

deployed in the browser so that you can

10:45:06

use it in the real world. And the point

10:45:08

with this is to give you the powers to

10:45:11

do this to actually create Chrome

10:45:13

extension that has value and also give

10:45:16

you the skills you need to deploy it to

10:45:18

someone's browser. So once you've

10:45:20

learned this, I would really recommend

10:45:22

you to look for opportunities. Look for

10:45:24

problems you see out in the world. Maybe

10:45:26

there's a problem you have or or someone

10:45:28

you study with or someone you work with

10:45:30

or just a problem someone tells you

10:45:32

about. when you come across problems

10:45:34

people have, I want you to think, can I

10:45:36

build a Chrome extension to help solve

10:45:38

this problem? Because if you can do

10:45:40

that, you truly have a superpower and

10:45:43

that'll manifest itself in opportunities

10:45:45

that you will get throughout your career

10:45:47

if you're just willing to use that

10:45:49

superpower, which JavaScript and web

10:45:51

development is. So, this was a long

10:45:53

introduction. I hope you are as excited

10:45:55

as me. Let's just move on and build your

10:45:59

very first Chrome extension.

10:46:04

Okay, in this challenge, you are going

10:46:05

to create the basic markup we need in

10:46:08

order to start building our app. So, you

10:46:10

are to create an input element which is

10:46:13

of type text and has the ID of input-l.

10:46:17

And then you're going to create a save

10:46:19

input button. That is the one the user

10:46:20

will click in order to save the input.

10:46:23

And it should have the ID of input-bn.

10:46:26

And here save input should be the text

10:46:28

inside the button. So go ahead and do

10:46:31

this right now.

10:46:37

Okay, let's do this. I'll start with the

10:46:40

input and give it a type of text and ID

10:46:44

of input L. And the input element is a

10:46:49

so-called void or empty tag, meaning it

10:46:52

only has an opening tag. So you're not

10:46:54

supposed to create hosting tag because

10:46:56

you're not meant to write anything in

10:46:58

between input tags. It is the user that

10:47:01

is meant to add the input. So this is

10:47:04

how you create an input tag which has

10:47:06

mentioned often called void or empty

10:47:08

tags or you'll also hear them referred

10:47:10

to as self-closing tags. Anyway, let's

10:47:13

move on to the button. New button that

10:47:16

is not a void tag. It should have a

10:47:19

closing tag and an opening tag. And in

10:47:22

between we are going to write save

10:47:24

input. And the ID is set here as

10:47:28

input.btn.

10:47:30

If we now run this code, you see yes

10:47:32

indeed we have an input field and a

10:47:35

button. Great job.

10:47:40

Okay. Now you are going to style our app

10:47:42

according to this design.

10:47:45

So, in the CSS file, which is where

10:47:47

you're going to work, you'll see that

10:47:49

I've already styled the body tag a

10:47:51

little bit. Specifically, I've cleared

10:47:54

out the margin. Since browsers often add

10:47:56

a default margin to the body tag, I had

10:47:59

to set that to zero to neutralize that

10:48:01

because I don't want any margin on the

10:48:03

body. However, I've set the padding to

10:48:05

10 because I do want a little bit of

10:48:07

padding. You can see here on the body

10:48:09

element that there's some space between

10:48:11

the edges and where our elements start.

10:48:13

That is the padding that is provided in

10:48:16

here. I've also set a font of Ariel and

10:48:19

that is a web safe font. So that one

10:48:21

should work without for example using

10:48:23

Google fonts in our project as well. So

10:48:27

just click on the slide here when you

10:48:28

want to see the design and click outside

10:48:31

of the slide when you want to go back to

10:48:32

the code. And I've also added a little

10:48:35

helper text here which is the

10:48:37

hexadesimal code of the green color

10:48:39

which you can see on the button and on

10:48:41

the borders of the input field. Now you

10:48:44

can see on the bottom image here that

10:48:46

I've added some text to the input field.

10:48:48

The slightly bluish color in the

10:48:50

background here is not something you are

10:48:52

to configure. That's just default

10:48:54

styling that is added by the browser. So

10:48:56

you don't have to think about that. As

10:48:58

far as you know the background of the

10:49:00

input element will be white. Now, I'm

10:49:03

going to get you started here with

10:49:04

making the input element full width

10:49:06

because that's a little bit unintuitive

10:49:08

and I want to show it to you because as

10:49:11

you can see here on the input element

10:49:13

when we enter text into it, we have a

10:49:16

little gap between the text and the edge

10:49:18

of it. However, in our app now, if I

10:49:21

like that you will see that there is

10:49:23

basically no gap. So, we have to add a

10:49:26

little bit of padding on the left side.

10:49:29

Let's say 10 pixels. And there you can

10:49:31

see we got the gap. We want the same gap

10:49:33

on the right hand side as well. So I'll

10:49:35

do padding right of 10 pixels as well.

10:49:38

So now we have that. And you might

10:49:40

wonder why I started there. It's a

10:49:41

little bit weird. But let's say that we

10:49:43

now want to provide the styling for

10:49:44

making this input field be full width.

10:49:47

Well then I'll do width and then set it

10:49:50

to 100%. That means take up all the

10:49:54

available space I have inside of my

10:49:57

container. And for the input field, the

10:50:00

kind of container it lives inside of is

10:50:02

the body tag.

10:50:04

So that means that 100% should make the

10:50:08

input field take up the entire body. And

10:50:10

the body has a little bit of padding as

10:50:12

you know. So I would expect this to

10:50:14

actually stop at the right 10 pixels

10:50:18

before the end of our browser. But

10:50:19

actually it doesn't do that. It

10:50:20

continues on and actually goes past our

10:50:23

browser which is a little bit weird. The

10:50:26

reason is that the true width of this

10:50:30

element now is

10:50:33

100%

10:50:34

plus 10 pixels plus 10 pixels because it

10:50:37

includes the padding left and the

10:50:39

padding right and adds that on top of

10:50:41

this width. So that's a problem and it

10:50:44

results in our input field being wider

10:50:46

than our body tag and we don't want

10:50:48

that. So the trick I'll use to avoid

10:50:51

that is something called box sizing. And

10:50:55

here I say I want you to size the box

10:50:58

along its borders. I'll write border

10:51:02

box. And there you can see now full

10:51:06

width includes the paddings as well. The

10:51:09

100% now takes into account the paddings

10:51:13

and just make sure that the entire thing

10:51:15

spans across the entire body tag but not

10:51:19

overflowing it.

10:51:22

I wanted to show you that because it's

10:51:23

not entirely intuitive. Now you have

10:51:26

what you need. Your job is to use only

10:51:30

these two selectors, the input and the

10:51:31

button selector, and make it look like

10:51:34

the design you can see here on the

10:51:35

slide. So go ahead and give that a shot

10:51:37

right now.

10:51:43

Okay, hopefully that went well. Now

10:51:45

let's do this together. I'm going to

10:51:48

continue with our input element because

10:51:50

here we'll see that it's very crammed

10:51:54

above and below the text we have written

10:51:56

in the input field. So what I can do is

10:51:59

padding bottom also of 10 pixels and

10:52:03

padding top

10:52:06

also of 10 pixels. Now we have something

10:52:10

that looks much more like what we have

10:52:12

here. Next up, we also need the color on

10:52:15

the border. So, we'll do border

10:52:20

one pixel

10:52:22

solid and then use this green color here

10:52:26

like that. Think look good. Now, we can

10:52:30

actually continue with the button. The

10:52:32

first thing is the background color

10:52:34

which is green. We'll do background

10:52:38

and use this green color again like

10:52:41

that. Okay. Also the text is white color

10:52:46

white like that. You see there's also

10:52:49

padding here as well which we need to

10:52:51

add. There's a little bit more padding

10:52:53

on the left and right hand side. Let's

10:52:55

try padding top of 10 pixels and padding

10:53:00

bottom of 10 pixels and then padding

10:53:04

left of 20 pixels. Yeah, starting to

10:53:07

look good. Padding right of 20 pixels.

10:53:12

And now I actually want to clean up our

10:53:14

code a little bit because you can see

10:53:15

we're using this very verbose way of

10:53:17

writing paddings both here and here.

10:53:20

Whereas in the body as you have learned

10:53:21

previously in this career path you can

10:53:23

use the short hand. And if all of the

10:53:27

top bottom left right are of the same

10:53:29

value we can just use padding. So I can

10:53:31

remove all of these and do padding 10

10:53:34

pixels. Here it's a little bit more

10:53:36

complex but the top and bottom are

10:53:39

identical and the left and right are

10:53:40

identical. What we then can use is

10:53:43

adding and then 10 pixels for the top

10:53:45

and bottom and then 20 pixels for the

10:53:48

left and right. So the first value kind

10:53:50

of becomes the y-axis above and below

10:53:53

and the second value becomes the x-axis

10:53:56

to the left and to the right.

10:53:58

If I remove this, you now see that it

10:54:01

looks identical as how we had it

10:54:02

previously, but we've removed a ton of

10:54:04

lines, which is good. Now, uh, another

10:54:07

thing on the button is that it has these

10:54:10

default borders. We don't want that

10:54:12

according to our design. So, we'll do

10:54:15

border none like that.

10:54:19

Now, it's really starting to look

10:54:20

similar, but there's two things. We want

10:54:22

to bold the text and we need a little

10:54:24

gap between the input field and the

10:54:26

button. So, font weight

10:54:31

bold. Yes.

10:54:34

And the gap between the button and the

10:54:36

input can be added to either of the

10:54:38

elements. I'm going to add it to the

10:54:39

input field. Do use a margin

10:54:44

button and set it to for example four

10:54:46

pixels. There we go. Now we have

10:54:49

something that looks pretty much like

10:54:51

what we have and it's also responsive.

10:54:55

So we are ready to move on.

10:55:00

Okay. Now we are going to move from the

10:55:02

CSS over to the JavaScript because we

10:55:05

have to make our input button work. And

10:55:08

while you won't make it useful in this

10:55:10

cast, you will at least have it log out

10:55:13

button clicked when the user clicks it.

10:55:16

So you know how to do this, you're going

10:55:19

to have to modify both some HTML and

10:55:22

write a function in the JavaScript file.

10:55:25

So go ahead and do it so that when I

10:55:26

click the save input button, the console

10:55:29

will log out button clicked. And once

10:55:32

you are done, return back to the

10:55:33

screencast and I will show you the

10:55:34

solution as well. Good luck.

10:55:41

Okay, hopefully you remembered that the

10:55:44

way to do this is to create an on click

10:55:47

handler on the button. There you want to

10:55:49

type the name of the function you want

10:55:50

to trigger. Let's call this function

10:55:53

save lead for example open and close

10:55:55

parenthesis. Then we'll head over to the

10:55:58

index.js file and create that function

10:56:02

function save lead like that and inside

10:56:06

of it we'll do console log button

10:56:09

clicked like that. We'll run the code

10:56:13

click the button and indeed we are

10:56:14

logging out button clicked. Great job.

10:56:20

So, while this way of writing event

10:56:22

listeners where we define a function and

10:56:25

trigger it via the onclick attribute in

10:56:27

the HTML works perfectly fine out in the

10:56:30

wild, you'll most likely see

10:56:31

professional developers use a slightly

10:56:33

different technique. So, it's important

10:56:36

that you learn that one as well. And the

10:56:38

way we do that is by first grabbing a

10:56:41

hold of the ID of the element we want to

10:56:44

hook an event listener onto. So I'll do

10:56:47

let input btn equals document dot

10:56:51

getelement

10:56:53

by id pass asing in the input batch btn

10:56:57

and then what I'll do is input btn dot

10:57:01

addvent

10:57:03

listener like that and inside of the add

10:57:07

event listener function or method which

10:57:09

it's also called I'll first specify what

10:57:12

kind of event I want to listen for and

10:57:14

here it is

10:57:15

click events and then I'll write a comma

10:57:18

and do something which might look a

10:57:20

little bit weird because now we are

10:57:22

going to define what are we going to do

10:57:24

when someone clicks on this input

10:57:26

button. Well, we are going to invoke a

10:57:28

function and in order to invoke that

10:57:29

function, we first have to write it. So,

10:57:31

I'll do function open and close

10:57:33

parenthesis and then the curly brackets

10:57:35

and break it onto a new line. And inside

10:57:37

of this function, we can write whatever

10:57:39

code we want to be executed when the

10:57:42

user clicks on this input button. So

10:57:46

here we'll do console.log

10:57:48

button clicked from add event listener

10:57:51

like that. And let's change this to

10:57:53

button click from on click attribute.

10:57:57

Now if we run this code, hit the button,

10:57:59

you can see both this line and this line

10:58:02

is executed. However, now we can

10:58:04

actually remove this on click event

10:58:07

listener from our HTML. And some would

10:58:09

say that this results in a cleaner

10:58:11

separation of concerns where the HTML

10:58:14

doesn't worry about any event listeners

10:58:16

as that's all gathered in the

10:58:18

JavaScript. So of course then we should

10:58:21

also remove the save lead function and

10:58:23

we're left with this. Running the code,

10:58:26

clicking the button and only this line

10:58:28

triggers.

10:58:30

So in the next cast you are going to get

10:58:32

some practice writing this type of event

10:58:34

listeners. So let's dive into it.

10:58:40

So in this challenge you are going to

10:58:41

practice writing event listeners using

10:58:44

the technique you just learned. So it's

10:58:46

a three-part challenge where you first

10:58:47

are to grab the box from the DOM and

10:58:50

store it in a variable. Here you can see

10:58:52

the box. It's just a rectangle that says

10:58:54

open the box. You can imagine that this

10:58:55

is some kind of Easter egg on a

10:58:57

e-commerce website where if you open the

10:58:59

box, you get a coupon or something like

10:59:01

that. And as for HTML, it's just a very

10:59:04

simple div with an ID of box. And of

10:59:07

course, I've styled it a little bit in

10:59:08

the CSS file, but we're not going to

10:59:10

worry about that. So, when you have

10:59:12

grabbed the box from the DOM and stored

10:59:14

it in a variable, you are to add a click

10:59:16

event listener to it. And then finally,

10:59:18

log out. I want to open the box when the

10:59:20

box is clicked. So, if you struggle to

10:59:23

remember how to add an event listener

10:59:24

using JavaScript, you can go back and

10:59:27

rewatch how I explained that or even

10:59:29

better, Google it out and you should

10:59:31

find the solution as well. With that, go

10:59:33

ahead and solve this challenge right

10:59:34

now.

10:59:40

Okay, hopefully that went well. Let's do

10:59:42

this. So we'll do let box equals

10:59:46

document dot getelement

10:59:49

I id passing in ox and then to add the

10:59:52

event listener it's box dot addvent

10:59:57

listener passing in first the event we

11:00:00

want to listen for that is the click and

11:00:03

then what do we want to trigger when the

11:00:05

user clicks well it's this function

11:00:08

right here and inside of it we're going

11:00:10

to console log I want to open the box.

11:00:15

Like that. Let's run the code. Click the

11:00:18

box. And yes, it works. Great job.

11:00:25

Okay, we are back at our lead tracking

11:00:27

app. Now, of course, you are going to do

11:00:30

what I showed you before you learned

11:00:31

about ade event listener, which is to

11:00:33

refactor our app so that it uses the

11:00:36

addeventlister when you click on the

11:00:38

save input button. Cuz this is Grimba.

11:00:41

I'm not supposed to write the code. So

11:00:43

even though I've already done it, now

11:00:45

it's your turn. So go ahead and do this

11:00:47

right now.

11:00:52

Okay, hopefully that went well. Now I

11:00:55

will quickly do it as well. We need to

11:00:58

grab a hold of the button. I'm going to

11:01:00

grab the ID here and do let input btn

11:01:05

equals document.getelement get element

11:01:08

by id passing in the ID. Now that we

11:01:12

have that, we can do input btn dot add

11:01:16

event listener. We're going to listen

11:01:18

for clicks. And the code we want to run

11:01:22

when users click the button is inside of

11:01:24

the body of this function right here.

11:01:28

So I'm going to copy this console log,

11:01:30

paste it in there

11:01:32

that now I can remove the save lead

11:01:34

function and I can also remove the

11:01:37

onclick attribute in the HTML like that.

11:01:41

I'll rerun the code. Click save input

11:01:43

and indeed it works. Great job. Let's

11:01:47

move on.

11:01:50

Now we need to set up the infrastructure

11:01:52

for being able to actually save the

11:01:55

leads that we enter into our input

11:01:57

field. And for that we need two

11:01:59

variables. First a my leads variable

11:02:02

which should be assigned to an empty

11:02:04

array. Secondly the input L variable

11:02:08

which should be assigned to the text

11:02:10

input field. With that I mean the input

11:02:13

field right here. So go ahead and create

11:02:16

these two variables right now.

11:02:23

Okay, the way to do this is let my leads

11:02:28

equals an empty array like that. And for

11:02:31

the input L, you probably did let input

11:02:35

L equals document

11:02:38

element by ID passing in the input L.

11:02:42

However, what I'm going to do is to swap

11:02:45

out this let with const. Hm, that's

11:02:49

weird. Why am I doing that? You might

11:02:52

wonder. And that is because in modern

11:02:54

JavaScript developers use both let and

11:02:58

const to declare variables. And now I

11:03:00

think it's about time that you learn

11:03:02

both of these methods. So we're going to

11:03:04

set the input l as a const and also the

11:03:08

input btn. Now the main difference

11:03:11

between const and let is that const

11:03:15

cannot be reassigned

11:03:18

and the name kind of hints to that. It

11:03:20

says const which is short for constant.

11:03:23

So whatever you assign it to should be

11:03:26

constant meaning you can't reassign it.

11:03:29

And if you don't remember what

11:03:30

reassignment is, it's when you do input

11:03:33

I'll for example equals

11:03:36

hello.

11:03:38

This won't work. If I run this code, you

11:03:41

can actually see assignment to constant

11:03:43

variable. I tried to assign the input

11:03:46

lel. However, it's a constant. So,

11:03:49

JavaScript is saying uh uh not allowed.

11:03:52

Now, you might ask, why do we need this?

11:03:54

This seems to be something that just

11:03:55

makes it more difficult for us to code

11:03:57

because it gives us less freedom. Well,

11:04:00

that is a very good question. So in the

11:04:02

next cast, we'll dig into exactly that

11:04:04

so that you properly understand why you

11:04:06

want to use both let and const and

11:04:08

actually get some practice using both of

11:04:10

these variable types.

11:04:15

Okay, let's say that we are back at our

11:04:16

blackjack game and we have two variables

11:04:19

player name and credits. The first one

11:04:21

is a const whereas the second one is a

11:04:23

let. Now immediately upon seeing these

11:04:26

two variables, a developer would

11:04:28

understand that player name is not to be

11:04:30

reassigned. However, this developer

11:04:32

wouldn't only think that credits can be

11:04:35

reassigned, it would actually assume

11:04:37

that credits are to be reassigned

11:04:39

further down in the code. So the

11:04:41

developer would expect something like

11:04:43

credits equals dreads minus 10, for

11:04:46

example. And the reason for that is that

11:04:49

developers often use the following to

11:04:51

decide whether or not they should use

11:04:53

const or let. So if possible, default to

11:04:57

using const. If not, use let. If these

11:05:01

two lines follow this methodology, it

11:05:03

would mean that it simply wasn't

11:05:05

possible to write credits as a const

11:05:07

because it is going to be reassigned

11:05:09

later down in the code. And thus we

11:05:11

skipped the default of const and used

11:05:13

let instead. And this is actually the

11:05:15

biggest benefit with const. It gives us

11:05:17

a way to quickly signalize to anyone who

11:05:20

are reading the code what we want to do

11:05:22

with the variables. So in addition to

11:05:24

expecting that something like this here

11:05:26

would happen, the developer would also

11:05:28

be very suspicious if she saw something

11:05:30

like player name equals something else

11:05:33

down here because that would mean that

11:05:35

the person writing this code mixed up

11:05:38

their let and const

11:05:43

error. So with all of this knowledge and

11:05:46

following this methodology, I want you

11:05:49

to do a challenge. Which of the

11:05:51

variables below should be changed from

11:05:54

let to const? Here the situation is an

11:05:57

e-commerce shop where you have a base

11:05:59

price, a discount, a shipping cost, and

11:06:01

shipping time. At some point though, the

11:06:03

details of the shipping changes and then

11:06:05

you calculate the full price and finally

11:06:08

notify the customer. So go ahead and

11:06:10

change some of these variables to const

11:06:13

and then I will show you the solution

11:06:14

afterwards as well.

11:06:19

Okay, let's do this. I'm going to start

11:06:22

down here on where things are

11:06:24

reassigned. It's easy to see that these

11:06:26

are reassignments since we're starting a

11:06:27

new line with just the variable name,

11:06:30

not let in front of it. So here we are

11:06:32

reassigning shipping cost and shipping

11:06:34

time. Meaning these two can be let and

11:06:38

this is a new variable. So actually

11:06:40

here's the end of our code and base

11:06:43

price and discount they haven't changed.

11:06:45

So they could be const and it says here

11:06:47

if possible use const. So default to

11:06:50

const. So then I'll do const and const

11:06:53

like that. And the code works perfectly

11:06:56

fine. I haven't broken anything. Is

11:06:57

there anything else we can do? Yep.

11:06:59

Actually, it is here at full price. We

11:07:02

see that this variable is only assigned

11:07:04

once. It's not reassigned further down,

11:07:07

just used here in the console log.

11:07:09

Meaning that this one also should be a

11:07:12

const. So hopefully you now understand

11:07:14

why we want to use const and let. And if

11:07:16

it's still a bit confusing, don't worry

11:07:18

about it. We're going to continue using

11:07:19

these variables throughout this course.

11:07:22

So eventually it'll be completely

11:07:23

natural for you to switch between the

11:07:25

these two variable types. With that,

11:07:28

let's return back to our lead tracker

11:07:30

app.

11:07:33

Okay, we are back in our lead tracker

11:07:35

app. And now we need to make sure that

11:07:37

when the user hits the save input

11:07:39

button, a lead is pushed to the myle

11:07:42

leads array. For now, you're just going

11:07:44

to use a hard-coded lead. So,

11:07:47

www.awomelead.com,

11:07:49

for example, and that value should be

11:07:51

pushed to my array when the input button

11:07:55

is clicked. So go ahead and give this a

11:07:57

shot right now.

11:08:03

Okay, hopefully what you did was to here

11:08:06

inside of the body of this function

11:08:08

write my leads

11:08:11

push and then pass in www.

11:08:15

awesomele.com

11:08:18

like that. If we now also console log

11:08:21

out the my leads array like that, we

11:08:24

will actually verify that it works. I'll

11:08:26

hit the save input button and there you

11:08:28

can see we now have one lead in the my

11:08:31

leads array. If I hit it again, we have

11:08:33

two and three and four. However, it's

11:08:36

pretty useless because we're just

11:08:38

pushing the exact same thing to the

11:08:40

array. So, let's fix up that in the next

11:08:43

cast.

11:08:46

Okay. So now we are going to take

11:08:48

whatever the user enters into the input

11:08:50

field right here

11:08:53

and push that value into the my leads

11:08:55

array when the save input button is

11:08:58

clicked. So push the value from the

11:09:01

input into the my leads array instead of

11:09:04

the hard-coded www.awomeleads.com

11:09:07

value right here. However, I haven't

11:09:10

taught you how to actually get the value

11:09:14

from the input L. That is, for example,

11:09:16

this www.example

11:09:18

value right here. So, you need to Google

11:09:21

that. And that's great practice because

11:09:23

googling is, as you know, something

11:09:25

professional developers do every single

11:09:27

day.

11:09:29

So, here is what I recommend you to

11:09:31

Google. Try to find, for example, a

11:09:33

Stack Overflow question and see if you

11:09:35

can figure it out on your own. If you

11:09:37

don't, no worries. I will solve this for

11:09:39

you when you return back to this cast.

11:09:42

So, go ahead and do this right now.

11:09:49

Okay, hopefully this went well. Let's