⭐ If you would like to buy me a coffee, well thank you very much that is mega kind! : https://www.buymeacoffee.com/honeyvig Hire a web Developer and Designer to upgrade and boost your online presence with cutting edge Technologies

Friday, November 7, 2025

12HR+ Coding Bootcamp!

 Hello everyone and welcome to this online Coding Bootcamp. This Bootcamp has been designed specifically to make your coding journey easier by utilising all of ‪@YouTube‬ functionalities such as the Timestamps and Cards. We will be using the Timestamps to break up our Bootcamp into sections, so that you can easily navigate to and from each one using the description below. I will also be using Cards in order to direct you to an external project you can try, based on where we are in our Coding Journey. I have also provided Code Sandboxes at the bottom for those stuck on code setup for the learning sections. I would advise to always type out the code to each exercise yourself, but as a safety net, they are provided as well. This 12hr+ Bootcamp is unsponsored and free and will always be free, so if you enjoy it please do give a big thumbs up and Subscribe! If you liked this course, and would like to buy me a coffee: https://www.buymeacoffee.com/aniakubow Weekly coding tips from my newsletter partnership: http://bit.ly/JS-tips Content: 00:00 Introduction 03:34 Code Editors -- HTML -- 06:05 HTML Introduction 08:22 HTML Boilerplate setup 10:55 HTML Elements 17:53 Online Portfolio Project -- CSS -- 20:05 Check-in 21:02 CSS Introduction 23:37 File set up 27:42 Class names and Id's 30:48 Pop Quiz 37:52 Box Model 39:56 Colours 44:12 Unordered and Ordered Lists 49:33 Images 54:22 Styling classes as id's 57:07 The Data property 59:00 Flexbox 01:01:45 Pop Quiz 01:03:41 Flexbox website layout 01:09:43 Commenting out Code 01:13:37 Gradients in CSS 01:15:53 Box Shadows in CSS 01:17:18 Button Styling in CSS 01:25:51 Fonts 01:29:25 Generic Website Layout 01:34:28 making a NavBar 01:46:54 Anchor Links 01:50:17 Creating Sections 02:13:50 Forms in CSS and HTML 02:26:55 Font Awesome 02:32:12 Break points 02:38:35 Z-index -- JAVASCRIPT -- 02:49:24 Check-in 02:51:07 Introduction to JavaScript 02:52:12 JavaScript file setup 02:58:39 Variables 03:16:15 Control Flow 03:16:40 If Statements 03:26:09 Operators 03:55:39 Fizz Buzz Exercise 04:00:59 for loops 04:07:58 Arrays 04:14:42 Objects 04:24:50 Functions 04:37:51 A Progress Exercise 04:48:20 Arrow Functions 04:52:21 While loop 04:55:23 Built-in-Objects Introduction 04:56:02 .length() 05:01:29 .concat() 05:06:41 .join() 05:12:06 .pop() 05:18:46 .shift() 05:22:13 .unshift() 05:25:32 .push() 05:35:51 .splice() 05:41:47 .forEach() 05:50:25 .some() 05:59:49 .map() 06:07:19 .filter() 06:17:06 .reduce() 06:22:27 .every() 06:28:25 .split() 06:34:25 Array work - Exercises to practise 07:18:06 .addEventListener() 07:26:09 .removeEventListener() 07:33:57 querySelector() 07:39:59 Check-in and Project suggestion 07:40:51 Math.random() 07:53:08 Let's make a Responsive Burger NavBar 08:10:12 Date 08:19:29 setTimeout() 08:29:00 setInterval() 08:44:11 Classes in JavaScript 08:52:16 Check-in and Project suggestion 08:52:58 Keys 09:01:46 switch case 09:22:51 .sort() 09:24:52 Introduction to Algorithms 09:25:16 .includes() 09:27:34 .contains() 09:29:52 .createElement() 09:38:22 Check-in and Project Introduction 10:27:07 Check-in and Project suggestions 10:28:16 Introduction to HTTP 10:36:55 fetch(). GET POST PUT DELETE 11:07:24 Check-in and video suggestion 11:07:53 Storing Projects on GitHub 11:15:58 Where to go next Code Sandboxes: at 04:05: To get started: https://codesandbox.io/s/tender-tdd-n... at 02:53:49: JavaScript set up: https://codesandbox.io/s/distracted-f... at 04:40:24: Functions Exercise : https://codesandbox.io/s/eager-tu-t2691 at 04:50:00: .length() https://codesandbox.io/s/xenodochial-... at 05:06:34: .join() .https://codesandbox.io/s/infallible-j... at 05:13:33: .pop() .shift() .push() https://codesandbox.io/s/optimistic-a... at 05:41:50: .forEach() https://codesandbox.io/s/sharp-ellis-... at 05:55:12: .some() https://codesandbox.io/s/admiring-lam... at 06:07:19: .filter() https://codesandbox.io/s/unruffled-wa... at 06:17:06: .reduce() https://codesandbox.io/s/hopeful-shad... at 07:18:06: .addEventListener() https://codesandbox.io/s/kind-torvald... at 07:26:09: .removeEventListener() https://codesandbox.io/s/ecstatic-rho... at 07:33:57: querySelector() https://codesandbox.io/s/ecstatic-lov... at 08:10:12: Date https://codesandbox.io/s/great-framew... at 08:19:29: setTimeout() https://codesandbox.io/s/clever-chand... at 08:29:00: setInterval() https://codesandbox.io/s/cool-frankli... at 08:52:58: keys: https://codesandbox.io/s/lively-river... Generic Sandbox Setup: https://codesandbox.io/s/hopeful-shad... Portfolio final code (edited): https://codesandbox.io/s/html-lesson-... 

 

 

0:00

hello everyone my name is annel Kuba and I'm a professional software developer YouTuber and your host for this 12h hour

0:08

plus YouTube coding boot camp now what exactly makes this a YouTube coding boot

0:14

camp you may ask and why the 12 hours plus well this course has been specifically built out making the most

0:20

of YouTube's functionality in order to help you on your coding Journey what I mean by this is this is a video boot

0:28

camp which will very much take the full form of a part one being you coding along with me in the video part two

0:36

being me presenting you with some exercises and challenges that you should attempt by yourself before we go through

0:42

the answer together and three at the end of each major section I will be

0:48

directing you to a project I think would be suitable for you to try with the knowledge you have gained so far this is

0:55

going to be an external video on my channel so I will be directing you to the video I suggest via a YouTube card

1:03

at the right moment in time this is also why we are calling a 12-hour plus video

1:09

as the learning content that you will be exposed to on your boot camp Journey will amount to the boot camp itself and

1:16

six suggested external projects to put in your developer portfolio now I am not

1:22

going to Sugar Code it coding can be hard to get your mind thinking like a developer takes practice and a lot of

1:29

repetition to help us do this I have Incorporated that repetition into each section by

1:35

providing you with questions and tasks to complete this is why I cannot stress

1:41

that the best way for you to learn is to get on your laptop and code along with me and not just take notes I find that

1:49

learning code is always better done by doing okay so what exactly are we going

1:55

to learn on this coding boot camp let's break it down in the first section we

2:01

are going to start off with HTML so the language that describes the structure of

2:06

a web page we will then move on to CSS or cascading sty sheets this describes

2:14

how HTML elements are to be displayed and finally move on to JavaScript most

2:20

of our time we'll be focused on JavaScript as there really is a lot to learn with this language this is where I

2:27

will be focusing most of my energy by providing you with some fun lessons accompanied by some exercises and

2:34

projects i' like to make the lessons very visual to break away from the generic teaching patterns we so often

2:41

see in software development here are just a few examples of what you will see on this

2:46

course this of course is a free course and I will be providing you all the necessary documentation and links in the

2:53

description below as well as a breakdown of all our lessons and where you can find them in this video thanks to

3:00

YouTube timestamps you can see a full list of what we're going to learn if you click on the expand button below so go

3:07

ahead and do that this course has been a while in the making and is available to everyone and anyone right here on my

3:14

channel I really do believe that anyone should have the opportunity to learn how to code which is why this course is free

3:21

and will always be free so what are we waiting for let's do it don't forget to

3:27

click and subscribe if you enjoyed this course and I look forward to having you on

3:34

board okay so let's jump right to it first off I want to have a quick discussion about how we're actually

3:41

going to be writing our code to write our code we are going to

3:46

be using a code editor now there are many choices for you to choose from I

3:52

have chosen four that I have used in the past in no particular order we've got

3:58

play code code pen jsfiddle and codee sandbox these are all online editors for

4:04

us to get started straight away for no other reason than for me having to

4:10

choose one I'm going to be using Code sandbox for this course this means that

4:15

the editor that you'll be seeing in this video will be code sandbox however you are absolutely free to use any of the

4:22

other three or find your own because what is important is the file structure it is also important to know

4:29

note that you can have a code editor directly on your laptop this is something that we're going to be doing

4:34

towards the end of the course two options that come to mind are visual studio and

4:41

atom okay so here is a recap of all the code editors available to you please

4:46

have a go at using all of them see which one fits you best or otherwise let's get

4:52

going with code soundbox okay so let's get started now

4:59

in whatever code editor you have chosen please go ahead and make an index HTML

5:06

file in the root of your project this would literally involve you creating a

5:11

file and calling it index with the extension HTML so your code editor knows

5:18

to make this an HTML file if this has worked you will see an icon pop up to

5:24

the left it might be that your code editor has some other files as well for example

5:30

code sandbox has this package Json this is because it's an online code editor so

5:36

it needs a couple of extra files to get us started if you are struggling getting to this point don't worry go to the

5:42

description below where I provided you with a link in order to get started that

5:48

link will provide you with this setup that you see right here okay so once you comfortable and

5:56

have your code edger of choice set up with an index h HTML file in the root of

6:02

your project let's carry on but before we get right into any code

6:08

at all what exactly is HTML hypertext markup language or HTML

6:14

is regarded to be a comparatively simple language which is great HTML is the

6:21

standard markup language for documents designed to be displayed in a browser but what do I mean by markup language in

6:29

computer text processing a markup language is a system of annotating a document in a way that is syntactically

6:35

distinguishable from text meaning when the document is processed for display the markup language is not shown and is

6:44

only used to format the text so for example here we have used the Bold tags

6:49

to make the text in between the two tags appear to be bold when viewed in the browser the idea and the terminology

6:56

evolved from the markup of paper manuscripts for example the revision instructions by editors which is

7:02

traditionally written with a red pen or blue pencil on author's manuscripts such

7:08

markup typically includes both content Corrections such as spelling punctuation

7:13

or movement of content and also typographic instructions such as to make a heading larger or bold face web

7:22

browsers receive HML documents from a web server or from local storage and render the documents into multimedia web

7:29

pages HTML describes the structure of a web page semantically and originally includes cues for the appearance of the

7:36

document HTML elements are the building blocks of HTML pages with HTML

7:41

constructs images and other objects such as interactive forms may be embedded into the render page HTML provides a

7:49

means to create structured documents by denoting structural semantics for text

7:54

such as headings paragraphs lists links quotes and other items

8:00

HTML elements are deled by tags written using angle brackets such as this this

8:06

is an opening tag most opening tags that be accompanied by a closing tag in order

8:12

for this to become an element so for example here we have the tags to make text bold browsers do not however

8:18

display the HTML tags but use them to interpret the content of the page but enough chat let's get to seeing some

8:25

code it is important to note that for this course we're going to be using the latest version of HTML and that is HTML

8:32

5 standard here is the basic file structure for when working with an HTML

8:39

file as you can see here I've gone ahead and created an index HTML file so I've

8:45

called the file index and by giving it the HTML extension my code editor knows

8:51

to treat this as an HTML file the first tag I want to show you is right here so

8:58

that's the tag it is a tag that tells the browser that this is an HTML 5 document as mentioned

9:06

there are previous older versions of HTML so just be aware of that on your journey as a web developer the browser

9:12

needs to know what version of HTML the document is in order to render it

9:18

correctly next we tell the browser where our HTML is starting we do this as even

9:25

though we only have HTML in here for now we can actually write CSS and JavaScript in this document too

9:34

something that I will show you later down the line in this course we going to be using this HTML opening tag and

9:41

closing tag as the root of our document everything else that we want to get

9:46

picked up by the browser has to live inside it next we have the head tag and closing

9:55

tag this is where we store information mainly this is not to be confused with a header

10:03

the head will store information that is not visible in the browser it's for storing and not

10:10

displaying next we have our title tag this is for naming our project we do

10:17

this so we can store what we want to call the project that we are working on and store this in the head so make sure

10:24

is in between the opening tag and the closing tag of the head once again this

10:30

is not a title that we will see in our browser however if you look at the tab

10:35

of the browser your project is in you should be able to see it it will also show up in search results so for example

10:42

in Google next we have the body itself now this is where the visible stuff will

10:48

be this is essentially where we are going to start coding out our web page so let's get to it first up I'm going to

10:56

talk to you about text first we have loads of different headers in HTML we

11:02

can start with an H1 header so that being our largest header hello and this

11:08

can go all the way down to H6 so if I just go ahead and change

11:15

these like so go H2

11:21

H3 H4 H5 and an

11:27

H6 okay we'll save that and open up our browser so you will see here now all the

11:34

headers in chronological order there is nothing P H6 so I can even put an H7 tag

11:41

like so hi and you will see here that it just

11:47

doesn't get applied this is just standard non- formatted text so that covers the headers we can

11:55

also do paragraphs so this is what a paragraph tag would look

12:02

like I am a

12:07

paragraph and there we go unlike headers paragraphs do not have a hierarchy it is

12:14

simply just this next up let's make some text show up in bold so we have two ways

12:20

of doing this I can do this either with a B tag so similar to here I'm just

12:26

going to do it on the paragraph put in a tag and a closing tag of the parts that

12:32

I want to make bold so for example here I made the whole paragraph bold or I can

12:39

simply make one part of it bold so in this example I've chosen the I or I can

12:46

use the strong tag now there is one major difference in this what is

12:51

interesting about the strong tag is that it also has semantic meaning to the browser meaning that the browser will

12:58

read this text as more more important than the rest now we also have the EM

13:04

tag so I'm just going to use it here so you can see what it does first and the closing

13:10

tag this tag has what you call it stress emphasis in the browser it will make

13:16

your text appear italic and once again it will tell the browser that we should be stressing this word also so it has

13:24

semantic meaning so to recap both of these the strong and the EM tag have

13:31

semantic meaning and they are also inline elements what this means is that

13:37

an inline element does not start on a new line and only takes up as much width as necessary this is opposed to a block

13:45

element which we will cover in a bit before we move on however I just want to cover two more tags that are relevant

13:52

for text the first is the a tag this a tag so this one right here

13:59

which I'll do it up here write an a

14:05

tag this a tag is short for anchor and we can use it to link a location within

14:12

the file or link the tag to a completely different web page so here I have

14:18

written an a tag I'm just going to put the words

14:25

GitHub then my GitHub

14:31

page now what I want to happen is that when someone clicks this word right here

14:37

so GitHub or to be precise the word in the anchor tag I want them to be taken

14:45

to my GitHub page which is online at the moment nothing is happening this is

14:51

because we haven't finished our anchor tag yet we need to give it an attribute

14:56

many elements can take attributes attributes are stored in the opening tag so right in here and give extra

15:04

information to the browser in the case of the anchor tag I want to give it the location of where I want the user to be

15:10

taken if they click on the element this is how the

15:15

href which is the attribute that I need to give my a tag will look I would

15:21

simply write href equals and the full or absolute path to

15:27

my GitHub page this will look like so I'm just going to move that out a little

15:33

bit for us to see now what I mean by absolute path is that it is the full

15:39

path to what you are linking to so for example I would have to include the HTTP

15:45

or https part of the URL just putting www will not do at the moment this might

15:52

seem obvious however when you start linking to pages in your projects you will start dealing with relative paths

16:00

to so here we have an example in the first example you will

16:05

see me linking the a tag to a relative path so a file called about HTML in the

16:11

same directory as the file we are in and then below you will see me linking the a

16:16

tag to an external website by providing the absolute path to the web

16:22

page let me show you this with an example I'm going to create a page so

16:27

I'm going to just go here here and call this about

16:33

HTML so we have that page here there's nothing in it yet now in my index HTML

16:40

let's say that instead of linking to my GitHub page I want to link to my about page let's do this here in the H3 tag

16:48

and I'm just going to change this from an H3 to an a tag and give it an hre

16:54

attribute in which I'm going to give the relative part

16:59

to my about page so simply put that if I

17:04

now click on here it will take me to my about page if however I want to link to a file

17:12

that is in a folder so let's go ahead and create a folder I'm going to call it

17:19

details I am going to put my about file into that folder now I'm going to have to go into that folder

17:29

and then get the about page so that is the Syntax for doing that I'm going into the folder called details and then I'm

17:37

getting the about page great okay it is now time to use

17:44

everything we have learned so far in the HTML section in order to build our first

17:49

project this project is going to be an online portfolio the portfolio itself

17:55

will be built out in HTML and CSS we will be be implementing a little bit of

18:00

JavaScript towards the end of our course as well so make sure to save this project as you go okay let's do it

18:08

online portfolio project coming up next I'm going to delete the text in

18:16

here so we're ready for the next section so we have just learned about inline

18:21

elements in HTML if you are curious as to how many inline elements that are out

18:27

there here is a complete list for you we have only gone over a few however there

18:32

are a lot more to go I don't feel we need to go into each and every single one of them I have used the most popular

18:39

ones and I'm going to teach you a few more as this course goes on now let's have a look at the Block Level elements

18:46

here is a full list of all the Block Level elements that are available to you you might already be familiar with some

18:52

as we've already discussed H1 H2 H3 four five and six tags as well as the

18:59

paragraph tag however the one that I think is the most important for the next part of this course is going to be the

19:05

div tag the HTML content division element or the div is the generic

19:11

container for flow content it has no effect on the content or layout until styled in some way using CSS as a pure

19:19

container the div element does not inherently represent anything instead it's used to group content so it can be

19:26

easily styled using the class or ID attributes let's go through this in an

19:32

example so in here I'm going to create my first div element I'm going to give an opening tag and a closing

19:39

tag as mentioned in the slide we would usually use a class attribute so similar to something like

19:46

this and then call it container so we can style it up in the CSS or simly we

19:52

can use an ID to to get to grips with these two concepts of IDs and classes we

19:58

need to start talking about CSS let's do that in the next

20:05

lesson okay so we have made it to the end of the HTML section as mentioned

20:11

there really are a lot of HTML elements that exist in HTML and while we did not

20:17

cover all of them we did Cover the most popular ones as we move on in the course I will be introducing new HTML elements

20:24

to you as well as showing you how to style them we will be doing this with the help of CSS so saying that the CSS

20:33

section is up next once again as a reminder please do code along with me in your IDE of choice I have provided some

20:40

templates for you below in the description if you need help on the setup or if you get stuck through the

20:46

next section so please refer to the description below to grab that template

20:51

now it will have a time stamp next to it to make it clearer as to which one you should use at this point in time

20:59

now let's get to it cascading sty sheets or css is a sty sheet language used for

21:07

describing the presentation of a document written in a markup language such as HTML CSS is a Cornerstone

21:14

technology of the worldwide web alongside HTML and JavaScript CSS is designed to enable the

21:22

separation of presentation and content including layout colors and fonts

21:29

this separation of presentation characteristics enable multiple web pages to share formatting by specifying

21:35

the relevant CSS in a separate do CSS file which reduces complexity and

21:42

repetition in the structural content as well as enabling the CSS file to be cached to improve the page load speed

21:48

between the pages that share the file and its formatting separation of formatting and content also makes it

21:54

feasible to present the same markup page in different styles for different rendering methods such as on screen in

22:01

print by voice and on Braille the name cascading comes from the specified

22:07

priority scheme to determine which style rule applies if more than one rule

22:12

matches a particular element don't worry if all of that went over your head we're

22:17

going to be going through this with examples now one way of adding CSS to

22:23

your div would be to add the style attribute to your opening tag so to do

22:28

do this I would simply add the style attribute like so and equals and then in

22:35

quotation marks I would set the property of width so I'm not making this up this is a CSS property and then I would put

22:44

the width in pixels so PX for pixels and

22:49

then end it with a semicolon when we get inside these quotation marks we are no longer writing HTML we are writing CSS

22:57

so we've got our width let's also set a height so I'm going to say height 200

23:03

pixels semicolon and a background color of

23:11

Green Save and there we have it we have successfully

23:17

styled our first div now this is great however as you can imagine you don't

23:23

really want to be writing all of your CSS in the HTML file it could be very unmanageable and get very messy to solve

23:30

this problem we're going to store all our CSS in one file let's do that in the

23:35

next

23:47

section so the first thing that I'm going to do is as mentioned separate my

23:53

style from my HTML page and create a new file which I'm going to choose to call

24:00

Styles CSS so I am telling my code editor that

24:05

this is now a cascading stylesheet by this extension like so the next thing we actually need to do

24:13

is link up our stylesheet to our index HTML file I'm going to do this with the

24:20

link tag so this is a HTML tag that will allow us to link our stylesheet to our

24:27

HTML file I'm going to do this above the header up here so

24:34

link then pass through

24:44

stylesheet and add the href so I'm linking the Styles

24:51

CSS document that I have written here make sure that it matches correctly otherwise this will not work

24:59

okay now to separating it so I'm essentially going to get all of this in here so as we said everything inside

25:06

quotation marks is considered to be CSS so let's go ahead and cut that out I

25:12

also don't need the style attribute anymore so I'm going to close that now

25:19

as we want to apply styling to the div I'm going to have to somehow tell my

25:25

stylesheet that that's what I want to style I could do this like so I would

25:31

grab the div open up some curly braces and paste

25:36

everything that I had previously and you will see our rectangle is back up our div is

25:45

once again styled now to make this look a little bit neater and more readable it is common to have this layout when it

25:53

comes to CSS let's save this file and let's carry on

25:59

so we have styled our first div however what if I want to create another div so

26:05

let's just go ahead and paste another div here and press save you will see that another div has been made with the

26:12

exact same styling that we have seen here we have two divs with the exact

26:18

same styling this is great when it comes to

26:23

not having to repeat ourselves and sty suing over and over again like we would have had to in the HTML if it looked

26:32

like this so we would have had to have that and once

26:38

again this and so on and so on and so on thanks to our sty sheet we don't have to

26:43

do that anymore so I'm just going to get rid of that

26:50

again great let's put in our second div and save now as divs are considered

26:58

to be the building blocks of HTML perhaps I don't want all my divs to look

27:04

like this now one option will be to use

27:10

another block element such as a section and give the

27:18

section some styling that is similar but not exactly the same as a div so I'm

27:24

just going to change the color in this case for now so there we go we've got a div a div and

27:31

a section however you will find that you'll soon run out of elements to use

27:37

this is why we have classes and IDs I'm going to show you this now in this next

27:43

section we're going to have a close look at classes and IDs and use cases for

27:49

both let's get to it so here we have two

27:54

divs let's say I want the second div to have styling that is different from this div I could easily give it a class and

28:03

let's call this one the about

28:08

me class and let's go in

28:14

here now to get this class right here I would have to use a different

28:21

type of syntax to denote a class I would have to use a dot in my Styles sheet

28:28

okay so by writing dot I am telling this file that I need to look for the class

28:34

of about me now I can give this a background

28:43

color of blue and there we go the div with a

28:50

class of about me is now blue what you might notice however is how the about me

28:57

div still has the styling from this div right here so it is still 300 pixels

29:03

wide and 200 pixels even though we didn't tell it to be those Dimensions

29:08

right here that is because we are essentially adding on top of the styling

29:14

that it already has so we are overriding the background color green with the

29:20

background color blue if you wanted this div to be completely separate from The Styling that it has

29:27

here here we would have to remove the styling from the div element itself so

29:33

we could do so like this by giving this a class that is separate so I'm going to call this

29:41

class header this is not correct we will change this but it's just to show you

29:47

for now so in here I would go dot

29:53

header and there we go the abat me has now disappeared because we have not given it a width and a height let's fix

30:01

that width 300 pixels

30:06

height 100 pixels and there we

30:12

go now let's go back to here you will notice that used a div with the class of

30:18

header this is not really correct we should not be doing this as we already have an element that is

30:25

specifically a header so let's go ahead and use that there we go and now we

30:31

don't want this to be a class anymore we just want this to be the element so let's delete that too we can also do the

30:39

same for a footer as there is already a pre-existing element for us so there we go okay now

30:48

it's time for a quick pop quiz let's do it here you have your index HTML file

30:57

all it has is it is a body with a background color of light Coral so I've

31:02

applied styling in the HTML file to give the body a background color of light

31:09

Coral now based on everything you have learned so far how do you think that you

31:15

would add a cirle element to the body

31:20

okay have a go at this yourself all I want is a circle I want the circle to be

31:26

any color you want and any size please put that in to the browser here so it's

31:32

visible for us please style it up as you wish I'm going to pause here while you

31:37

have a go at doing this please have fun if you don't get it that's absolutely fine because we're going to be going

31:43

through the answer together see you in a bit

31:58

okay so I would do it like this I would open up our body because the div has to

32:04

be a child of the body I will then go ahead and put a div I would style it to give it a

32:12

background color and let's make it light

32:17

SE green we won't be able to see anything if we refresh our page because we

32:23

haven't given this a width or a size or a height so I'm going to go ahead and it

32:31

has to be in here give it a width of 100

32:36

pixels and a height of 100 pixels just going to get rid of this for

32:42

now so we can see everything okay so we have a square and

32:49

the one last thing that I will need to do so I'm actually going to give it something called a border radius

32:57

and get 50 pixels and there we go we have now created a circle in our

33:07

body I hope that was fun don't worry if you didn't get it that's what I'm here

33:13

for we're going to be going through the answers together and please feel free to uh use the internet if you ever get

33:20

stuck that is absolutely fine too now I want you to essentially add a style

33:27

sheet what you have done so far so we can take out the style and put it into a separate file or our stylesheet so just

33:34

like we did in the lessons I'm going to pause here so I'm going to open up this

33:39

as well because you will be needing to add files and some structure please have a going and do this first feel free to

33:46

use what you have learned before as a hint you will have to link up your stylesheet and add the styling into the

33:53

stylesheet have fun I'll see you soon

34:02

okay so the way I would do this is this first off we actually need to link our

34:08

stylesheet to our index HTML file so let's go ahead and create it

34:13

first I'm just going to write Styles CSS so I'm giving the file the CSS file

34:19

extension to tell our IDE that this is that this is a CSS file if I click enter

34:26

you will see a little icon show up to see that that has worked next up I would

34:32

actually need to link this file to my index HTML file so I'm going to do it in

34:38

the head and I'm simply going to write a link going to make it a self closing

34:43

link I'm going to add the hre go to the Styles CSS file and I'm

34:51

also going to tell my IDE that this is a style sheet

34:58

for good measure okay so now we've linked our stylesheet we've created a file I'm

35:05

actually now going to take all of the styling so I'm literally just going to cut it out we don't need this style

35:13

anymore because we're literally going to put it in here now the next thing we need to do is

35:20

actually add all of this to the div so I'm going to pick

35:26

out my div by giving a class of

35:31

circle and then I'm going to grab that class cuz it's a class name we need a DOT and the word class and just put all

35:40

of this in here like so I'm also going

35:45

to get rid of this oops we were class going right

35:54

Circle and get the body so this time I'm not telling it it's a class I'm just

35:59

grabbing the element of body itself and once again pasting what we had

36:07

before like so and we have done it we have recreated what we have written

36:14

previously by taking out the styles from our index HTML file so all our styles

36:20

are now in a separate file okay so hopefully you see that there is no

36:25

styling in here anymore we just have a body and a div with a CLA of circle and

36:31

in here we have the body element which is styled and the class of circle so

36:37

anything with the class of circle will have this styling okay so I've hope you've enjoyed

36:44

this pop quiz if you didn't get it that's absolutely fine if you had to rewind and look at a lesson again or

36:49

perhaps use the internet that is totally fine that is absolutely normal as a software developer we'll be doing a lot

36:56

of these quizzes and a lot of the challenges so I hope you enjoyed this one let's carry

37:02

on okay so you've just seen me use three CSS properties that is the width where

37:08

we set the width with the pixels the height where we set the height with the pixels background color where we set it

37:15

to Blue and I also like to use border and Border radius these are my five most

37:22

used CSS properties I would say if you look at the border you can see that that

37:27

it takes three values if I want the border to be solid then I put solid and

37:33

then I choose a color and then I choose the Border width and the Border radius is something that allows me to soften

37:40

the edges of a rectangle it is also what I would use to create circles we'll be using all of these in our project before

37:47

we move on I just want to show you what I mean when I talk about Border in this next section we're going to look at the

37:54

Box model here we have our div I have named it

38:00

here as content in purple our div also has a padding so you can access the

38:06

padding by the padding CSS property and then you can see the border the border

38:13

is just above the padding and lastly above the Border you will have a property called a margin so all divs

38:20

possess all of these three properties and we can use them to our advantage let's go back to our stylesheet

38:28

so let's take the about me so as a reminder the about me is a div with the

38:34

class of about me if I add a margin to it so I'm going

38:41

to add margin 10 pixels you'll see the about me now has a margin of 10 pixels

38:48

here here here and here if we change this to padding our div now has a

38:56

padding so an inner padding of 10 pixels from the actual div

39:02

itself just going to switch that back to margin I'm also going to add a border so

39:10

once again I want a solid border let's make it black and then it already has a default

39:18

width but I'm just going to change that to 10 pixels and click save one other thing that I did mention

39:25

is the Border radius and I'm just going to choose 15 pixels

39:32

and now you'll see that our div has softened

39:38

edges because we've applied a border radius so that is just some of the

39:43

properties that are available to me in CSS there are quite a lot out there but

39:48

for the purpose of this course I'm going to be using the most popular ones now the next thing I want to talk

39:54

to you about is colors in this next section let's talk a little

39:59

bit about colors hex colors are a way of representing colors from various color

40:06

models through heximal values a heximal color follows the format r g g BB this

40:15

is where R is red GG is green and BB is

40:20

blue these heximal integers can be in a range of 0 0 to FF to specify the

40:26

intensity of the color this hex color for example represents black and this

40:32

one represents white a simple example of this is this one right here this color

40:39

is pure red because the red component is at its max value of FF and the green and

40:46

the blue components are at their lowest of O however when you get into the

40:51

design aspect of things and people really want to customize their colors you're more likely to see something like

40:58

this using hex color codes to represent different colors is an easy way to differentiate between colors once you

41:05

understand how they work you can easily change the red blue or green values to create a different shade this is

41:11

particularly convenient given that you have such a range of color options with hex color codes which guarantees color

41:18

exactness we also have the RGB color model the RGB color model is an additive

41:24

color model in which red green and blue light are added together in various ways to reproduce a broad array of colors the

41:32

name of the model comes from the initials of the three additive primary colors red green and blue the main

41:39

purpose of the RGB color model is for the sensing representation and display of images in electronic systems such as

41:46

televisions and computers though has also been used in conventional photography before the electronic age

41:52

the RGB color model already had a solid theory behind it based on human perception of colors

41:58

RGB is a device dependent color model different devices detect or reproduce a

42:04

given RGB value differently this is because color elements such as phosphors or dyes and their response to their

42:10

individual RGB levels vary from manufacturer to manufacturer or even in the same device over time what is great

42:17

about the RGB model is that we can also add a level of transparency so here by the 0.5 we are

42:24

indicating that this color we want it to be at 50% opacity I'm going to show you

42:30

this with an example it is absolutely your choice what you'd rather use if

42:35

you'd rather use the preset colors that we have already here whether you'd rather use the RGB or the hex for here

42:43

I'm just going to choose to change this so I'm going to change it from background to RGB and

42:53

then don't forget our semicolon so we just Chang this to this

42:58

sort of brownie red color and now if I want to make it transparent by 50% I

43:05

would simply add 0.5 I can change the level of transparency so I can make it super

43:10

transparent or less transparent if I wish same for the hex so with hex colors

43:18

it is a little bit different we don't write RGB in front or hex we simply get the hash like so and then get our are

43:29

six numbers and letters to represent the color that we

43:34

want with some code editor tools it is possible to click on the actual color

43:40

itself and just choose from the selector right here

43:46

also so for example similar to that so that is three ways of adding

43:54

colors in CSS you could either choose the default colors choose your own RGB

44:00

color or choose a hex color the choice is totally up to you now let's go back

44:07

to building our page just going to save this for now so we have our header which

44:14

currently doesn't have anything in it it is just a header that is purple we have

44:19

a div with the about me which is here and we have a section which is blue

44:26

lastly we also have a footer which currently doesn't have anything as this is a portfolio page for myself I want my

44:33

footer to contain some information I want to put this information in a list

44:39

let's learn a little bit about lists Now using just HTML we can make two

44:44

different types of list an ordered list so with numbers and an unordered list so

44:50

just with bullet points or similar I'm going to show you how to do this now so

44:55

in my fo out I've deed decided that I want a table of content let's do this first with an ordered list so I would

45:02

use the o tag for this o for ordered list I'd make an opening tag and then a

45:10

closing tag so you won't actually be able to see anything for now it's not

45:15

until we start adding list items as denoted by the LI tag so once again an

45:21

opening tag and a closing tag until we can see things so my first list item is

45:28

going to have an About Me section so if I click save you will see a list item

45:35

that is ordered by ordered I mean it has the number one I'm just going to make

45:42

the height of the section here smaller so you can see it and make our header 50

45:49

pixels high as well so let's have an about me a contact page we have a form and a

45:58

link to my GitHub if I wanted to change the

46:04

starting number of my ordered list I would simply add an attribute of start

46:09

to it and pass through the number 50 like so so now my ordered list starts

46:17

from the number 50 however I decided that I don't actually want an ordered list at all I want an unordered

46:25

list that makes a lot more sense in regards to what I want to try achieve

46:30

the bullet is a default that gets given with a UL tag if you want to start this

46:36

up in a different way we're going to have to use CSS for example I'm just going to put the

46:42

styling in the HTML file just for this just for now and I could do something

46:48

like this list style type and then pass through a square so

46:56

now we get little squares instead of bullet points I can also have the type

47:02

be a dis and of

47:07

course Circle other things that I can do to sty my list I'm going to do it in the

47:13

HTML file rather than the stylesheet for now just so I can show you quickly and

47:18

that is change the line height so I'm just going to pass through a line height

47:24

of 100 pixels so that's what it would look like more space out 10 pixels and so on and so on

47:34

I can actually also use percentages for this so I know we've been using pixels quite a lot but if we want to use

47:39

percentages that is absolutely fine too similarly to here instead of having

47:48

the width be 300 pixels I can actually use my browser width to decide on the

47:54

height to decide on the width of my elements so here you will see my

48:02

header width is now 50% of the browser if I extend this you will see that moves

48:09

around with it it is now responsive I'm just going to get rid of

48:15

this for now because I'm happy with the default Heights and we'll style this out

48:21

a little bit later one thing that I'm also going to want to do that we have learned already is actually link these

48:27

up with our anchor tags so let's go ahead and do that now we don't actually

48:33

have an about page built out yet or a contact page but there's no harm in just

48:40

leaving this like so so we don't forget to do it

48:46

later so once again we need the hre and I'm going to put the absolute

48:53

path to my GitHub page so you'll already see that that has created an anchor link

48:59

which again we can style to our preference for example if I don't want to line that I can get rid of that if I

49:05

want to change the font if I want to change the color if I want to have it change if I hover over it that is

49:11

something we can do and once again here I'm just going to leave it for now

49:16

because we haven't written the page so that is just a placeholder for us to remember to do that later okay so we

49:25

have our header we have an about me div we have a section and we now have a

49:32

footer now that we have lists down I want to show you how to embed images

49:38

into your project there are two ways of doing this I'm going to show you how for this I'm going to use my About Me

49:44

section I'm going to open up our div so what I am saying essentially is I want

49:49

my image to be inside the div

49:55

here and I'm going to use use an image tag like this what is important about image tags

50:01

is that they are self closing we don't need an opening and a closing tag so you

50:06

can use it like that or simply like this it is up to you the image tag needs two

50:15

attributes the source attribute in which we provide the path to the image we want

50:20

to embed and the alt attribute the alt attribute holds a text description of

50:27

the image which isn't mandatory but is incredibly useful for accessibility

50:33

screen readers read this description out to their users so they know what the image means alt text is also displayed

50:39

on the page if the image can't be loaded for some reason you know for example network errors content blocking or link

50:47

Rod I would always advise to have an ALT text so for this one I'm going to put

50:53

Ana Kubo head

50:58

shot now for the image one way of adding an image into the image tag is to Simply

51:06

go on the internet and find a absolute path for the image you want so for example if I go to the

51:16

internet I find a hedgehog I then copy image

51:24

address paste it up here here you will see there is an image or a rather large

51:31

image of a hedgehog which then of course I can use CSS to change the sizing

51:38

of this is okay however it's probably not the best practice for projects such

51:44

as this I would advise to store any images you use in your project directory

51:51

so let's go ahead and do that now so in my my file structure I'm going

51:57

to create a new folder I'm going to call it images where I'm going to sort all my images for this project now inside here

52:05

I'm actually going to upload a

52:12

file and it's going to be my avatar we can store PNG files JPEG files

52:19

it's totally up to you so now we need the relative path so I'm going to go

52:26

into to my images folder and then going to get the

52:32

Ana make sure to type it out exactly as you see it PNG file and click save great

52:42

now I'm also going to style this image so I can either choose to use the image tag and sty it up however I'm not

52:49

confident this will be the only image tag that I use so I'm going to use a class to do this and I'm going to call

52:56

this Avatar like

53:03

that and then choose a DOT because we are working with the class name go

53:09

Avatar and set a width of 100 pixels for the image

53:15

great I'm also going to use border radius and give a border radius of 50

53:22

pixels to make my avatar look like a

53:27

Circle okay so this is looking good I have my first image I'm just going to shut down that folder let's go back to

53:35

our index HTML file you will see that this code editor

53:41

is actually reformatted this for me to be more readable so now my image tag

53:46

consists of the class attribute a source attribute with the relative path to my

53:53

PNG file and an alternative text so it's more

53:59

accessible the next thing that I want to talk to you about is IDs so we've already styled something by elements so

54:06

when we were grabbing elements such as the header and section we've also used

54:12

classes such as denoted by this dot but we can also use IDs now before we move

54:18

on I'm just going to explain a little bit more about this first so for example we can grab things by elements such as

54:25

the D we can add classes to elements and grab

54:30

them in our CSS thanks to a DOT and we can add IDs to our elements and grab

54:36

them in our CSS thanks to the hash IDs and classes are essentially hooks but

54:43

what is the difference between them well IDs are unique each element can have

54:49

only one ID and each page can have only one element with the ID now this isn't

54:57

Just A good rule of thumb this is something that's quite important if you are a purely HTML and CSS person the

55:05

difference might not be evident but when we start working with JavaScript this will really make a difference for one

55:11

your code will not pass validation if use the same ID on more than one element validation should be important to us all

55:18

so that alone is important and a big one classes however are not unique you can

55:24

use the same class on multiple elements so similar like we did with the divs you can also use multiple classes on the

55:31

same element any styling information that needs to be applied to multiple objects on a page should be done with a

55:36

class and one last thing elements can have both so for

55:42

example my div here can have a class of about me and then also an ID as

55:50

well this is however optional but sometimes a very good idea to have so

55:55

I'm going to write a tit here so I'm going to choose to have an H2 tag the closing tag and I'm going to

56:03

give an ID of

56:10

name in it I'm going to have my name so Ana Kuba and hit save this will not do

56:20

anything for now I can however style it so I'm just going to show you what that would look like if I did I would use the

56:26

hash to get the div with the ID of

56:32

name and then I'm just going to choose color not background color because we're working with text for this one and I'm

56:39

just going to choose blue and save you will also note that

56:45

because H2 tags and image tags are not

56:50

in line they display as block they actually stack over each other and don't fit in my my section anymore I would

56:58

ideally want my image element to float to the right I'm going to show you how

57:05

to do this with something called flexbox before we move on I just want to talk to you a little bit more about other

57:12

properties we can assign elements in HTML so for example we have the data ID

57:19

let's have a look at a few more in code okay so as we know we can have

57:26

elements so I'm just going to make a div here so here's my first tag and my closing tag and I can give a class name

57:35

so for example box an ID for example

57:42

Main and then I can also have data set readon properties as well a data set

57:50

read only property starts off like this it is in fact a custom data

57:57

attribute what this means is that I can make up any word I want as long as it has data in front of it so as a recap

58:05

the attribute will begin with data and for Slash and can have anything after it

58:11

I can have data ID such as this I can have a data

58:20

user such as Joe I can have a

58:27

let's get rid of this for now

58:33

data data date

58:38

of birth it is completely and totally up to

58:45

you so that is just something to keep in mind as we will be using data IDs for some of our projects and later on in our

58:52

JavaScript course so as long as you uh make a note of this you should be fine let's carry on with

58:59

our lesson in this next section we are going to be looking at Flex boox let's do

59:06

it flexbox or the flexbox layout module aims at providing a more efficient way

59:12

to lay out aign and distribute space among items in a container even when

59:18

their size is unknown the main idea behind the flex layout is to give the container the

59:23

ability to alter its items with or height to best fill the available space

59:29

a flex container expands items to fill available free space or shrinks them to

59:35

prevent overflow most importantly the flexbox layout is Direction agnostic

59:41

this is supposed to the regular layouts that we have while those work well for Pages they lack flexibility to support

59:48

large or complex applications let's go over some Basics and

59:54

terminology so here we have three child elements in yellow in an orange

60:00

container so that is the parent div they are in at the moment the three child

60:05

Elements which are divs are displaying as they should as a default so stacked over each other we're going to talk

60:11

about the properties for the parent so the orange Flex container now let's

60:17

initialize this to use display Flex I'm going to show you how to declare a flex

60:23

Direction This establishes the main axis that's defining the direction Flex items

60:28

are placed in the flex container so in this example the flex direction is row

60:34

and we are making all our elements in the parent container display as a row alternatively we can also set the flex

60:41

direction as column and we will see our elements align like so next we have Flex

60:47

wrap by default Flex items will all TR fit onto one line you can change that

60:53

and allow the items to wrap as needed with this property so I'm just going to show you now Flex wrap wrap I've also

61:01

numbered them for you so you can see a little bit better now let's change that to row so once again 1 2 3 and I've

61:09

added another diven there of fourth so you can see how that is wrapping instead we can also use something called

61:16

justify content to essentially make our divs Bunch up to the start Bunch up to

61:22

the end using Flex end and then Center as well

61:28

we also have space around space between so hopefully you're seeing these small

61:34

changes in the divs and space evenly along with many others such as align

61:39

items align content Flex grow and a few

61:45

more okay quick pop quiz let's do it so here we have my index HTML file

61:56

all it has really is a link to my stylesheet and a div with a class of

62:01

child which I have styled up to look like this now how do you think using

62:07

display Flex that you would get the child to appear in the right hand side

62:14

right here no matter what or how big a screen is it will always stick to the

62:19

right end of our screen have a think about this based what we have learned please do have a go

62:26

at trying this out in your own code editor and I'll see you in a

62:36

bit okay that's right I hopefully you've got it if you haven't don't worry I'm going to show you the answer now I would

62:43

initiate the parent by writing display Flex so the body is the parent of the

62:51

child because the child is in the body that is the one up from it is the

62:57

body and then I just use justify content

63:04

Flex end and there we go no matter how big the screen is square or the

63:11

rectangle will stay to the right now how do you think I would make it stay in the

63:22

middle that's right I would change this to Center and now no matter how big or

63:28

small our screen the square will always stay in the

63:35

middle okay that was our quick pop quiz

63:40

let's carry on okay let's get to using what we have leared in our project so

63:46

far for this I'm going to use my section as the parent div so here we have the

63:52

parent div itself I'm going to go in here and in the section I'm going to use

63:59

display

64:04

Flex so what we are doing here is defining a flex container it's going to enable a flex

64:11

context for all of its direct children so what that means is anything that I put inside the section is going to be

64:19

affected I'm going to save that and then in here I'm just going to create some divs so here's one div and it's closing

64:26

div I'm going to give it a class of

64:33

test I'm just going to put one 2 3 4

64:38

five and then in here I'm going to style it just so we

64:43

can see it a little bit this is just for test purposes so you can see withd height 30

64:49

pixels and I'm going to give it a background color of red

64:57

and a margin so we can see each one a little bit more of five pixels so there

65:02

we have our five divs inside my section perhaps let's actually make the

65:09

about me a bit

65:14

higher a bit bigger so there we

65:20

go okay so here we have our blue section with five five

65:27

child elements now if I use flex

65:35

Direction row they won't change because they're already in a row however if I

65:42

choose column you will see here that all of my divs are trying to squash

65:48

into the section and because the section height is 100 pixels it doesn't matter

65:55

that these these test Dives are 30 pixels it's squashing inside okay to fix this we need to use

66:03

flex wrap

66:08

wrap now you will see that instead of squashing our divs are

66:15

essentially still lining up in one column however once it gets to the end

66:20

of the section they are wrapping over they are wrapping over so if if you follow my mouse it goes like this 1 2 3

66:29

4 5 we can also justify the content of the section so

66:36

justify content

66:41

Center and you'll see that they are all aligning to the center so if this was my

66:47

Axis they're aligned to the center right here if I change this to be Flex Direction

66:52

row they all centering around this axis instead instead of Center I'm going to

66:59

put space between and you will see all the divs

67:04

are spacing out with equal spacing in between each one I can also choose space

67:11

around and now you'll see that each one has the same space around

67:18

each div so that are just some examples of what we can do with flex box the most

67:24

important thing is that it makes everything Dynamic so for example I'm just going to

67:30

get rid of this for

67:42

now and apply Flex box to the body so our body is the tag that accompanies all

67:48

of our elements inside here so let's go get the body

67:56

so again I'm going to use display Flex to initialize Flex box they are as

68:02

default displaying inline I then want to get the flex

68:09

direction to be

68:15

column okay so that's step one the next thing we're going to do is actually get my section and instead of have a

68:22

hardcoded width I'm going to I'm just going to put

68:28

100% same for the header

68:33

100% And for the about me I'm also going to

68:38

have 100% I'm also going to get rid of the

68:47

margin like that and instead I'm going to apply margin top 10 pixels and

68:56

margin bottom 10 pixels another way of writing this is to

69:04

write margin 10 pixels 0 10 pixels

69:09

0 okay so that's just another way of writing essentially the same thing I'm

69:16

adding a margin to the top to the bottom keeping it zero here and keeping it zero

69:23

there too so now you'll see this is much more

69:28

responsive and no matter where we're viewing this on our Mobile on a browser on a tablet it will look much more

69:43

professional commenting out code so you might see me commenting out code uh this

69:49

just means that the code is unreadable at times and really helps us when we develop code because you can write

69:55

pseudo code so anything that I don't want my ID to pick up I'm going to

70:01

comment out and we comment out by simply selecting the code we want to comment out and pressing command and then the

70:10

forward slash on your keyboard okay so have a go at doing that I'm going to

70:16

show you an example of what I mean by this here we have a star sheet I would

70:23

simply grab that and press press command slash to comment it out and then once

70:29

again command for slash again to uncomment it so that we can use it

70:35

please have a go at this yourself you're going to be seeing me use this quite a lot in the course so have a go have fun

70:42

and let's continue so I'm just going to comment

70:47

this out the about me so this is how you would comment out in CSS you need to put

70:54

a d and a asteris as well as an ending Aster Dash and that code will then be ignored

71:03

okay so once again press command and then the forward slash to bring it

71:10

back and command for slash to comment it out or you can simply type out this here

71:17

and here too both will essentially work just to recap what we've covered so

71:23

far with flex box I'm going to use apply Flex box once again to these five divs

71:29

so again this is in the section I'm going to apply display Flex to the

71:35

parent div as the section the blue section is the parent of these five divs

71:41

here if you look here the five divs are inside the section making it their

71:47

parent so I'm going to use display

71:53

Flex you will now see that by default all the divs are displaying in

71:59

line I can then use justify content to Center the divs I

72:07

can use justify content to space them evenly I can use justify content to

72:14

space between I can also align items to flex

72:24

end if I want them to be at the end I can align items to

72:30

Center so if I want to display them straight bang in the middle I would align item Center but also justify

72:39

content Center there we go and now they will always be in the center of that div

72:47

no matter what so I'm happy with my section I like

72:53

the fact that the divs are always going to be in the center no matter what and

72:59

if I go small they will even squash up like so but always remain in

73:05

one line so that is looking good if I wanted them to wrap well you guessed it

73:12

I would use flex wrap wrap so

73:18

now you will see them wrapping over each other

73:25

so whatever you

73:37

want now I've decided that I actually want the section not to be a solid color

73:43

I want it to be a gradient I could simply I'm just going to comment this out for now so once again command and

73:48

forward slash and I'm going to use background image

73:55

I'm also going to use linear gradient and pass through two

74:00

colors so just for example I'm going to pass through red and yellow and then don't forget

74:07

semicolon and we have now created a linear gradient I could also customize

74:15

this even further for example if I write

74:20

two two right and then a comma you will see that the gradient is moving

74:27

in the other direction I could also have to bottom right and once again you will

74:33

see the gradient is moving towards the bottom right hand corner you can of

74:40

course customize this as much as you want if you're really particular about a certain angle you can even pass through

74:47

the exact angle you want by degrees and you'll see that happen one

74:54

thing I can also to do is add in multiple colors or as many as I want so

74:59

I'm going to pass through green and if you're feeling really crazy

75:05

just going to get rid of the degrees for now you can have a

75:12

repeating linear

75:19

gradient and really go wild on the customization of everything so there

75:25

really is a lot to play around with the CSS I'm just opening a NeverEnding Pandora's Box for you to really go

75:33

wild okay I don't particularly like it though however so I'm going to just remove it and keep it like that just for

75:51

now another thing that I want to show you that's quite retro is adding box Shadows so for example this is probably

75:58

a good place to put an ID so say I just want to add a box Shadow to the middle

76:05

div it already has a class however I'm going to add an ID too so this is me using a class and an ID on one element

76:13

and I'm going to put

76:18

main save that now in my Styles I'm going to use the ID of

76:25

Main and add a box Shadow I'm going to put 10 pixels 0

76:34

pixels 10 pixels so now you'll see that my middle div has a box shadow that is

76:42

quite solid it is not very

76:48

opaque I can also make it a lot softer

76:54

and change its color okay so here we are defining the horizontal Shadow here we

77:01

are defining the vertical Shadow here we are defining the softness and here we

77:06

are defining a color if I want to move a little bit closer I simply

77:14

change the pixel Direction okay so I wouldn't say our

77:20

portfolio is looking good but we are exploring all the options that we can used to make it great one last thing I

77:27

want to show you is buttons so this is going to be a HTML tag right in

77:37

the About Me section under the image I'm going to

77:43

use a button tag so if I click save you

77:49

will see a button I can also add click me

77:56

now the benefits of using the button tag is that it will come with a pre-made button already if we hover on it it will

78:04

slightly change you will see that we are slightly clicking it if we click it you'll see a little animation happen so

78:11

that's stuff that's already built into the button tag itself we can use it to

78:16

take us to another page an external link submit forms anything we really want you

78:24

might see that some developers choose to omit the styling of this button completely and just use a div instead

78:30

that is also an option however we're just going to style our button here so once again I'm just going to grab the

78:36

element itself so that now when we use a button tag anywhere in our project it

78:42

will be standardized and looked the same so I could do something like give it a

78:47

border of zero that will get rid of the borderer of the button

78:55

I can give it padding 020 pixels and that will give it

79:01

a 20 pixel padding from the left and right and a zero padding on the top and

79:07

bottom I can also change the font size to 20

79:14

pixels a background color of rgba in case I want to change

79:21

this to be slightly transparent further down the line at the the moment one it means it's solid there is no

79:27

transparency we get our semicolon R rgba now I want to add

79:36

some gradients so I'm going to add a linear

79:42

gradient to top left and then pass

79:48

through some colors so I'm going to pass

80:00

so I'm going to pause through rgba 0 0

80:05

0

80:12

0.2 R GPA GPA 0 0 0

80:22

0.2 30%

80:31

just going to fall back this a little bit better so we can read it rgpa 0 0 z0 ending

80:41

colon so you can already see it's not a solid color it's just very slightly

80:47

linear graded perhaps less offensive than this it is just a b more

80:53

stylized then a box Shadow

80:59

inset two pixels two pixels 3 pixels

81:04

rgba 255 255 255

81:10

0.6 in set - 2 pixels - 2 pixels two pixels RGB

81:20

a 0 0 0 0.6 once again the ending

81:29

col box Shadow so already that's looking more like a button you might see online

81:36

it obviously is quite labor intensive CSS is a skill that you have to practice

81:42

at quite a lot there's a lot of really amazing CSS artists out there I really

81:48

do recommend you check out codepen to see them all it really is amazing what people can do

81:55

with this

82:02

scale I'm going to make this white as well just going to give it some text

82:09

Shadow before we move

82:16

on Pixel one pixel pixel

82:25

okay so I think I'm happy with that for now this is obviously a much more extensive way of styling using

82:32

everything that I have taught you so far it's just a lot more detailed and I really get to the nitty-gritty of linear

82:39

gradients and box shadows and everything now the reason that I have done this is

82:44

because I want to show you how to add styling if we hover on a button at the moment nothing is happening I want the

82:51

style of the button to change if our Mouse hovers over it and if we click on

82:57

it so to do this I'm going to actually get our button again so I am

83:05

literally grabbing the element and then using this syntax like

83:10

this hover I'm simply going to give it a background

83:19

color rgba save so now if we hover on the

83:25

button it ever so slightly goes that little bit lighter and the same for if

83:32

the button is active so once again we grab the

83:39

button active so I'm not making these up this is already inbuilt you could say if

83:44

the button is active I want to add a box

83:52

shutter we can add the on har an active onto any element it doesn't just have to

83:58

be a button which is quite handy we can do it for divs we can do it on the

84:03

header itself we can do it for just about anything and so I'm just going to show

84:09

you how this would look and then if we click on it you will

84:15

see it's ever so slightly the Box Shadow is turning white around it like

84:23

so so there we go just to prove we can do this whenever

84:29

we want I'm going to go in here get the button

84:37

tag by command D I can actually select both of these words right here and replace it with a div and instead give

84:45

this a class of

84:50

button and then in my stylesheet instead of just grabbing the button element

84:55

because that doesn't exist anymore the class button does however so once again

85:01

I would simply place that and just fix this up a

85:08

tiny little bit by giving it a

85:18

width and making sure that it fits in the About Me section so I'm just going

85:24

to change this to 250 and then let's do text

85:34

aligner so there we go you will now also see that there's no blue surrounding square around it this is because there's

85:41

no longer a button element it's now simply a div that we sted as a button and I would personally prefer to do it

85:48

this way and I do recommend it to you too in this next section we are going to

85:53

be talking all about fonts let's do

85:59

it now that we have covered buttons I think it would be a great time to talk about fonts mainly because I am not a

86:06

fan of this font right here so I'm going to go into my body and set

86:14

a global font for anything in the body so font family and choose I'm going to

86:21

choose this one right here so just as a default and what this is saying is that I am

86:27

choosing Gil sounds to be my first font if for some reason our browser doesn't support it Gil sounds Mt as a third

86:35

backup calibri as a fourth Tre buter Ms and as a fifth sounds serif I don't

86:41

think it's always necessary to have so many sometimes you could just have three so let's go ahead and just cut that down

86:49

if we really want to customize this further we can import fonts to use two

86:54

so I'm just going to show you how to do that I'm going to go to Google fonts Google fonts provides loads of

87:01

free fonts for us to use so for example say I want to use Roboto in my project I

87:07

would simply go here and select which styles of Roboto I want I'm going to

87:12

choose regular so I'm just going to choose one for now now I'm going to choose to select the link tag rather

87:20

than the import tag so I'm going to choose to copy this right here and then

87:26

in our HTML file where we link the stylesheet I'm also going to

87:35

link to the Google fonts API in order to

87:40

get the Roboto font so I'm just going to save that and

87:47

now instead of the font families that I chose I'm going to choose to have Roboto

87:52

and as a backup s s siif Sans serif is just one of the ones that are provided

87:58

for us whereas Roboto is a special font you could say so right in here our font family I'm

88:05

going to choose Roboto which is the one we have just taken from the Google API and as a backup I'm going to have the

88:12

Sans serif default font so now you'll see that all the font

88:18

in our entire body so that means that in the section the About Me section and in

88:23

the footer is going to have Roboto this is because body is the parent to all of

88:31

these elements inside of it if for some reason I wanted to apply

88:39

a different font to the footer I can essentially override the font in the body so I would

88:46

get the footer and then use Font family

88:55

like so and the font will be overridden so that's looking good one last thing

89:00

that I want to show you how to do before we go to town on making this look good rather than just learning is to remove

89:07

the line under the links so I would grab the a tag and then I would get text

89:17

decoration none and there we go we have now removed the lines on the hyperlinks while the

89:23

hyper links still exist okay so in this section we are going to explore layouts a little bit

89:30

further let's do it okay now I want to talk to you a

89:37

little bit about website or app layout I'm going to break this down for you by

89:42

div as that's essentially the building blocks of any website or app so let's get to it so at the moment we have built

89:50

this site right here if I was to break it down by by div our page layout would

89:56

look similar to this so we've got our header in purple and then we have our

90:02

hero section which has our name image and button and then below that the About

90:07

Me section and then below that the footer however as we want our website to

90:13

look more like this we essentially want our website to look like this so this is the finished

90:20

product you will see the layout is a lot more complicated in terms of split out

90:25

areas in regards to the layout if I was to tell you what this looks like in terms of divs you would see something

90:33

like this we have divs next to divs on top of divs it is essentially our

90:39

Website Layout so let's go back to what we have built so far now in this

90:46

specific code editor when I can choose to view the browser in the editor itself

90:51

I can also view it as if we were viewing it on a browser so I'm going to open up

90:57

here so as you can see here it is really visible because we are now viewing this on a laptop browser and everything has

91:04

been stretched you will see however that we still have one div up here an orange

91:10

div a yellow and red div and our footer if I was to inspect this page so we can

91:17

inspect this page by essentially clicking control and then left clicking

91:23

the page and then getting our inspect

91:28

tool and this should show up all our elements so I can actually pull this

91:34

down so we can see this a little bit further and what you will see here is our

91:39

header our about me div a section and our photo what is great about this is I

91:45

can also select elements to expect on the page so for example if I want to select the About Me section you will see

91:53

here that I've selected the About Me section and in it I've got an H2 tag an image and a div that is styled as a

92:01

button this is really useful for seeing div size you will see even though I am

92:06

essentially floating over the div with a class of button you can also see the div

92:12

actually on the browser and it takes up all this space right here so once again

92:18

I'm just going to float on it and there we go this is because we haven't assigned the div Max width or a width so

92:24

it literally stretches to our browser same for the h2 tag not the same

92:32

for the image however as we did assign it a width I'm going to show you one more thing that is quite useful if you

92:38

are not sure about how a style can affect an element so for example if I go

92:44

on the about me div which has all three of these elements inside I'm just going to

92:50

click here I can actually edit it from my

92:56

console so here you will see for example background color I can essentially change this to whatever I want this will

93:03

not change anything in the project this is simply changing it for us in the browser and is a quick way to

93:09

essentially change things for us to see what it would look like in the finished

93:17

product let's try another one so I'm going to inspect let's inspect this one right here and then let's change the

93:26

height 100 pixels and there you

93:32

go okay so this is a cool way of inspecting and seeing what something potentially might look like you can do

93:38

this on any website I can go on to any website I want so for example if I go to

93:45

google.com let's go on the main search page let's inspect it I'm going to

93:50

select an element so let's just select this input right here and it's already

93:56

given me all the CSS for it so I can go ahead and change the font size to 30

94:04

pixels and there we go once again I am not changing this on the actual Google

94:11

code repository I'm just changing this in our browser this is essentially private for us to view only on our

94:18

laptop in this browser okay so now that you hopefully understand a little bit more about divs

94:23

and layouts and how to inspect them in browsers let's carry on okay in this

94:29

section we are going to focus on everything we have learned so far by building a nav bar let's do

94:36

it just going to move this back here make that a little bit smaller for

94:43

us so we can see now let's get to using what we have learned in order to create our header or

94:50

essentially our Navar so let's go back to our

94:55

HTML I'm just going to rename this to Ana Kubo

95:01

portfolio once again that will not change anything for us this is just sort of metadata it is what our project will

95:07

show in the browser so as you can see in this one you will see Ana Kubo portfolio

95:12

show up here as the title of the tab and let's get to making the Navar so

95:19

I've called this header but I'm actually going to change to Navar as I think it makes more sense and it is important to

95:25

make things as readable for anyone that goes onto our project as possible so

95:30

here we have a navbar this is again a element that is provided for me I did not make this up it

95:38

exists now in our Navar well I want to have a logo so I'm going to put in an

95:45

image I also want to have a list so we've done this before I'm going to make

95:51

an unordered list as opposed to an ordered

95:56

list make sure that is a closing tag and in here let's have some list

96:02

items so here's our first list item and I'm just going to have 3 2

96:10

three now my first list item I want to be about me my second I want to actually connect

96:18

to my GitHub page and then my third I want to say contact

96:25

me now each of these I actually want to make an a link so an anchor link so as a

96:33

reminder an anchor link we can link to a specific place in this page another page

96:40

or an external page such as GitHub so let's just do that now I'm

96:47

going to leave some of these placeholders

96:54

so there's one there's two and there's

97:02

three okay now we're going to add a logo to our navbar similarly to how we did it

97:08

here so let's not forget that we need to add a source which at the moment I'm

97:15

going to need blank CU we don't have anything imported yet make sure the formatting of this is correct and then

97:22

we also need an alt for the visually impaired and I'm going to

97:27

have Ana Kubo logo so with my logo I'm just going to

97:35

actually import it by dragging it in so let's go to downloads now with my logo I'm actually

97:42

just going to drop it in so here it is I've searched for my logo on my computer and I'm just going to drag it into the

97:49

images folder we have already made so we will see it in our images folder right

97:54

here so once again we need to navigate to this file so I'm going to go into my

98:01

images folder going into it and getting the JavaScript games logo and it's a PNG

98:10

file so make sure that is correct and there we go we have our logo

98:15

in now I can already see it's too big I don't really like that so I'm going to add a class to this element so the

98:22

opening tag of the element and I'm just going to put

98:27

logo now let's go into our stylesheet I'm going to get rid of header because it doesn't exist anymore

98:34

change it to the nav element I'm going to get rid of the background

98:42

color next I'm going to the class of logo and make the height let's make it

98:50

30 pixels and I'm also going to give it a margin

98:55

so it's not so squished margin

99:01

15 30 pixels so once again this is a shortcut I could have essentially

99:07

written margin top 15

99:12

pixels margin right 30

99:19

pixels margin bottom

99:25

pixels margin left 30

99:31

pixels okay but this is a shortcut I am essentially saying this is the top this

99:36

is the right and then I'm repeating it so that is some useful knowledge for you

99:41

I'm just going to get rid of that now and use the shortcut instead okay so we have our logo however

99:50

everything is stacking on top of each other okay it's stacking block we need to change this and we're going to do

99:56

this with the responsive layout tool we used earlier and that is flex box so on

100:02

the Navar I'm going to initiate it so display flex and then use

100:10

justify content I'm going to choose to use space between for this one as I want

100:16

the space between each of them to be equal don't forget we've added a margin here so I'm talking about the space

100:22

between here and the whole div of and this div including the margin so

100:29

that looks evenly spaced to me the next thing we want to do is sort this out

100:35

because I don't want these Stacks over each other either I want them next to each other so for this I'm going to get the

100:44

unordered list tag I'm going to add a class to it

100:50

this because we are already using another unordered list in here so I need to pick this out by class or ID but I

100:56

think it makes more sense to use class in case we want to use this again and I'm going to call it

101:02

n bar so now I'm going to get the class of

101:14

Navar once again I'm going to use display Flex so I'm initiating

101:21

it I'm going to use just a y content Flex end let make sure it's

101:28

always at the end of the page and then we use something called

101:33

list style

101:38

type none this is because I don't want the little

101:43

dots nav bar Signet it's a class so we need the dot we are telling this we need

101:50

to find the div with a class of Navar let's initiate flexbox

101:58

justify let's initiate flexbox display Flex okay and now let's justify

102:06

content I'm going to use flex end this time because I want everything to go to the right of the page so there we go

102:14

that's happening and then I also want to get rid of these dots right here I don't really want them so we can do that with

102:21

something called list style

102:26

type none so we did see this before but we saw the circle and disk this time I

102:33

just want none okay this is looking good however I do want some space around each individual list element so I would get

102:42

the list element itself and go margin I'm just going to

102:49

use the short hand again so 15 pixels and 5 pix Source okay so that is now

102:56

affecting this list item this list item this list item but also these down here

103:01

once again this is a short hand so I'm affecting the top margin the right

103:07

margin the bottom margin and the left margin I'm going to show you one more

103:12

cool thing that you can do I can actually manipulate the text itself so

103:18

if I want the text to always be uppercase I can do that from my CSS I

103:24

don't have to go back into my HTML and write everything out again so that is quite cool and I'm just going to make

103:31

the font size smaller too make it 12 pixels okay my navbar is looking good

103:40

one more thing and that is actually we need to decide where these are going to go so let's go back to talking about

103:48

pffs so I've already shown you how to link to an external page and that is using using an absolute path so like we

103:56

did here so we are literally going to a web page that is my GitHub page we have

104:04

also discussed how to link to other pages in your project and we've briefly talked about how to link to elements in

104:13

your actual page so I'm going to show you how to do all three of them now so

104:18

we already know that to connect to a GitHub page or an external page you need

104:23

the absolute path similar to this now let's create a contact me page so in

104:30

here just going to save this file I'm going to create a directory called pages

104:38

and in it I'm going to create a contact HTML page don't forget to make

104:45

sure that this file is actually in the Pages directory now I'm just going to

104:50

put some boilerplate HTML in here change the title to contact page and

104:58

remind you that this is now not the relative path to our stylesheet why is

105:03

that that because our stylesheet is not in the same folder as our contact HTML

105:09

file okay this would be implying that it's in the same folder we need to go

105:14

out of this folder and into the root of our project so I'm going to show you how

105:20

to do that if I indeed want to use the same style for my contact page I would have to go

105:26

out this project so this is how you go out a folder going out of the folder

105:32

with these two dots and then I would need to get the Styles CSS

105:38

file so I'm just going to put something like an H1 tag here so we can see what

105:44

is happening

105:49

contact and go back in here so now in here I once again need to put

105:57

the relative path so I'm going into the Pages

106:02

directory and I'm getting the contact file click save now if I click the

106:09

contact me I will be taken to the contact page just going to show you what

106:16

this looks like in an actual browser contact me the contact page in

106:23

our actual browser you will see that the URL has changed this URL will be

106:29

whatever location you are in obviously I am using an online IDE so this is a

106:35

specific URL link for that IDE and then we are going into the pages

106:41

folder and then getting the contact page okay this is opposed to being on the

106:48

homepage there is nothing extra after it the index HTML is our root

106:54

okay so back to the homepage so we have linked up an external site we have also

107:01

linked up a page in our project the last thing I want to show you is how to link

107:07

to an element in our page so I can do

107:12

this with an anchor link all I need to do is actually use an ID and I'm just

107:18

going to write about me okay so now that is essentially linked to something but we need to tell

107:23

it where to go I'm going to choose to link it to this section right

107:32

here so I'm just going to write h2 tag the h2 tag is going to say about me

107:41

and then using open up our a tag name and I'm

107:50

literally copying this

107:55

ID so close that tag and then I'm going to close that tag

108:01

here save I'm also going to just make this

108:08

hero section A little bit larger so we can see this more visibly so this is the About Me section

108:15

I should probably rename this it's going to make it 500

108:20

pixels so now if we click about me you will be taken to the About Me

108:27

section once again let's view this in an actual browser about

108:33

me and it is coming more into view we can change exactly how much we

108:40

want this to scroll into view in our CSS but just know that it is coming more into our view as the

108:48

user okay just going to change this back

108:56

so we have our links however I don't really like these default colors they're not really doing much for me I don't

109:01

like this purple I'm going to show you how to change the color of the links based on certain actions that happen so

109:08

if we click it if we hover over it and so on let's go to our

109:14

stylesheet now I already have an a tag already done here this is when we

109:19

decided to remove the line so as a a reminder this is what an a tag will look

109:25

like without any interference however I've decided to get rid of the text

109:31

decoration now I also want to change the links to be black so there we go that's

109:37

happened but there's a lot more that we can do with these I can get the a tag and by writing this kind of syntax like

109:43

this I can change the color to be any color I want so now if I hover

109:51

over a link the color changes so this is a great thing to remember when you

109:57

really start to get to the nitty gritty of design and ux and UI you can even go

110:03

really wild and change the font size if you wish it is totally up to you the world is your

110:10

oyster just going to get rid of that for now as I'm not really a fan of that type

110:15

of look and there we go okay I think we are now ready to move on to the hero

110:21

section so I'm going to call this part my hero section if I just show you the

110:26

final product of what I want this to look like here we go my hero section is going to have my name a little bit about

110:33

me a button so I can get hired and an image so let's get to doing that now I'm

110:41

also going to make it responsive in responsive design page elements reshuffle as the view point grows or

110:47

shrinks a three column desktop design may be shuffled to two columns for tablet and a single column for a

110:54

smartphone responsive design relies on proportion based gids to arrange content and Design Elements while responsive

111:01

design emerged as a way to provide equal access to information regardless of device it is also possible to hide

111:07

certain items such as background images and so on decisions about hiding content or

111:14

functionality or altering appearance for different device types should be based on knowledge about your users and their

111:20

needs so let's get to it let's make our first responsive section so back to the

111:27

HTML file so I've named this section about me however I want to change that I don't

111:33

want to make this about me anymore I'm going to change this to be called a hero section so in our stylesheet let's find

111:40

the about me and change it to

111:47

Hero now for this to work I essentially need to split this section into two

111:54

sections okay so if you remember back to here I want two purple sections so that

112:02

each can hold different information and can essentially stack over each other if we go into mobile view okay so that's

112:09

what we want so let's build that out now let's make one

112:20

div let's make one one div

112:26

here and then another div here just so we can see what is going on

112:34

I'm going to call this class hero info and then the second one

112:44

class second for now I'm not going to keep this class it's just so we can see what

112:50

is happening so now

112:56

if I go hero info make sure it's a

113:03

class and second let's make it withth 300 pixels

113:11

height 300 pixels back background color

113:19

red and then the same for this one you will see that they are stacking over

113:25

each other let's also get rid of the height of this hero image so we can see so they are stacking over each other

113:32

just going to perhaps give a margin so you can see that a bit better too margin five pixels lgin five pixels we don't want

113:41

this we want them to essentially be next to each other but only stack if they go into mobile view so in the

113:50

hero I'm going to use display Flex to initiate Flex

113:56

box okay they are stacking however we do have all this extra information here too

114:02

so let's go back in here and take the button and the image so make sure to

114:07

take all of them and the h2 tag okay I'm just going to put that in

114:14

to Hero info so now they're in here and then we have a second Square here

114:23

so that's looking great if it's a larger browser however they're still sort of

114:29

collecting to the left I'm also going to use justify content space

114:36

between okay I think that's looking a lot better for what we need please bear

114:42

in mind I am building the site so it's maximum to these proportions this is just for the tutorial if you are

114:48

building this out to use on the browser please be conscious of of the fact that this in the browser will look like that

114:55

but yeah for this tutorial this is going to be the max that we're going to view this website in okay the next thing we

115:01

need to fix is that I actually want these to not squash in like so I want

115:07

them to actually stack over each other so you might remember a little something called Flex wrap and

115:16

wrap so now as soon as the two squares don't fit

115:23

on the same line they will wrap over each other like

115:29

so okay so that's one option and that's the second we can also even get to the

115:35

nitty-gritty of what happens when we are at this stage because obviously there's a lot of Blank Space here but that is

115:42

something I'm going to leave to a later on lesson let's get comfortable with this part first so there we go our hero

115:50

image is coming along nicely we've got our hero information and then

115:56

our second Square here too I'm just going to give the hero information a

116:01

larger margin I'm going to stick it to 30 and I'm actually going to get rid of

116:07

this second styling for now you can see what is happening so I'm going to get rid of that and I'm also going to get

116:13

rid of this class the only reason I added it so you can visually see it but just be aware that if we put anything in

116:18

here the same styling and same logic will apply and I'm also going to get rid of

116:28

that for the next part let's actually add some text so let's go back to our

116:33

index HTML here going to get rid of the contact page

116:39

too make this a little bit smaller so we can see

116:44

everything so we have our name I'm just going to start this to look better because we already have an ID for it

116:50

here so I've said blue but I don't actually want that let's just make it a bit

116:55

larger so I think 45 pixels would be good enough right and then make it

117:04

black I'm also going to make this an H1 tag on than H2 as we want to prioritize

117:11

this and then I'm going to also put a paragraph okay and in the paragraph I'm

117:17

going to put I am a professional

117:23

software developer and

117:30

YouTuber I love to teach anyone and

117:37

everyone how to okay so that is looking good however

117:45

you will see because there's no div here at the moment the text is stretching I don't really like this

117:51

let's fix it it in the so let's check what this is in the P tag the parent of

117:59

it is hero info so let's go to Hero info and give it a Max width of 300 pixels

118:07

that's not a width that's a Max width okay so it will mean that this will change if I go any smaller the max width

118:15

will always be 300 great now I'm actually going to get rid of this image here I've decided that

118:22

I don't want it here anymore I'm going to have an About Me section and I think that will fit much better into it so I'm

118:28

just going to put it here and make sure that it's formatted

118:34

correctly the next thing I want to show you how to do is create custom thematic

118:39

breakes so a thematic break I'm going to show you what this looks like as a

118:44

default under the paragraph here so I can put in a thematic break similar to

118:51

this it's just a simple line it's essentially a break however I don't like it I don't really like how it looks I'm

118:58

going to create my own so I'm actually just going to use a div for this and I'm going to give a

119:06

class of styled

119:13

break so let's go into our CSS styled break

119:22

I'm going to give it a width so I'm essentially just going to make a rectangle and round off the edges width

119:29

give it a height 5 pixels so that we can see it a little bit and then give it a

119:35

background color I'm going to go with the purple

119:41

that I'm really into at the

119:47

moment so there we can see it right here and then I'm going to going to give it a

119:53

border radius we're going to round it off of 2.5 pixels so that is half the

120:01

height and then let's give it some margin so once again top

120:07

margin side margin bottom

120:12

margin side margin and there we go and finally I

120:18

just want to change this button it's not really the style that I'm going for of course this was a great button to show

120:24

you all the different things that we can do to a button but let's change it for the sake of this

120:31

design so I'm just going to get rid of the majority of this

120:39

now save that going to give it padding and pixels

120:47

instead let's give it a background color I'm going to use the orange that is in

120:54

my logo EF 866

121:00

C I'm going to give it a width 80 pixels of course a border radius because

121:08

I'm partial to border radiuses I say 20 pixels I say the font should be

121:15

white that is white and I also want the text to be

121:23

be uppercase so whenever there's a button we're going to transform text to be uppercase and font size 12 pixels

121:31

let's also align the text so it's Center so text align Center there we go so I've changed the

121:38

button however I'm not going to change much about the hover actually maybe let's change the hover to a slightly cuz

121:45

at the moment it just goes red let's change it to a slightly more orange orange

121:52

so I'm going to use 744b this is one I found on the

121:59

internet earlier okay I think that's looking good and if the button's active well we

122:05

still have the box Shadow inser and I'm quite happy with that I'm going to keep it let's go back to here now and instead

122:13

of Click me I'm going to put higher me and we'll link that up to something

122:19

soon okay so we have this here the one last thing I want to add is an image so

122:25

once again I'm going to drop in an image that I have previously

122:39

made it's an image called working illustration I'm just going to drop it in

122:45

here so let's just make sure that I don't want that one in there just going

122:50

to change it working

122:58

illustration illustration PNG great and inside this

123:08

div I'm going to get the image tag I'm going to open it

123:15

up I'm going to use the source of the

123:20

relative part I'm going to into my images folder and I'm going to get the working

123:27

illustration PNG great so there is it's very large

123:34

don't worry don't forget to give it some alternate text for the visually impaired

123:40

working illustration of a

123:46

woman awesome let's also give this a class we can sty it I don't like the size so

123:57

Class Hero image and let's go into

124:04

here and write under the I like to keep everything roughly together so under the

124:12

hero info I'm just going to have hero

124:18

image and let's make sure to give it a size that is makes sense so it

124:25

fits just going to give it that size right here and once again I'm going to give it a margin because I don't like it

124:31

being so close to here I'm going to say margin 30

124:38

pixels okay so if we go into the larger size like this we can see both and if we

124:44

start moving into the tablet so ideally this looks good and this looks good

124:53

however I don't really like it when it's like here we'll have to fix that as I said when we start doing more responsive

124:59

work so this is talking about break points but for now let's carry on so I'm

125:06

liking how this looks here let's get rid of this now we don't need this now we don't need to see how

125:12

the div is looking and there we go

125:21

I'm also going to get rid of this hero background I don't want it to be this color

125:29

anymore I just wanted to take on the color of whatever is the

125:37

body so in the body here I'm going to say background

125:47

color and this is a sort of off Gray

125:52

and perfect next up the abat me section I'm just going to move this over

125:59

for now like this so we can work on the About Me section so let's go back in

126:05

here so once again I'm going to have to split out the About Me section into two

126:10

divs so as you can see here in the purple Under the hero div and then each of the two purple divs is going to have

126:16

a different amount of divs in it stacked on top of each other so let's do it

126:22

hopefully this is becoming more clear to you we're going to do exactly what we did for the hero section but to the

126:27

About Me section so in this section right here I'm going to make a

126:35

div I'm going to call it I'm going to give it a class

126:41

of about me so there's our one div and there's

126:46

our second div

126:56

once again I'm just going to give it a CLA so we can see what is happening so

127:01

second into here under our

127:07

section about B and

127:14

then second so width 300 pixels height 300 pixels

127:23

background color blue and

127:29

margin pixels and then same for the

127:35

second once again you will see the two Dives now what is quite good about this is that they are in the section their

127:42

parent is section so we are already adding the flex wrap to it meaning that they will stack however there got a lot

127:48

of other stuff in here too so let's sort that out

127:54

first off in the About Me section well it is confined to a height so let's get

127:59

rid of that okay so there we go it's now

128:06

stretched it also has some other things in here which I don't want so let's go

128:11

back in

128:17

here I'm actually going to so in the first box box I want to put in my image

128:24

so let's do that for the about me let's get the image and then in here put in the image

128:31

so that is looking good and then in the second box I'm going to put the h2

128:41

tag okay and then we have some socials which looks fine if we view our site in

128:46

a browser of these proportions however if we get any larger the socials go to

128:52

the right I don't want this happening I want them to stack over each

128:57

other so I'm going to take one of these I'm going to remove them from this

129:05

section so that's looking better and I'm just going to create

129:10

another section so it's got its own separate section

129:16

now and let's just post them in here okay so this is the great thing about

129:23

classes I've essentially reused The Styling for sections so now each of my sections has this red and yellow

129:30

gradient I could just repeat section section over again and there we go I don't actually

129:37

like the colors of the section so let's just make it white have background

129:45

color white and there we go so even though

129:51

this is is technically two sections you can't really see the difference but they are staying in the correct layout that I

129:58

want at all times great now let's get to some

130:05

styling okay now I'm just going to get rid of the blue boxes for now and we also don't need this second box right

130:12

here so I'm going to get rid of that second and I'm actually going to call this info

130:17

instead that makes more sense and once again and just get rid of the height and

130:23

the background color for the about

130:30

me let's make sure that the image always stays in the

130:40

center let's do justify content space

130:49

evenly okay and let's add some text for the About Me

130:55

section so once again I'm just going to use a paragraph

131:01

tag and I'm just going to put some text this can be just a little bit about

131:09

yourself it's totally up to you I'm just putting some placeholder text here for

131:14

you

131:28

okay so we have our text it is quite long once again we get this problem so we can easily fix this with you guessed

131:35

it applying a Max width so we gave it the class of info I'm going to say

131:45

Max with 300 pixels okay it's looking

131:54

better and I'm also going to give it a margin of 30 pixels everything in here

131:59

I'm basically giving a margin of 30 pixels I just think it looks quite nice let's do the same for the image here

132:07

margin 30 pixels actually no let's get rid of it

132:14

from there okay so this looks good however it

132:19

doesn't look so great when we suddenly switch it out so I'm going to apply some styling to the

132:26

section of course Please be aware that it will apply to this but I'm absolutely fine with that I don't mind I think

132:32

it'll look quite good so let's find a section and give it a margin we just

132:39

want the top so I'm going to put 40 pixels and then the size we want

132:47

zero padding there we go

132:53

actually we might make it zero zero okay I think that's already looking

133:01

better we slowly getting there slowly but surely so there we have it you can of

133:09

course feel free to edit this as you wish I'm sure some of you have uh different ideas when it comes to styling

133:16

this is only a tutorial for you to take and use as you want let's check the

133:21

about me is linking correctly and boom there we go about me boom it's taking us

133:27

directly to that section I'm really pleased with that and let's just check for mobile that is also looking good

133:35

too okay now I want to put some Social Links here however first before we move

133:43

on let's actually create a contact me form so that's what I'm going to do forms up next

134:00

okay so next up we are going to learn all about forms so let's start creating our form using HTML and CSS first for a

134:08

form we will need some type of script in order to actually submit the form so it's going to be a great segue into

134:15

learning a little bit of JavaScript but before we get onto that point let's get it working visually but

134:22

so let's decide where we're going to do this well I'm actually going to create a new section for this so once again I am

134:29

creating a section there we go and in this section

134:34

I'm going to use a form tag so once again this is not something I'm making up this is pre-made for us and opening

134:41

up our form you won't see anything in it now this is because we actually have to start putting stuff into our form

134:48

first now I'm going to put an h2 tag in here that is absolutely fine you don't

134:55

just need to put inputs uh into a form so here is my first thing that I'm going

135:02

to put into the contact form and that is just an H2 tag you'll see that showing

135:08

up right here now the form element can contain

135:13

one or more of the following form elements an input tag a text area tag a

135:20

button a select option an option itself a field set a label and an output so I'm going

135:28

to show you some of these now let's create our first part of this form and

135:34

that is a way for someone to input their first name and last name so I'm going to create a label this is we can actually

135:41

see what the form options are for so label for first name make sure that is

135:50

an equal sign and I'm just going to put first name like so so we can see it and the

135:58

next thing we need to do is create an input so here we have an input tag I

136:03

want to specify that the type of input we take is text I'm also going to give an ID so we

136:10

can work with it later so this is just correct things that you need to put with an input field first

136:18

name and I'm also going to give it a name of first name this is also that we

136:24

can use it with our JavaScript later on and in here I can also put in a

136:30

placeholder we can do this by simply adding another attribute and I'm just going to

136:37

put John so there we go that's how you put a placeholder in of course this will

136:43

disappear if I start writing on it it's just a placeholder as mentioned at the moment

136:49

this isn't connected to anything that's what our JavaScript is going to do I'm just going to really push that out for

136:54

now so we can see everything in full so there we have our first label let's do

137:00

the same for a second

137:05

name second name second name or maybe we could put

137:11

last name that probably makes more sense last

137:16

name and then again I'm going to put a placeholder name of d so that is one

137:22

example of an input it is a text input I'm going to show you another

137:32

now so another input that we can have is a radio button option if you don't know

137:37

what a radio button option is I'm going to show you here so once again we use the input

137:45

tag I'm going to put type radio and you will see

137:51

we get a little dot that you can select show up like that so that's pretty cool

137:57

once again it has no functionality and once again we need to give it an ID and

138:02

a name so I'm going to go with ID and I'm going to use this for [Music]

138:08

displaying office work name office work and it actually does

138:16

need a value even though you can't see it for now I'm going to put in anyway

138:21

it's for later on in our JavaScript and once again let's not forget to give it a label so label this is for the button

138:33

itself for office and then I'm just going to

138:40

put office so what I'm getting here which I'm going to put that label below

138:46

that looks more sense that looks better so you can select

138:52

office like so just going to do a few more so I'm

138:59

just going to do maybe three so we got office and change this one

139:06

to remote work and once again make the label say

139:11

remote work so we can see it visually in our browser and then this one I'm just going to put

139:19

other other okay so now I have three options three

139:25

little buttons that is looking cool so we've

139:30

got a text input we've got a radio button what else can I show you well there's also another type of button and

139:37

that is a checkbox so why don't we go ahead and create that it is also an input

139:46

tag type we're going to put checkbox

139:51

so once again you can see it's already a checkbox and once again I need to give it an ID and this time I want my check

139:59

boox to tell me if its contract work so I'm just going to put ID

140:04

contract name contract and

140:11

value contract this might seem like Overkill but it will make sense when we start doing the

140:17

JavaScript so we've got input let's give it a lb

140:23

label for

140:31

contract and then just we can see the text contract

140:41

work okay and once again I'm just going to create two

140:47

more make sure they are format Ed correctly

140:55

too and that label is spelled correctly

141:01

Bell so we've got contract work let's make the second one full

141:12

time so once again full time and this

141:18

one we'll put

141:24

spons ship

141:32

sponsorship great so we have all our fields that we want we now need an onsubmit button and this again is going

141:40

to have to be an input so there we

141:45

go submit so we've got a button here

141:51

type submit value

141:58

submit and then I'm going to add the class that I use for this button here because I want all my buttons to look

142:04

the same class button

142:14

Tada so I don't actually need this here because it's picking up from the value

142:19

and there we go okay this is looking good let's just make sure to make it look nice so this

142:27

is where some of our layer Works going to come into at the moment if I pull this out it's just all appearing on one

142:33

line I want it to be a stor of each other and then on one line for some

142:39

occasions so let's do it like so I'm going to make a

142:48

div I'm going give it a class

142:53

of input section so at the moment you'll see that

142:59

that has split out this first one here let's do the same for the second

143:06

batch of inputs once again closing

143:11

div make sure to format correctly so it's more

143:17

readable and then last one

143:23

and I'm closing div and make sure to format it so it's more readable so now

143:29

instead of them all being in one line because I put them in three separate divs the three divs are stacking over

143:34

each other so that's one step in the right direction let's go to our

143:41

styling and then towards the bottom so I'm going to do it here

143:50

input section I'm going to put margin I'm

143:55

going to space them out the top not the

144:01

sides okay so that's looking much better I mean it would be nicer if this

144:06

perhaps fit on one row instead so let's do that up here

144:13

too I'm want to put the first name and surname in a separate div

144:28

it's one div it's a second

144:34

div and then I'm going to give this a class so that the first name is over the

144:40

input I want to give it maybe input group they are grouped

144:47

together so this one and then here do input

144:54

group do input group display

145:03

Flex Flex Direction

145:10

column and then let's give it a Max with two so just the width we find

145:21

well actually perhaps we don't need this and then for the input section display

145:27

plugs okay and just give this a margin so it

145:32

gets a margin just to the right that would be

145:38

0 5 pixels 0 0 okay and this is looking a lot

145:48

better nice let's perhaps give the form a bit of

145:53

space down here so I'm going to put up here form

146:03

margin nothing from the top nothing from the side 40 pixels of the bottom and

146:08

nothing from the other side okay great you can of course play around with these

146:14

as much as you like it is totally up to you it's obviously however you wish to

146:22

display these things same for the footer perhaps you want it to appear in the

146:30

middle once again I'm just going to use display reflex and justify

146:37

content Center to do that great this is all looking really good

146:45

there's three more things that I want to do before moving on to JavaScript and that is learn how to use icons create a

146:51

new page and talk about breakpoints so let's do

146:56

it in this section I want to talk to you a little bit about how we can include

147:02

pre-made icons into our project with the help of something called font awesome

147:08

let's do it font awesome is the most popular way to add font icons to your

147:13

website font icons are created using scalable vectors so you can use high quality icons that work well on any

147:19

screen size I'm going to show you how to do this now so I'm just going to minimize

147:26

this you can already see all the cool icons that we can use all we need to do is get

147:31

started so start get started for free I'm going to put in my email address and

147:39

then get sent the startkit code so you will see that I've already got it sent

147:44

to me but you should receive some code that looks a little bit like this

147:50

this okay so click to confirm your email select a password so I'm just

147:57

going to select a strong password Ania

148:03

Kubo just going to leave this to 2020 and all let's go okay so you first

148:11

need to add your kits code to a project so I'm going to copy this script and

148:17

head over to my index HTML file well I will put it in the header so just under

148:25

the link here I'm going to put in my special link to font awesome now I'm

148:32

going to pick a free icon so let's just go ahead and for the sake of this use

148:38

this one make sure to be in free you can of course choose a paid one too but for

148:45

this I'm just going to use a free version and then you can choose the

148:50

color you can essentially edit this as much as you like I'm going to click start using this icon and then I'm

148:57

simply going to copy this go back to our code and then the index HTML file where

149:06

you can see these divs here I'm just going to replace it like

149:11

so and there you go you will see my user Circle show up now I can of course edit

149:18

these more and more if I want however you might have to upgrade for this there is so many and so many you

149:24

can choose from for example if I want to start using this icon just going to copy

149:32

that and once again put that in my project and you will see I can go ahead

149:40

and replace all of them okay so that is how you would use

149:46

Font awesome icons there are plenty of free ones there are p ones too and you

149:51

can of course edit them the colors and how large they are based on your

149:56

preference if I want to pick one out I can simply pick out one of these words so I'm going to choose

150:02

far as it's the class name that is appropriate for all of them so I know

150:07

that we mentioned that elements can have more than one class name this is a great example of that I'm going to go in here

150:14

I'm going to pick out far and I'm going to give each one a margin

150:20

of three pixels okay so that immediately spaces them all out at the moment these

150:26

are not linked to anything but please feel free to link them up using the href similar to how we did with the list

150:33

items that is also an option too now let's move on to creating new pages so

150:40

as you can see I have my contact me section right here let's go ahead and

150:46

move it to the contact page cuz I think it will make a lot more more sense there so I'm going to essentially take this

150:52

entire section so I'm taking the entire section here you will see now that the form is

151:00

gone and I'm going to actually put it into my contct HTML page and save so

151:12

now if I click on my contact page you will see that the form shows

151:17

up once again I'm going to put this in my my browser click on the contact and

151:23

there we go as a reminder you will see that the URL has also changed so the URL

151:28

is taking us to the Pages directory and then our contact page at the moment this

151:35

page is not really built out we cannot even go back to our homepage from this page we will need to essentially delete

151:43

the URL in order to do that so that is something that you might want to consider working on if you do want to

151:48

have more than one page in your project let's go back okay so even though this is looking

151:56

great I am also going to keep a copy of this in my index HTML file there's no

152:02

one telling me that it can't be in both places so I'm going to keep it like that okay so I think we are now ready to move

152:09

on to talk a little bit about break

152:17

points so so far in this tutorial we made a web page with RS and columns it

152:22

was responsive but it did not look great when we changed the size of the screen to just about here we were left with a

152:29

lot of white space to fix this we need to talk about break points and media queries can help us with that we can add

152:36

a break point where a certain part of the design will behave differently on each side of the break

152:42

point media query is a CSS technique introduced in CSS 3 it uses the at media

152:49

rule to include a block of CSS properties only if a certain condition is true for example here if the browser

152:56

window is 600 pixels or smaller the background color will be yellow let's

153:02

check it out okay now let's see this with an example so here we have our page once

153:09

again I am happy with it when it's in mobile I'm happy with it it's in browser

153:14

I'm not happy with it when it's around here okay so let's change that I'm going

153:20

to guess that the width of my page is about 600

153:25

pixels so if anything is under 600 pixels I want the text to stretch and I

153:33

want to make the image disappear so we can do this like this I'm going get at

153:40

media only screen and Max

153:47

width 600 pixels just going to make this a little

153:54

bit smaller so we can see so now if our browser is under 600 pixels I

154:01

want the hero info to have

154:07

a width of 600 pixels

154:22

so you will see 600 over 600 over 600 over 600 and under 600 and you will see

154:30

that text is now spread so once again over

154:35

600 under 600 so perhaps we can even make it larger let's make it Max

154:43

width 800 700

154:49

you could just fill around with this whatever feels good to you so there we

154:55

go and that's when the switch happens you can even see it in slow motion there we

155:00

go and then make the max with 650 or 700 actually just to make it fit

155:08

the whole way and there we go okay now let's make the image

155:15

disappear so make sure you are in the curly braces and at The Brak point of 700

155:23

pixels I want you to get the hero image and

155:28

visibility hidden okay so we can see the image and

155:33

then can't see the image it's disappeared I'm also going to make the

155:40

height 0 pixels so that looks a lot better and there we go

155:51

so I'm pretty impressed with that I think that looks a lot better we are simply getting rid of the image once it

155:57

gets the 700 pixel break point you can also have as many break points as you

156:02

like so obviously there's ours and boom then it disappears it is totally up to

156:10

you try again with a color just to get some practice with it let's do about the

156:16

footer so the footer changes color that should be quite simple for us to see so

156:21

let's scroll down to the footer and then right below it add media only screen and and then

156:32

Max width so let's set the max width is time to 500 pixels so as soon as our

156:39

browser gets to 500 pixels so if we're going this way

156:46

500 over 500 pixels over 500 pixels over 500 pixels under 500 pixels the color

156:52

will change so let's grab our footer so let's grab our

157:00

footer and make the background color

157:07

blue refresh once again over 500 pixels over

157:12

500 pixels over 500 pixels over 500 pixels under 500 pixels blue over

157:20

under over under so that is pretty

157:26

cool now of course we can also have Min width as well so if I change that to Min

157:33

width and save the opposite will happen so a lot of developers actually design

157:39

mobile first which means they will make sure that the design looks perfect in a mobile form you will find that most

157:46

websites do get visited the most from mobile so perhaps this is the shift happened it also means that if you

157:52

design mobile first you will need to use the minwidth on your media queries

157:58

because as you get larger so then you start designing for tablet then you'll apply a style and then if you want a

158:04

different style for desktop where you can add another Min width so that's it

158:09

Max width and Min width it just depends what browser you are designing for first

158:15

and what you feel most comfortable with okay let's move on I think it's now time to start writing some

158:22

JavaScript but before we do that let's recap everything we have learned so far about HTML and

158:35

CSS let's take a quick break to talk a little bit about the Zed index I'm going

158:40

to do that now the Zed index property specifies the

158:46

stack order of an element an element element with greater stack order is always in front of an element with a

158:53

lower stack order I'm going to show you what I mean by this and how we can use the Zed

158:59

index so here we have my index HTML file I'm just going to go ahead and put

159:06

into divs so here is one

159:12

div let's give it a class first block

159:20

and then div second

159:27

block now let's go into our stylesheet which is in the source

159:35

folder let's grab the first block so just like we did here we need to get the

159:41

class so I'm going to use a DOT for class and then open up our Kye braces so

159:48

that is our first block I'm going to style it up a bit so I'm just going to give 100 pixels width and

159:53

a height of 50 pixels and a background color of

160:02

coral and I'm just going to copy this we're going to have two blocks so it's the first block and it

160:09

was the second block so once again that is a class so we need the dot and I'm just

160:17

going to pull it second block and let's give it another color so we can

160:22

tell so there we have it now I can actually move so I'm just going to give

160:29

this a position of

160:34

absolute by saying position absolute I'm saying that I want the position of the

160:40

first block to be absolute what I mean by this is by giving the position property the value

160:47

of absolute we are making Mak sure the element is positioned relative to its first positioned ancestor element so I

160:55

have given the body some styling if I was to just commment that

161:00

out and refresh that is the absolute position okay it will always be there

161:06

that is absolute and if I was to do the same for

161:12

the second block it will be in the same position they're not uh appearing in line or

161:18

block I would then move I can then move the second block so let's give it a left 50

161:25

pixel so I've literally moving the second block which is a light SE green 50 pixels to the right by giving a left

161:34

spacing so given it left spacing of 50 pixels I can go 150

161:40

pixels I can go 80 pixels okay that is just one example of how I would use

161:46

position absolute and left now say we had this styling but I actually wanted

161:52

the second block to appear below the first block okay so what I mean by this

161:58

is I want the orange block to be more visible and the green block to be below it I could do this with the Zed index so

162:07

I can either choose to get the first block a zed index of one and that would move it

162:14

above the green or second block which has a default Zed index of

162:20

zero I could also have chosen to give the second block a zed

162:26

index of minus one okay both things would do the same

162:32

thing that is how the Zed index works sometimes when you have more than one or

162:37

more than two elements apart from yours on your screen you would have to increase the Zed index from -1 to - 2 -3

162:47

or - 99 to be sa if you do really want it to be at the very very bottom of the

162:54

stack okay so that is how the Zed index works I'm going to ask you to do this by

163:02

yourself with a little challenge so I'm just going to get rid of all

163:07

these so make sure in your style CSS you just have a body with a background

163:14

color and then in your index HTML file I'm just going to refresh

163:21

this we're going to have a first block a second block a third block and a four

163:27

fourth block so third

163:32

fourth so that is my index HTML file that is my

163:40

stylesheet I want you to essentially build out the four blocks as circles so

163:47

I want you to create four circles and stack them on top of each other so

163:52

but visibly on top of each other like we just did to have the first block at the top and the fourth at the bottom okay so

164:00

four blocks or let's just be more precise four

164:07

circles that are stacked on top of each other as a clue I've made this example

164:13

this is what I want you to recreate in your browser you can make the colors different you can make the space faing

164:19

different that part is up to you okay I'm going to pause here while you have a go at doing this so once

164:26

again this is what your index HTML file should look like and this is what your style sheet should look like

164:34

okay good luck I'll see you in a

164:45

bit okay so if you've managed to do that well done and if you haven't don't worry we're going to go through the solution

164:52

together so I'm just going to make sure that I've saved these files we don't need the index JS file for

164:58

now so the first thing I would do is grab my first

165:04

Circle I'm just going to grab the first Circle let's open up our Cy braces let's

165:10

actually style it up so we can see it I'm going to use 50 pixels and a height of 50 pixels and then a border

165:19

radius 25 pixels to make it a circle making sure just SP border radius

165:25

correctly and background color let's say

165:33

salmon and I am actually going to reinstate this cuz I do want it to be in the

165:38

center so that is my first Circle I'm actually going to make it a

165:44

bit bigger why not it's a bit small so there we go my first Circle I'm

165:51

actually just going to copy this for the second Circle and let's give it another color

165:58

this time let's make it a bit

166:04

lighter it's not lighter let's make it lighter

166:19

we go and then we need a third

166:26

circle once again I'm going to make it even

166:33

lighter and a fourth circle which once again you

166:39

guessed it I'm going to make even lighter so we've got our four circles

166:45

now I want them to stack over each other so let's do that first well I could do

166:51

that in the body so I can simply write Flex

166:58

Direction column and there we go they are stacking

167:03

over each other I'm also going to give it a

167:10

margin left so we can see it 150 pixels it's just for us let's get

167:18

rid of that and now let's do some positioning and

167:24

Zed indexing so for this one position

167:30

absolute so it might appear to be disappeared but it's just because all the circles will now be in the same

167:38

position roughly or exactly so there we go so that is our absolute positioning

167:47

now the first Circle well that was the darkest wasn't it so let's give that a zed

167:53

index of Min -4 and I'm also going to give it a top

168:00

of 400 pixels so now it's moved all the way down there that is fine for now we

168:06

will be adjusting these this one I want to be the third last so I'm going to

168:11

give it a minus 3 index and top 300 pixels

168:20

actually maybe let's make it go down a bit more so let's go 350

168:25

pixels okay so you already see it is

168:30

stacking this one we're going to give it a zed

168:35

index of minus 2 and a top of 300 pixels there we go and then finally the

168:43

full circle which is the top Circle I mean I just leave it as it is

168:50

in fact so top 250 pixels and there we go we have now

168:57

completed the challenge it is absolutely fine if you chose to do the Zen indexes the other

169:03

way so use positive numbers or choose different colors or choose uh different

169:08

sort of styling as long as you've got them stacking to look similar to this you have passed the challenge so well

169:16

done I hope you've enjoyed this little challenge with me let's carry on with our

169:22

lessons congratulations everyone you have now finished the CSS section of our

169:27

boot camp next up it is time to focus on JavaScript now even though we have

169:32

finished the CSS portion there will be some extra lessons in the next section to as CSS and JavaScript are often

169:40

closely intertwined for now I would save the project we have been working on and

169:46

put it away while we will go back to it at one point in the course that part of our learning is now over and we should

169:53

start up a new project or window in our code editor JavaScript is considered to have

170:00

a different way of thinking than CSS and HTML it can take a while to get used to

170:05

it and for it to stick this is why this section is going to have a lot more

170:11

exercises and projects along the way don't worry though when you understand

170:16

the way of thinking in JavaScript it will become second nature to you something will just click patience and

170:23

persistence will be key in this section so please do pause and go over a section again if something is not clear the

170:30

first time round once again I will be providing code playgrounds for each of

170:35

the lessons so if you do start a new section or for some reason your code editor is not working please use the

170:42

timestamp code playgrounds in the descriptions below Okay so what are we

170:49

waiting for let's do it JavaScript we will be starting off with some Basics and moving on to the fun stuff once we

170:56

get an understanding of the fundamentals first such as what is a variable a

171:02

function and so on okay now it's time for the JavaScript

171:09

portion of our course but what exactly is Javascript JavaScript is a scripting

171:14

or programming language that allows you to implement complex features on web pages every time a web page does more

171:21

than just sit there and display static information for you to look at you can bet JavaScript is probably involved it

171:28

is the third layer of the cake when it comes to standard web Technologies two of which we have already covered our

171:35

HTML and CSS JavaScript is not to be confused with Java which is a completely

171:40

different language in itself so to recap JavaScript is not Java it is a

171:46

completely different language JavaScript is also one of the core Technologies of the worldwide web this is alongside HTML

171:53

and CSS JavaScript essentially allows us to have interactive web pages so as in

171:59

the case of the form that we are currently working on it will allow us to add functionality to that form and send

172:06

off information for us what is even more exciting is that we can actually add extra levels or superpowers to our

172:13

JavaScript code with so-called application programming interfaces or

172:18

apis apis are readymade sets of code building blocks that allow a develop to implement programs that would otherwise

172:26

be hard or impossible to implement think of it in a way as Lego blocks you're building something in Lego and then you

172:32

suddenly see a whole other part that's already been pre-built for us we can essentially take that part and put it

172:38

into our project that is what an API is in a nutshell don't worry we'll be

172:43

looking at some real examples of this later on so in this part of the course this is

172:49

going to be the biggest part of the course as there is a lot to learn we've already covered the Core Concepts of

172:56

JavaScript next up we're going to have a look at variables and then control flow

173:01

which includes if statements for Loops operators then classes functions methods

173:07

and HTTP there's a lot to get through I'm excited let's do it in this section I

173:14

want to talk to you about file setup when working with JavaScript let's do it

173:20

so up until now we've only been working with HTML and CSS this is some boiler

173:26

plate for our HTML which we discussed in the previous section I also have a link

173:33

to link our stylesheet so our style CSS file which is here we have told in our

173:40

IDE that this is a CSS file by giving it CSS extension file extension and hence

173:48

we get this little logo right here now how do we get to adding JavaScript well

173:55

first off I'm actually just going to make a Javascript file I'm going to call it index

174:01

JS so JavaScript JS is for the JavaScript we are telling our IDE that

174:07

this is a Javascript file and enter and you will see the JavaScript logo shows

174:13

up which means this is correct this has worked we've got our index JS

174:20

file now if we go back to our index HTML I can use a script tag so similarly to

174:27

how do I did here I could simply put a script tag like so so opening and

174:33

closing script tag and then the source of this is going to be my

174:40

index JS file now it is best practice to put

174:46

the index GS and sty sheet in a file of its own or a folder of its own sorry so

174:52

I'm going to make a new directory and call it Source in it I'm going to put my index

174:58

JS and style CSS this might not make sense now but when it comes to building projects and

175:04

deploying them onto the internet it makes sense to have the source folder different to the build folder so that is

175:11

how we would do it this however means we get some error messages because before

175:17

the index HTML file was in the same directory so the same the root of our

175:24

project with the star CSS file it can't find anymore because we are telling our

175:30

index HTML file that the stylesheet is here with it in the root it is not nor

175:37

is the index JS so we need to fix this by going into our source folder and

175:43

getting the stylesheet and once again going into our source folder and getting

175:48

the index JS file and there we go we have now fixed the

175:55

errors now if you do wish to keep your script file in the header and this is

176:02

important so I'm just going to open this up yet we would have to actually wait for all the HTML to be

176:09

loaded before applying any JavaScript so to do this I would have to add this

176:16

piece of code which we will start talking about much later in this lesson so I'm just going to show you for now

176:21

but keep it in mind because we will go back to it I would have to use a ad event listener to listen out for when

176:29

the content is loaded so like that and then once all of

176:38

our HTML has loaded then so don't content loaded and only then will we be

176:44

able to execute any JavaScript Okay so so that is one approach it is totally up

176:51

to you if you use it this way or you can get rid of that and simply move our script tag to

176:59

be at the very bottom of our body so in this case you'd have to remember to

177:04

write all your HTML above the script tag at all times each way is correct the

177:12

first one is considered to be maybe a little bit more foolproof but both work for small projects each one is fine I'm

177:21

going to carry On by using this approach for this course okay I think we now have

177:28

the setup down if you are using the code sandbox like I am there is a preference

177:35

that I like to use if you go into the file and into the preference settings

177:41

and choose sandbox settings in the prettier settings I have chosen

177:48

then to essentially get rid of my semicolons this is a personal preference

177:54

as well I don't want the semicolons are being added if I save a file I've also

178:00

chosen to use single quotes so these are two of my preferences this is what

178:05

you're going to be seeing in the course so if you like the way I write it then please feel free to change these or if

178:12

you don't want to that's absolutely fine too the choice is up to you so that is

178:17

how you go into it once again it's file preferences code soundbox settings and

178:23

prettier settings these settings the prettiest settings will essentially be applied each time you save a

178:31

file great let's Carry On First lesson

178:36

of JavaScript let's go first up variables okay so before we get started

178:44

I just want to take a little moment to talk to you about the file structure here so as previously we have our index HTML

178:51

file in the root of our project meaning it's at the very base of our project I

178:57

have then created a directory called Source in which I have stored my stylesheet so just like we were working

179:04

with before when it was just CSS and HTML however I have put it in its own folder and then we have an index JS file

179:11

in here now too so this is new I have named it index and I have told my code

179:17

editor to treat this as a JavaScript file based on the extension I have put

179:23

these in a source folder it might not make sense now you might think why am I bothering to do this however when it

179:29

comes to actually deploying what we built this is a very important step I'm not going to go into it too much now

179:35

however just be aware of that it is something that we're going to cover when it comes to deploying our project okay

179:41

so as a recap make sure the index HTML file is always in the root and store

179:46

your stylesheet and index JS files in a source folder

179:51

okay let's get to our first lesson of JavaScript so in JavaScript you can store values in something called

179:58

variables they are legal identifiers quite simply it is this so

180:06

the variable X here equals 1 it is important to note when you declare a

180:11

variable its name must be unique you can assign numeric value to your variable so

180:17

like this number one here you can also assign a string value so by string I

180:25

essentially mean a word or a number or a Boolean

180:32

that is in between two quote marks that makes it a string an

180:39

array so an example of array would be this I am opening up my array so I'm

180:44

getting these two square brackets and then passing through a string and then another string that is an array

180:51

of two strings we can also store booleans

180:57

so true or

181:03

false and finally we can also leave our variables undefined so that we can assign it value later on now by

181:11

definition variables means anything that can vary so let's see this in action

181:17

just going to get rid of all these for now we're stripping it back to just

181:22

saying that VX equals the numeric value one now let's grab X so I'm going to

181:28

grab X and assign it the value 23 note we are not declaring it again so

181:36

we're not putting VAR here x has already been declared up here we are simply assigning it a new value and that is the

181:44

numeric value 23 I'm going to use something that is inbuilt essentially

181:49

and that is a console log so I have not made this up this is for our use and I'm going to console log the value of x to

181:58

view this I'm going to get my console log up so in here in our simulated

182:04

browser I can click on Console in order us to see what is essentially going on

182:09

in the back so this is how we would view it I am seeing that yes I'm console logging 23 I can also console log

182:18

directly so just hard code something like hello and that will show up in our browser too so I'm console logging a

182:25

string and am console logging a numeric value this is essentially the same as me

182:33

inspecting the page in the browser so once again let's go to Google similar to

182:38

our example before and I'm going to inspect the page so once again control and left

182:44

click inspect and click console here this is

182:50

exactly the same as what we are simulating in this online IDE so let's

182:55

refresh that now I can also reassign this another value so if I click save

183:01

now X is now five you can imagine it as me just taking this value and sticking

183:08

it on top of here and then on top of here if I however get this and put it

183:14

there and refresh the value of X is 23 this is because we read JavaScript from

183:21

top to bottom okay now let's talk a little bit

183:26

about Scope when defining variables it is important to know that they have scope

183:33

variables have two types of scope Global scope and

183:39

function scope Global scope means that variables can be accessed in a whole Javascript

183:46

file right here and function scope means that the variables can only be accessed inside a

183:53

function let's have a look at this in code so I'm just going to get rid of this

184:01

here I'm going to write a function this function so this is the first function that you're going to see

184:08

print name this is essentially the Syntax for a function you tell the file that you're

184:16

writing a function so once again I did not make this up this is how you tell the file that you want to write a

184:22

function this however I did make up this is a name that I have chosen to call my

184:27

function I've chosen to call a print name we then open up some parenthesis we

184:33

do this so we can pass variables into our function and then we use some cardi braces and this is where all the magic

184:40

happened so this is where I'm going to write my code to invoke the function

184:48

we then do that so just as an example I'm just going to put console

184:54

log High

184:59

Ana and there we go you will see that because I'm calling my function I get

185:05

high Ana if I get rid of that essentially nothing will happen I

185:11

need to call the function in order for this to work okay now I'm going to declare

185:17

variable so I'm actually going to say VAR name and declare this as Ana now

185:24

instead of Printing High Ana here I wanted to print whatever name I want so I'm just going to pass through the

185:30

variable like so so console log High Ana if I clear my

185:39

console log you will see that that is working

185:45

that is because our variable is stored globally okay it can be accessed within this

185:51

function I can change this to Chris I can change this to

185:58

Rob this is a great example of a variable having a global scope however

186:05

what if I move this variable to be inside another function so let's have it here

186:12

function print last name

186:20

and then let's call our print last name function and in here just going to put

186:26

console log

186:33

Pi name last

186:40

name don't forget a

186:45

space let's define last name so last

186:52

name Deca just going to move this over for

186:57

now so now we have two functions this function prints out the first name and

187:03

the last name so maybe let's change it to print full

187:12

name and this one just prints out the first name they both work as both of

187:17

these variables are Global but what if I took this variable and put it only in

187:29

here so now just going to make it more clear

187:35

which one we are working with print

187:43

name and this one is print full name

187:49

so now print name we'll pick up hi Rob this is because the variable is being

187:55

declared here however we are not picking up the name here you will see in the

188:02

console log that print full name is simply printing out High Deca this is

188:07

because this variable here now has function scope we cannot access it in

188:13

this function it is scoped to this one only so I'm just going to move this over for

188:19

now so you can see everything so let's recap that again this variable so V name

188:26

is Out Of Reach for this piece of code okay hopefully you now understand a

188:32

little bit about global scope and function scope let's move on

188:48

now what is const

188:54

and let and how do they differ from V so when es6 came in it introduced two

189:03

new ways to create variables let and const so what is the difference between

189:10

them and VAR let's focus on let and VAR first let allows you to declare

189:17

variables that are limited to a scope of a block statement unlike far which

189:22

defines a variable globally or locally inside a function I'm going to show you

189:28

a great example of what I mean by this just going to move this over so

189:34

here we have a function function find X you will see that v x is here defined as

189:40

one and then inside these squ braces we declare VX again we say VX is two

189:48

now if I console log X here gives me two and if I console log X here it also

189:55

gives me two this is interesting as I would have expected X here to be one as

190:03

I would have thought that v x here is outside of its scope however with v that is not the

190:09

case let me show you the same thing but with let so I'm just going to change this and

190:16

this to let and click

190:21

save you will now see that X in here is 2 and X in here is one that makes a lot

190:29

more sense to me this is because X here is outside of the scope of here so X

190:36

should be one so I've written the same function simply replacing let with

190:42

v this is what I mean when let allows you to declare variables that are limited to scope of a block statement

190:49

unlike VAR which defines a variable globally or locally inside a function

190:55

hopefully you can see how using VAR can be very confusing for writing code this

191:00

is just one of the reasons that let and const were invented and why VAR is very

191:05

rarely used today in professional coding standards however it is useful to have

191:11

this knowledge just in case you see it being used in projects now finally there is is

191:19

const const works in the same way that let does in that you cannot access it if

191:25

it's defined inside a function or block statement however it is also constant as

191:31

the const would indicate once you have defined it you cannot overwrite it later on this is pretty useful when working

191:39

with big projects and declaring what you do not want to be changed let's have a look at this in our code editor so for

191:46

example here I have const count and I'm just going to put some

191:52

integer values in here like so now if I get count and try to

191:58

override it so I'm just going to put 1 two 3

192:07

8 you will see here count is readon we cannot override count if I was to

192:14

console log out count you would see this orig array not this one we cannot

192:20

override cons okay so there we have it let's

192:27

recap V declarations are globally scoped or function scoped while let and cot are

192:34

block scoped V variables can be updated and redeclared within its scope let

192:40

variables can be updated but not redeclared and const variables can be neither updated

192:47

or redeclared let's have a look at some more examples together so I'm just going

192:53

to get rid of this for

192:59

now okay now time for a little practice question just going to move that over

193:05

here and move that back here we have two functions one here and one that has been

193:12

commented out both of these functions will not work as count is not defined F

193:17

so it hasn't been declared and nor has name using either const or let how do

193:23

you think we would solve these functions in order for them to work as a clue you just need to declare them using const or

193:31

let here so have a think about it which variable do you think would suit count

193:37

here would it be let or

193:45

con okay so I'm I'm going to show you now this function increment essentially

193:51

takes the count which is currently zero and then assigns it the value of whatever count is at that current moment

193:58

in time plus one so when we call this function it should add one to whatever

194:04

the current count value is if I choose

194:11

const this function will not work this work because count has already been declared as a con and is read only

194:19

meaning we can't reassign it in new value I would have to make this

194:24

let so now if I console log

194:33

increment and return the count I will get the value of

194:42

one great let's move on

194:47

here we have another function that currently does not work this is because name is currently

194:54

not declared we need to tell our JavaScript whether to use let or const

195:00

so here we have a function that uses the name variable we have written a function we have called it send text and then we

195:07

are simply console logging hey name you left your bag at my house and then we

195:13

are calling that function so as you can see here we can't do it at the moment it

195:20

is not working we need to decide whether name Doug is let or const what do you

195:25

think it should be okay well I can tell you that the

195:33

name Doug if I choose let that technically will work however

195:40

it's not the best practice as the name is not going to change we are not reassigning a new value I should be

195:47

using const because the name will not change hey Doug you left your bag at my

195:55

house okay so hopefully that has enlightened you a little bit more into the uses of let and const once again we

196:02

will not be using VAR from now on V has essentially been replaced by let and con

196:08

with es6 and we will not be using it from now on next up we're going to learn about control flow

196:18

okay and now it is time to move on to control flow JavaScript supports a

196:24

compact set of statements specifically control flow statements that you can use to incorporate a great deal of

196:30

interactivity in your application this next section provides an overview of all of these statements so if statements for

196:38

loops and relational operators let's start off with if statements the if statement executes a

196:45

statement if a specified condition is truthy if the condition is falsey

196:52

another statement can be executed but what exactly does truthy and falsy mean

196:58

to explain this let's look at falsy first a falsy value is a value that is

197:05

considered false when encounted in a Boolean context JavaScript uses type

197:10

conversion to coers any value to a Boolean in context that require it such as conditionals and loops there are

197:17

eight falsy values this is the keyword false the number zero the number

197:24

negative zero big int when used as a Boolean just as a bit of insight big int

197:30

is a built-in object that provides a way to represent whole numbers larger than 2 to the^ of 53 it's not really necessary

197:37

for now but just keep that in mind an empty string value null so the absence

197:44

of any value undefined an Nan or not a

197:49

number this makes it very easy for us to Define what is truthy as it is everything unless it's a falcy so some

197:57

typical examples of truthy values are the number 2 five six basically any number that is not Zer or negative Z

198:05

strings the Boolean true and that's just off the top of my head as a rule if it's

198:11

not one of these eight you can consider it to be truthy

198:16

okay but enough chat let's actually get to learning this with examples of code first so as mentioned the if statement

198:24

executes a statement if a specified condition is truthy so the simplest

198:29

example of what I can do to show you this is write an if statement so if and

198:34

then whatever I pass through here is truthy execute this block of code so I'm

198:42

just going to put a console log here it is

198:53

truthy now I can be very basic about this and simply pass through the Boolean of true if I pass that through I am

199:00

indeed printing out it is truthy this is because true is truthy the same for the

199:07

number three because three as a number is truthy as you can see here the console

199:14

log is printing out it is truthy and then I could pass through a string like

199:19

this once again it has printed out again because this is truthy now just going to delete that

199:28

clear our console log if I pass through a zero and

199:33

save well you've guessed it nothing is printing because this is falsy so we are

199:39

not executing this because if this is true or truthy then we execute this line

199:47

if it is falsy well we do nothing so once again if I pass through false

199:53

nothing and if I pass through an empty string also nothing I can also do things

200:00

like this so if a is bigger than

200:05

two console log truthy and let's set a here so con a

200:12

equals the number one it's clear here our console well a

200:19

if a is 1 one is bigger than two that is

200:26

false so we do not get anything printed in our console log however if I change

200:32

this to our five it is truthy why because five is indeed bigger than two

200:39

so this statement is true or in other words truthy and we can print out our

200:45

console log so this is great it's very useful when

200:50

it comes to programming there's a lot of if else statements that are used on a daily basis one other thing that I want

200:57

to show you is the if else statement okay so if this is true print out

201:04

console log otherwise print out it is

201:11

false see okay so now if I go back to a

201:17

is one I am printing out it is falsy so

201:22

before nothing would happen so when we think back to when we didn't have this nothing would happen however we have now

201:29

giving it an else statement so if this is true print out truthy otherwise print

201:36

out it is falsy so once again let's read that if this is false then skip that and print

201:45

out this is falsy so I'm just going to replace it with actual Boolean if false

201:52

it is falsy and if true it is

201:59

truthy if a is deeply equal to

202:06

1 so if one deeply equals 1 it is truthy or if a deeply equals 5 well it

202:15

is faly because because one does not deeply equal five this is something

202:20

we'll go into in a little bit it essentially means deeply equals because this is not a thing in JavaScript that

202:27

will not work we need to either have this or this but don't worry we'll leave that for another

202:34

time now we also have the else if statement so I'm just going to get rid

202:41

of this get rid of that

202:48

let's have a variable I'm going to call it const time and set the time as an

202:53

integer to be 10 now

202:59

if time just to be clear this is going to be in 24hour time so that's 10:00

203:07

a.m. or actually maybe let's make that more obvious so let's make 14 14 hours

203:14

so 2 p.m. for those of you who don't know 24hour time that is 2: p.m. if time

203:22

is smaller than 12 console

203:28

log good

203:34

morning and then instead of just an else I'm going to have a if I'm going to have an else if time dly

203:43

equals 12 console

203:48

log oh it's noon it is

203:57

noon and then else now I could have time is larger

204:04

than 12 or I could just leave it like that because we've exhausted all our

204:10

options if it's not this and it's not that well then we know that it's

204:21

afternoon okay so as you can see here if the time is currently 14 it is the

204:29

afternoon and we get a message that says good afternoon now if I change the time

204:34

to 12 oh it's noon and if I change the time to 9 good morning so that is a great

204:42

example of an if else statement we can really go town on this so if I really

204:47

wanted to I could get rid of this and write else if time is

204:54

larger than 12 and time is smaller than

205:05

18 console log good

205:12

afternoon else

205:18

console log good

205:23

evening save that and let's try so once again good morning 12 oh it's noon and

205:32

then let's get a time between 12 and 18 so 14 good afternoon and then if we go

205:38

19 good evening so yes there's a lot of flexibility with this you can go on and

205:44

on and on there's really no stopping you with an if statement now we have done

205:49

two things that I haven't discussed yet and that is as mentioned this triple equal sign and the double and we will

205:57

get onto this this is of course a mathematical operator this means that

206:02

whatever is on this side is larger than whatever is on the right side and the opposite for

206:09

here okay so before we carry on I just want to take a moment to talk to you about operators as we have actually seen

206:16

someon action but you might not know what they were called or how they really work so I'm going to take the time to

206:24

explain that for you so there are a lot of different types of operators that we can use in

206:30

JavaScript the most basic is the arithmetic operators then the assignment

206:35

operators comparison operators logical operators and tary operators there are a

206:40

few more but these are the main ones so I'm just going to focus on these let's

206:46

start off with the arithmetic operators first so the arithmetic operators well

206:53

there's six that you should know and that you can use in JavaScript in order to make your life a lot easier if you

207:00

did do maths at school some of these will be really familiar to you or you might pick them up a little bit easier

207:06

but don't worry I'm going to go through all of them now so first up we have modulus well modulus is simply something

207:14

that will tell us what the remainder is after we use it so for example I could use it in this situation so I'm just

207:20

going to show you like a simple mathematical example if I put through the number five and use modulus

207:28

3 well three goes into five exactly once

207:34

and we leave two as a remainder so our console log will print out the number

207:41

two what do you think will happen if I put a four in what do you think my console log will spit

207:50

out well it would spit out a one that is because four goes into five once and

207:57

would leave one remainder let's do something a little bit more complicated

208:02

let's try 20 and great we would get a zero this is

208:07

because four fits into 20 exactly five times and leaves zero as a remainder the

208:13

use of modulus might not be super clear to you now now but if you try one of my game tutorials which I'm going to suggest for you during this course it

208:20

should become super obvious as to why I love modulus I use it in Pac-Man I use

208:26

it in snake I use it in pretty much all my grid based games so please do check them out when the time comes to

208:33

it next up we have the increment operator well this is something that you might

208:39

have seen in the for Loop it is simply incrementing a number by one so in our

208:45

for Loop you to see an i++ being used this is the increment operator I'm going

208:51

to show you how to use it I can use it like this so let's say let count equals

208:57

4 and then if I got count and used Plus+ and then console logged

209:06

count well you would guessed it I would get five this is because we are getting

209:11

count so here we have assigned the value four to our variable of count so here it

209:18

is four but then we use the Plus+ or the increment operator in order to increment it by one so when I conso it out here I

209:27

would get a five the decrement operator is pretty much the same so once again

209:34

let's go let count once more I'm going to get rid of it

209:41

here let count equal 20 count negative negative so that's the

209:48

decrement operator and if I console log count I should get

209:57

19 next up we have un negation this simply means that if let x equal 4 and

210:06

then I console log X well I would get a four but if I put a

210:13

negative in front of it I'm simply adding a minus 4 to it so un re negation

210:18

is essentially just adding a negative to make something negative okay it's it's really that

210:26

simple now the UN plus we can use this to essentially turn strings into numbers

210:35

so let me show you what I mean by this so I'm just going to get let Y and I'm going to use four but put it in a

210:42

string now I'm going to console log it's not liking that console log y so

210:51

I'm console logging y as a string we can tell it's a string because it's a different color to these it's a string

210:58

here we know it's a string because it's in these two quotation marks but if I put a

211:03

plus well that changes to a number okay so that's a great

211:10

example of using un plus and finally the exponent

211:15

exponential operator this will calculate the base to the exponent power so once

211:22

again let's get Z this time and get a four

211:27

console log Z so let's make 4 to the^ of two I would

211:34

write 4 to the power of two like so and 4 to the^ of 2 is indeed 16 so that's

211:43

really it I don't want to focus too much on this section because this is just I guess a math lesson something that you

211:49

would have learned at school perhaps just a sort of recap into how you would use it in JavaScript so that was pretty

211:57

Swift if you want to make a note of these please do as mentioned I will be using all of these in the course so you

212:04

will get plenty of practice let's carry on next up we have assignment

212:12

operators an assignment operator assigns a value to its left oper round based on

212:17

the value of its right oper round the simplest assignment operator is essentially this x = 4 I have assigned

212:28

the value of four to X so let's clear that and let's I'm going to put a

212:35

console log down here console log X you will see that X is four so that's

212:42

it in its basic state however the AR a few other assignment operators that I

212:47

want to show you once again there's a lot more but these are the most popular ones so I'm just going to go through

212:53

them with you so we've gone over what assignment

212:58

is what about addition assignment well addition assignment is pretty cool it

213:04

can work like this so I can get X and use plus

213:11

equals 5 okay so let x equal let's start

213:16

off with six what I am saying here is that I am getting six and adding five to

213:23

it however this is not to be confused with this x +

213:31

5 so this wouldn't work we are not assigning anything back to X if we conso log X X is back to thinking it's six

213:39

right so this won't work if you want to essentially write what you would in mathematical sense in JavaScript

213:46

you would need to write this this is essentially the same as writing x = x +

213:55

y so just keep that in mind next we have subtraction assignment

214:01

so I'm just going to clear this for you well it's essentially the same so I'm just going to commment this out at the

214:07

moment X is 6 so we're getting 6 if I get six or X and use minus equal

214:16

five well you guessed it X will be one this is because we assigning x a new

214:21

value after we minus five from it essentially we are doing

214:28

that next up we have the multiplication assignment X multiply equals y or let's

214:38

say 5 will mean that we get 30 once again this is the equivalent of getting

214:44

X and whatever ever X is we are getting it and multiplying it by

214:53

y division assignment is the same we are getting X we're using divide so that is

215:00

divide and we are assigning the new value of x after we've divided it by

215:05

five so once again the meaning of this will look like so remainder so this is

215:13

one of my phase we're going to use modulus equals 5 we get a one because if

215:22

we put 5 into six and R is currently six has a value of six we get a remainder of

215:29

one so once again this is the same as writing that this is simply the short

215:35

hand for it and finally the exponentiation assignment this would be

215:41

x equals say five

215:47

just going to Coma these out so they don't interfere with

215:53

anything let's clear that and we will get the equivalent of

216:00

if we wrote this okay so 6 to the power of

216:08

five great so those are some of the more

216:14

popular assignment operators that you will see when you're working with JavaScript once again we will have

216:20

plenty of time to practice these I just want to show you them for now so make a note of them hopefully you've got it I

216:26

mean the format is pretty much the same for all of these so yeah that's

216:31

assignment operators for you let's move

216:37

on now we're moving on to comparison operators two of which you've already seen that is greater than or equal than

216:45

and I'm going to show you a few more and discuss them in a little bit more detail so let's do

216:51

it a comparison operator operates its operant and returns a logical value

216:57

based on whether the comparison is true the operant can be numerical string

217:03

logical or object values I'm going to show you what I mean by this exactly

217:10

so each of these is essentially going to return a Boolean response or true or

217:15

false so let's start off with the equal so let's go ahead and get our

217:22

console log up again I'm going to get X so let x equal

217:28

and what don't we go with 20 sure why not the numerical value of 20 is now X

217:34

for this session now if I want to check if something so this variable is equal to

217:42

something I would do this I would get X and if x

217:48

equals 20 well we get true let's just clear

217:54

that so we can see it better so we're getting true because X

218:00

we have X here does indeed equal 20 now you may remember me from another lesson

218:06

saying that this does not exist if I wrote that I would essentially be giving X the value 20 and we don't want to do

218:13

that this is an assignment operator now this is how we are writing equals from

218:20

now on so if you want to check this is why it's called comparison operators if we are checking if x equal 20 does it we

218:29

get a true does x equal 21 we get a false okay so we're getting

218:35

Boolean responses now what is also cool about this equal is that we'll pick it up if

218:41

it's a string as well so if I pass through a string

218:46

and pass through a 20 I will get true so that is pretty

218:56

cool okay let's move on not equal so let's get our console log out again I'm

219:02

going to get X which we know has the value 20 and then I'm going to use something called a bang and an equal

219:09

sign okay so this bang essentially means not equal that says not equal and let's

219:16

just put A2 so I get the answer true the Boolean

219:21

of true this is because X which we know has a value 20 does not equal two so

219:27

that is true so we get a true however if I put X does not equal

219:35

20 well we'll get a false because X does equal 20 this is 20 this is 20 so saying

219:42

X does not equal 20 would be false this also works for a string so it will

219:50

pick that up as a string it will know that's still a 20 despite it being a string it will recognize it either way

219:58

and that will also respond with a false deeply equal up next so this is

220:06

very similar to equal let's just get our console log up again and get X which we know has a value of 20 now I could use

220:14

deeply equal so once again let's put 20 so once again our console log will let

220:20

us know that it's true because this statement is true X which we know has the value of 20 does equal

220:27

20 however if I put this as a string we get a false this is because

220:35

unlike equal deeply equal doesn't just need it to be the same value it needs it

220:40

to be the same type as well so we need this to be a

220:46

integer value or a number in order for us to get true on this

220:53

statement okay similarly to straight not equal so

220:59

let's get our console log up again get our X which has the value of 20 and I

221:05

could put bang equal equal so that's a bang equal equal and then let's put

221:11

through a two so again we know that will be true now let's put a

221:19

20 great we were expecting that to be a false so in this case we would get a

221:25

false right because that is recognizing that it is 20 but it's a string so it's

221:31

saying okay fine this is false and then let's ask ourselves does 20 does a numerical value not equal 20 as a string

221:38

value according to this it would be false according to this however

221:45

so let's put this as a string we would get true this is because

221:52

even though our X here is 20 this is 20 as a string so this is not

222:00

recognizing the two values to be the same and we are getting a brilliant response of

222:08

true I appreciate this could be quite confusing the first time you see this

222:14

but don't worry with some practice and me just repeating this to you you will

222:19

eventually get it I really do advise you to be coding along with me and trying these out yourself that is the best way

222:26

to learn learn by doing I'm here to teach you but you really should be doing this on your laptop as

222:33

well okay let's move on greater than so this is one that you would have seen in

222:38

your full loop I'm going to get our console log now we know that the value

222:43

of x is 20 but let's check what our console log thinks so let's get X is X

222:51

bigger than five true it is bigger than five so that

222:57

is how greater than works we can use it to return a Boolean statement based on

223:02

how we compare it to another integer we can also do it for greater or

223:09

equal than so X is greater or equal than

223:18

20 well we will get a true because X does indeed equal 20 however if I did X

223:25

is bigger than 20 we get a false okay because X is not bigger than 20 x is

223:33

equal to 20 once again less than so let's get our

223:38

console log up X is smaller than 20

223:45

false that is because x equals 20 so if I less than or equal to 20 we will get a

223:56

true great okay I think we've

224:02

covered all of these for now I think we're ready to carry on I do

224:10

understand how it can be confusing because we are dealing with a lot of true and falses and booleans and stuff

224:17

that you've learned for the first time so please do take your time with this experiment with the numbers pass

224:22

different things through to your console logs change X go wild I'll see you in

224:27

the next lesson okay now it's time to move on to

224:33

logical operators so let's do it now for this one I thought I would

224:39

show you with an example as it's quite a difficult one to get your head around it is to do with the and so this is the and

224:48

the or and the Not So the bang and for this illustration I've chosen to create

224:55

an array of fruit so we know it's an array because we have these two square

225:01

brackets here and it's assigned to a variable and then in it we have three items we have one string of Apple One

225:08

String of banana and one string of grape now I've written an if statement

225:16

if fruit so we get on array and we use the JavaScript method of

225:22

includes so this is a JavaScript method I did not make this up It Works by us

225:28

putting an item in its parenthesis and if the item exists on the array this

225:36

statement is true okay so this will come back as true as Apple does exist on our

225:43

array and then we are checking if our array also includes banana and only if both are true so if

225:54

this statement is true and if this statement is true then we

226:00

execute this line of code and we get both fruits

226:06

exist okay so that's how and works if this code is true and this code is true

226:15

then we can execute this line of code this is one example of how you would use

226:20

and in code if I however changed this

226:26

statement to let's find a fruit that doesn't exist on it let's put a pair let's clear that

226:35

out so a pair so now this statement is true but this statement is false well

226:52

just okay so now this console log doesn't get shown this code does not get

226:59

executed this is because we need both of these to be true that's what the N does

227:05

it wants both of these to be true in order for us to execute this

227:10

code same as so let's clear this again so say this one is true so let's make

227:15

this apple and let's change this so once

227:21

again it's now it's showing but let's change this to I don't

227:28

know coconut once again this will not show

227:34

this is because we need both these statements to be true in order to show

227:40

this code and that is a great example of the and operator in

227:45

funtion now let's have a look at or so or is essentially these two lines here

227:52

let's talk through the code so here we have the same piece of code however we

227:58

are checking for coconut and we are checking if coconut exists in our fruit array well it doesn't so we know this is

228:05

false this is a false statement however this one is true and

228:11

we are seeing our code that's how or works if at least one of these is true

228:18

then we execute the code if both were false so let's put

228:28

Peach and then let's put

228:34

hair so now you will

228:42

see that this code does not exist execute this is because this is false

228:48

and this is false so we don't execute the code we need at least one of them to

228:53

be true we need one to be true that's what the or is so we need this one or

228:59

this one to be true in order to execute the code and finally let's move on to not so

229:08

not is like the bang that we saw previously by putting a bang here I'm

229:14

ass essentially saying so we know that cherry doesn't exist on our fruit array we can't see it

229:21

so we know that this statement is false if I got rid of this this would be a false

229:27

statement and we wouldn't see anything in the console L because this is false so we don't get any message showing up

229:34

however by putting a bang in front of it it turns it to true and we see the code

229:41

so that is how not works please once again have a good with this yourself it

229:46

is a lot to get your head around I hope this example has made a little bit clearer because I know there's some very

229:52

confusing explanations out there I think doing it with an example is always best

229:59

if you want try also maybe console logging out so this is something that I would find

230:05

useful so I would console log out this and then perhaps the second one too

230:12

just to see what exactly is happening happen in behind the

230:18

hood so we've conso like this one this says false we've conso of this one this

230:23

one's true so we're not going to get the code we need both of them to be true in order to get this code

230:31

okay so there we go just to make it a

230:36

bit clearer perhaps let put first statement let's clear this out a bit

230:45

and then put second statement so yeah you will

230:52

see the first statement is false and the second statement is true we need both to be true in order to see the code so that

231:00

is why it's not working okay I hope that was clear like

231:06

I said please do practice these uh to get your head around them I do have plenty of tutorials on this I will get

231:13

around to sharing them as soon as I can I just need to go through a few other things with you

231:20

first and lastly we have the tary operators so let's check them out the

231:26

Tanner operator is essentially another way of writing an if statement it is a

231:32

little bit more on the advanced side but I do think that I should cover it now however feel free to make a note of it

231:39

and perhaps use it when you're a little bit more comfortable with if statements if statements are great I just want to

231:45

show you a Shand that exists as I would hate to not show you I think this knowledge is important but just know

231:51

that it exists don't worry too much about implementing it for now if you don't want

231:57

to so the Tanner operator allows you to simplify your conditional logic into one

232:04

nice simple oneliner what I mean by this is that I can take one 2 3 4 five lines

232:10

of code and put it into one first off I'm just going to talk to

232:15

you a little bit about what is happening here this is an if statement I have set

232:20

is game over so let's just pretend we're playing a game here uh the game is

232:26

currently not over so game over is false I have set is game over to false I have

232:32

assigned it the value false so if we go to our if statement if is game over

232:39

equals true so the game is over you know you've lost the con log will say sorry

232:45

you lost otherwise we console log carry on

232:51

playing so at the moment game over is false hence we're getting the message carry on playing if I then change it

233:00

to true we get sorry you lost easy now

233:05

let's get to writing this in one liner code thanks to tary operators I would do this like this so

233:17

is game over I'm just going to comment that up

233:23

for now is game over question

233:32

mark If game is over I want to console

233:39

log sorry you lost otherwise

233:44

console

233:52

log carry on playing okay so I'm just going to move this over so we can see it

233:58

all I'm essentially asking so the question mark here is game over okay is

234:05

game over and if it's true sorry you lost

234:10

otherwise carry on playing I can also change it to

234:18

false so now we know that this is false is game over well it's not

234:25

so carry on playing let's change this back to

234:31

true sorry you lost I could essentially also just use

234:39

true or false but it's not really seen to be

234:45

done this way it's usually a variable that has a Boolean value that is used to determine the outcome whether it's this

234:52

one or this one but I just think that's a pretty cool way I really liked hry

234:57

operators I'm just going to put it back there so you can see it I think it's really readable for a developer as well

235:02

you literally asking yourself is the game over well we know it's true so return this otherwise return that once

235:11

again is the game over question mark well yes it is true so return this one

235:18

but if it wasn't we would return that one right there and there we go that's

235:23

tary operators in a nutshell don't worry if you don't want to use them and you're more comfortable

235:29

using IFL statements like I said this is something that perhaps is a bit more advanced so feel free to skip this

235:36

lesson if you

235:41

wish the fist bus challenge is one that is considered to be a favorite for software developers to be interviewed on

235:48

in a tech interview situation it is for this reason that we are going to go

235:53

through it now together based on all we have learned so far in our JavaScript

235:59

portion of the boot camp the fizzbuzz challenge will practice your knowledge

236:05

of if statements loops and operators it is no wonder why this is such a favorite

236:13

on the T scene if you do not manage to finish the

236:18

challenge don't worry that is what I'm here for and we will go through the answer together however please do get

236:26

your laptop out and definitely have a go with me now I'm going to leave you with

236:32

a quick exercise and it's called the Fizz Buzz exercise this is a popular one

236:38

that you will see in a lot of coding interviews so it's one to definitely be aware of the rules of his buzz are as

236:46

follows start with the number one and count upwards if any number is divisible

236:52

by three it is replaced by the word Fizz and any number divisible by five by the

236:57

word Buzz also numbers divisible by 15 become

237:03

fbas using an if statement I want you to have a go at writing this so just to

237:10

help you out if I was to speak out what this if else statement should do I would say something like this if number

237:18

divisible by three console log fiz else

237:23

if number divisible by five console log Buzz else if number divisible by 15

237:31

console log fiz buuz else console log number okay so hopefully that's helped I

237:37

want you to have a go at doing this yourself don't worry if you don't get it we'll go through the answer together

237:49

okay so hopefully you've had a go that if not don't worry let's have a good at writing the solution together so if

237:58

number now I'm going to use something called modulus for this modulus is a mathematical operator that essentially

238:05

allow us to divide a number by any number and if there is no remainder then

238:11

we know that the number is divis visible purely by that number this is something

238:16

that we covered in the previous lesson so please do go ahead and go back if you need that refresher let's go back into

238:23

here if number divisible by three and the remainder deeply equals

238:30

zero console log

238:36

Fizz I'm going to start with off number zero that number equals

238:42

zero else if number

238:50

modulus five DP equals z

238:56

console log

239:03

Buzz else

239:09

if number modulus

239:15

15 deeply equals z so there's no remainder it's divided by 15 and it leaves no

239:21

remainder console log fiz Buzz

239:31

else console log

239:36

number okay so there we go let's start counting one so one 1

239:45

2 3 oops three

239:51

Fizz four a four five buzz and let's

239:56

move on a little bit let's do a 15 15 we're getting a Fizz okay so this

240:02

is a problem as we are passing through 15 and it gets stopped here because 15

240:08

is divisible by five only no remainder so we get a buzz so what we need to do is swap these out so I'm just going to

240:14

put this one up here instead and then put this one at the

240:21

bottom then just put Fizz buzz and have Fizz so let's start again number 15 Fizz

240:28

Buzz good number five Buzz good number three Fizz let's put 30 Fizz Buzz

240:36

fantastic okay this is looking really

240:42

good I'm really pleased with how this went one thing that we can do is

240:47

actually create a full loop to actually print out all the numbers for us which is a great segue as for Loops are up

240:55

next see you in a bit so next up we have for

241:04

Loops for Loops a really neat part of JavaScript that allows us to execute a blocker code as many times as we want

241:12

I'm going to show you how to do this now so a super simple example and the Syntax

241:17

for a for Loop goes like this you start out writing the four and then you need to start with something so we're going

241:23

to declare I let I equals zero because we want to start from zero and then as

241:30

long as I is smaller than so here we essentially import a number I want to

241:37

put in a number that will tell our code how many times we want to execute the

241:42

blocker code so let's go ahead and put 10 semicolon and then i++ so this is the

241:50

Syntax for a for Loop we would then put the code we want to execute right here so I'm just going

241:57

to console log I for now and already bam

242:02

in our console log you will see let's clear that so we can see a little bit better you will see 0 1 2 3 4 5 6 7 8 9

242:14

now you might notice that I have put through 10 here however we are starting

242:19

from zero so this means that we are counting Zer 1 2 3 4 5 6 7 8 9 but we

242:28

have essentially executed something 10 times okay now the great thing about a

242:35

for Loop is that I can essentially print out the same thing or I could customize

242:40

it based on the count so for example example I can have something like and

242:46

then the word beer on

242:53

the wall so we would start

243:01

from zero be on the wall one beer on the wall and so on and so on or I can have I

243:07

plus one just going to clear that one be on the wall two be on the walls three

243:13

four 4 five all the way to 10 beers on the wall beers on the

243:19

wall and there we go that is essentially our for Loop let's move on to talking a

243:25

little bit about for loops with if statements so you might notice here that one beers on the wall doesn't really

243:33

make sense let's change that with what we leared about if statements so in here

243:40

I can essentially do something like this if I =

243:48

1 console log and then I'm just going to console

243:57

log beer on the wall however we don't want one we want

244:03

zero because as you know we are counting from the number zero and then

244:10

else console log BS on the wall let's save that

244:16

refresh and now you will see that if I equals 0 so the first item the first

244:24

time we are looping console log one be on the wall else console log be is on

244:33

the wall so that is one example of how to use for loops with if statements now

244:41

I think you can already guess what I'm going to try I make you do it involves the fizzbuzz challenge and this for Loop

244:50

so similarly to how we got our fizzbuzz game working however we had to manually

244:57

type out the value for number to replace it with 1 2 3 4 I want you to write a

245:04

for Loop that will essentially go through all the numbers of FSB for us printing out the correct words if a

245:11

number that is divisible by 3 5 or 15 is met so I'm going to leave that for you

245:19

here here is our Fizz Buzz challenge again and its answer I want you to write

245:25

a for Loop that will execute this code up to the number 100 have a go at this

245:31

if you don't get it don't worry I'm going to go through the answer

245:41

too okay so let's go through the answer well the first thing that I know is I don't want to declare this number right

245:47

here I'm going to write a for Loop so once again let's get the syntax of the for Loop for let num equal zero so we're

245:58

starting out with the number zero I could keep this as I if you've kept it as I that is fine

246:05

it just means that we need to replace all of these with I2 if I equals z and as long as I

246:13

smaller than 100 increment I by

246:21

One and essentially I can now put all of this code in here however we don't want

246:28

to start at zero let's actually start from one so we can do that either by

246:35

starting from one here and changing that to 101 so there we go we have now done it

246:45

start from the beginning 1 2 3 4 five six let's check for 15 yep and so on all

246:52

the way to 98 99 100 so that is one way that I would do it or if you wanted to

246:59

I'm just going to change this back you could have done I + 1 I + 1 I +

247:10

1 I + 1 and then don't forget to put these so I'm just going

247:19

to make sure that that is red together let's

247:24

refresh and once again one two Fizz four Buzz fizz fizz Bzz Buzz Fizz Buzz all

247:32

the way to 98 99 100 okay well that was fun as I

247:40

mentioned this is quite a popular question that pops up in coding interview so I really would take the

247:46

time out to understand it perhaps do it a few more times to really get to grits with for loops and if

247:53

statements make a note of it otherwise let's carry on now before we move on I want to take

248:00

a moment to talk a little bit more about arrays as we are starting to see them in our for loops and functions so arrays

248:10

the JavaScript array class is a global object that is used in the construction of arrays which are high level list like

248:17

objects what I mean by list like is this so here we have an array I'm going to

248:24

call it books and I'm going to open up my array so this is the Syntax for an array and

248:31

in it I'm going to have a list of books so M dick

248:39

life life of high

248:46

and then sapiens so that is my array of

248:53

books that is it that's as simple as it gets we can also store numbers so let

249:00

count equals 1 2 3 4 we can also store

249:05

booleans so results pass results maybe pass results

249:12

even though I'm not sure you would see something like this you can store booleans too false true true false okay

249:21

so that is three examples of arrays let's use the first one to

249:27

continue now with arrays we can find out the length of an array by simply

249:33

grabbing the array so I've grabbed the array I've grabbed the whole thing and using a JavaScript method of length so

249:41

I've not made this up okay this this is a JavaScript method that will allow us

249:46

to get the length of the array so what do you think it's going to come back with it's console

249:56

log three this is because there are three items in my array now I can also

250:04

do this which is quite cool I can go into my array so I'm going into my array

250:09

and then if I pass through a zero because as we know arrays start from

250:15

zero I will get Moy dick if I pass through a

250:22

one I will get Life of Pi because in my book array is 0 one it's got a one index

250:32

position and then I can always pass through a two I'll get sapiens if I pass

250:37

through three however I will get undefined as there is no fourth item in my array

250:44

I can also add stuff remove stuff to my array but that is something that we'll do in a later lesson for now all you

250:51

need to know is that an array looks like this we can access items from our array

250:57

by index and we can also get the index length we're using a JavaScript method

251:02

of length cool now let's learn a little bit more about loops with arrays so I'm

251:10

going to actually get my books back back let's actually get the books back like

251:16

so let's say we have a lot more books in here so I'm just going to add a few

251:21

more The Hungry

251:28

Caterpillar new Earth and a

251:41

dictionary so there's a a few books in there now say we have a lot more in there and you're working at a shop and

251:48

they want you to find if there is a certain book in your inventory well we

251:53

can use a for Loop to do this I would do so like this so I would grab our for

251:59

Loop once again let I equal zero and then as long as I is smaller than the

252:06

books length so this is where this comes in very handy indeed because we don't

252:12

know how long this say it goes on forever and ever and ever and is always changing it's quite nice to have

252:17

something like this so that this updates no matter how long the book array is and

252:23

then we increment I now

252:30

if books and then we can go into the array

252:35

so what I'm doing by passing an i is I am passing through a zero so I'm going into the books array and getting this

252:41

value and then I'm going into the second item and getting this

252:48

value and so on and so on so I'm just looping over if that value deeply equals

252:55

and let's say we are looking for the book

253:04

sapiens we could just console of

253:11

true Okay so so yes sapiens does exist in our array of books how about another

253:18

book let's try James and the Giant

253:28

Peach and we don't get anything so else console log

253:36

F so now we get a false as that book does not exist we could also do

253:41

something like this so for example say sapients existed not just once but we had a few sapients in

253:49

our inventory so now if books equals

254:04

sapiens count equals count + one and then let's store

254:11

count up here we're not actually going to assign it anything or we could start with zero it's up to us

254:18

else nothing so we can actually get rid of that so

254:24

now just going to console log count actually I'm going to console log count

254:29

here just so you can see what is happening I'm also going to console L

254:36

out each book so you will see here we have three books it's counting there was going one we're adding to the count the

254:41

count is then changed to one one then it's changed to two then it's changed to three and it stopped because we have

254:47

found three books and we have finished our Loop I'm also going to conso log out

254:53

book I I'm going to do it up here so before

254:59

the if statement books I and you will see all

255:05

the books being printed okay so as it's checking it's checking M dick that it

255:11

does not equal SA so we don't add one to the count it's checked Life of Pi that does not equal sapiens so we don't add

255:18

to the count it's checked sapiens it matches so we add one to the count and so on and so on so every time we hit

255:24

sapiens it adds one to the count so that is a great example of a

255:30

real life use case for a for loop with an if statement and working with AAS I'm

255:37

going to show you one last example before we move on

255:44

okay so I'm going to take a quick break before we carry on with array work to talk to you about objects we're going to

255:51

create our first objects in JavaScript so objects objects are essentially the main

255:58

unit in objectoriented programming in this section I'm going to show you how

256:04

to make your first object in order for us to work with it in the next section

256:10

so what I mean by object is this this I'm going to make a cons

256:18

user okay so just like we did with any variable at all I've got our user I

256:24

declared it as a const now instead of just typing straight away here I would

256:30

open up our curly braces to start creating our first

256:37

object now objects work in a key value sort of way so I would get a key for

256:43

example a name some people like to call this a property some people like to call

256:48

it a key it is totally up to you and then we get a value so as you've guessed

256:55

this is going to be my user object and the first property or key has

257:02

the value of Ana so this is the Syntax for writing

257:11

objects you would have the key or property and then have the colon

257:17

followed by the value and then a comma if you want to have another key and

257:22

value so I'm just going to fill this out a little bit more and what else can I

257:28

have I don't know pets dog I don't really have a dog I

257:35

wish I had a dog okay so that is my first object if I didn't have a comma I would get squiggly lines so that is why

257:43

the commas are important this is the Syntax for an object so we've made our first object now I can store anything I

257:50

want in this okay so I can store strings as values I can store booleans as values

257:57

so I can have pets true I do own pets even though sadly it is

258:03

false uh last name is a string integers whatever we want I can even have an

258:08

object within an object but let's not get into that for now so that is my first object now I can actually access

258:17

values by grabbing properties with do notation of my

258:23

object so if I console log my

258:30

object so I'm just going to console log the user because that is what I've stored my object as and here we go I get

258:41

the user name last name and my

258:46

pets okay now what if I just want to access my name my first name I would do

258:53

so by grabbing the property so I'm going to grab that I want the name and then

259:00

using dot name and that's it if I want the last

259:08

name I would get the property of last name to return the value and once again

259:16

that'ss false so that's quite

259:21

cool however I can also have an array of objects okay that is where accessing

259:30

things get us a little bit more complicated but let's cover that in the next

259:36

lesson okay let's look at these objects this time in arrays let's carry on so so

259:43

here we have an array this array is different to the ones you've seen before it is still an array however it's an

259:49

array of three objects what I mean by objects is this that is one object that

259:57

is a second object and this is a thir in my object which I'm going to think of as

260:04

a user object I have a username of the user with a string the follower count

260:12

with an integer and then a Boolean value for if that user is followed or

260:18

not okay so once again we know it's an array because we open up these square brackets and then we have three items in

260:25

it they're just a little bit more complicated we have an array of three objects rather than three strings or

260:32

three integers or three Boolean values however we're going to treat it exactly the same so just a little bit of a heads

260:41

up before we start start working with this array we can still access values in the array so I'm just going to console

260:48

log I'm going to move up a bit I'm going to console log our users because it's called

260:57

users and if I conso log the first user you get the full object okay so if I

261:06

open it out a bit you get the username the followers count and it is followed and it is mode 24

261:13

four so that is looking correct now if I then want to access let's say just the

261:19

username or just the follow account or just that is followed I would get the

261:27

key so the key of username so now I get the string

261:34

Mo 244 if I just get the key of followers I

261:39

will get the value of 34 and if I do is followed I will get the

261:47

value which is a Boolean of false great let's carry

261:54

on now I want to write an if now I want to write a for Loop that

261:59

will send you Loop over all my users and only send them a message if we follow

262:06

them so if is followed is true how do you think we would do

262:11

this pause here and have a think about it and I'll see you in a

262:19

bit okay so this is how you would solve it we would of course start off with writing the Syntax for our for Loop so

262:26

let I equals z and as long as I is smaller than the users length so once

262:33

again I am getting the users array I'm getting this and I'm getting

262:39

its length so we know that this value value will be the integer of three as

262:44

there are three users and we increment I by one now

262:51

if users and then I'm looping over user remember so I'm looping of I'm going to

262:57

the first one the second one and the third one so I could just replace it with

263:03

I if that uses is followed deeply equals true

263:14

well then we send them a message what

263:21

hi long time no speak and then if it is false well we do

263:29

nothing so let's hit save and great I'm just going to clear

263:36

that so we followed two users because is followed is true for Angela and is

263:42

followed the true for sexy work so we should see the console log message printed twice and that is correct hi

263:50

long time no speak if we really want to personalize this we could do something like that so

263:56

hi users once again we go into the first object and get the

264:07

username plus long time

264:13

speak so there we go hi Angela

264:18

Buu long time no speak hi sexy Rick 21 long time no speak so this is quite an

264:25

interesting example as I'm pretty sure this is on the basis of what some of the LinkedIn scrapers do when they

264:31

essentially take your first name and then send you a message or an add request so it's quite useful to show you

264:38

this example I hope that was helpful I hope you're really learning more and more about you know for loops with

264:45

arrays and if statements I think we're now ready to carry on okay so we made it

264:52

quite far into the introduction part of our JavaScript course we've covered variables if statements objects but we

264:59

haven't really talked in depth about functions we've seen a function sure but

265:05

we really haven't gotten to grips with what exactly the best practices are how to pass parameters and what exactly a

265:12

function is so let's do that now so as a reminder we have seen a

265:19

function already we used it before the Syntax for a function looks a little bit

265:24

like this we would get the word function to let our IDE know that we want to

265:30

write a function we would then choose a name of our choice to call this function

265:36

so for example I'm going to choose to say send text

265:43

so I've chosen to call my function send text the function is doing something

265:50

it's going to send a text hence we have written it this way most functions

265:55

usually start with uh send get any word that indicates doing something so send

266:01

text is perfect we will then open up our parenthesis and then get our cly braces

266:07

and write our block of code that we want to execute when we we call the

266:15

function like so okay so this is standard this is your standard

266:22

function now when choosing a name that you want to call your function make sure

266:28

that it is in camel case what I mean by this is that the first word starts with

266:33

a small letter and the second starts with a capital letter and so on and so on this is for readability for your

266:42

fellow developers so that they can read your code a lot better it's considered best practice and I agree I I tend to

266:49

quite like this this kind of format so make a note of that Camel case

266:57

for naming functions and this is just a best

267:03

practice it won't break your code or anything but you know it's good to have

267:12

okay so we have our function here now we want to essentially execute something so

267:18

I've been using console log a lot that's because we haven't actually started working with the browser yet I'm just going to use console log again here I'm

267:26

going to try not to use it from now on but for now I'm just going to write console

267:31

log and let's send a text saying

267:39

hey Bobby do you want to hang

267:47

out so now when we call our function or when we execute our function or invoke

267:53

our function whatever you want to say we get the message in our console log that says hey Bobby do you want to hang out

268:00

without calling it nothing happens however with calling

268:06

it we get the code to execute we've already discussed Global

268:14

variables so I can actually put a global variable up here that says Bobby or the

268:20

string Bobby and take Bobby out here so I'm going to close off the

268:26

string add the variable of

268:31

name and I've essentially replaced Bobby here in the sentence with

268:38

a variable of name so now I can easily change the name up

268:44

here so there you go Danny Amy whatever you

268:51

like great now you might be wondering what these parentheses are for they are for

268:58

passing through parameters into your function so instead of declaring a

269:04

global variable here I can essentially reuse my function and then pass through

269:12

the parameter of name so let's pass through Bobby so I passed through Bobby

269:20

into my function I passed through the string of Bobby into my function so I've

269:25

essentially passed through a name that I then want to appear here and there we go

269:33

so this approach is useful as it allows us to check this out reuse code so now

269:41

if if I go like that I can literally write Bobby

269:47

Dany Amy I don't know faroq and I can essentially reuse this

269:54

to message all these people just by passing through their name into the function so that is pretty cool I'm

270:00

spamming people to find out if they want to hang out with me and I could repeat this over and over again reusing this

270:06

code so that is pretty awesome that is a great example of why functions are so useful F they are

270:13

reusable so now I've shown you an example of how to reuse a function but also how to pass parameters into a

270:20

function to I can pass not just one parameter but two parameters so I can

270:26

pass through a time which means I can spam people and ask them to hang out with me at different times so there we

270:35

go I'm just going to pause through different times hey name do you want to hang out at

270:42

and then let's put the time

270:50

here and close that off again so it's

270:56

correct and there we go I've sent messages to Bobby asking him to hang out

271:01

at 10 Danny to hang out at eight Amy to hang out at five and a for ruk to hang

271:07

out at 1 simply by reusing this function and passing through to

271:15

parameters okay I'm going to ask you to actually have a go at this again by

271:21

yourself so I'm just going to clear

271:26

this let's write a function and this function I want

271:32

to send reminder okay so once again this is the

271:38

Syntax for a function send reminder I am writing the function so I'm telling

271:44

my IDE that this is a function I've named it send reminder and this is the Syntax for a function and then I am

271:51

calling the function here I want you to pause here and have a

271:56

go at sending a reminder using the console log to four people that their

272:02

meeting is at X time so just like we did before but just have a go at doing this

272:09

yourself I'm going to pause here while you have a go at doing this don't worry if you don't get it I'm going to go

272:15

through the answer with you soon okay so hopefully you've had a go

272:22

at that if you haven't don't worry I'm going to go through the answer with you now so what do we want our message to be

272:30

well we want our message to be dear

272:36

name so plus name

272:41

your meeting is at and then let's do

272:48

time okay so once again let's actually pass through a name here so

272:57

Freddy and then three let's also send a reminder to so

273:05

[Music] Danny Olivia Hana

273:12

Freddy Danny at four Olivia at five and Hannah at six Okay so we've done that

273:20

and the last thing we to do is actually pass through the variable so I can name

273:25

this whatever I want I can name this glob it really doesn't matter it's just

273:30

saying that whatever the first thing that we pass through is is what I want

273:36

that to be in here okay so there we go that will work too obviously if we put

273:43

the time in so if I put three here well it would read de 3 you have a

273:50

meeting your meeting is at your meeting is at Freddy and that would make sense

273:57

so the order of which you pass these through at is super

274:02

important let's just change that back for you okay I'm also going to change this B because that doesn't make

274:09

sense and there we go feel free to make a note of this otherwise if you're

274:17

comfortable with functions let's carry on with some more

274:22

examples okay so I'm just going to get rid of that let's clear

274:30

this I just want to show you one more thing about passing through parameters

274:35

so we can have Global variables so let's just write another function let's make

274:40

it show alert and then once again let's call our

274:47

function here I'm going to write name console

274:57

log name you or let's just say wake

275:09

up now we can have Global variable so let name equals Ana in which case we

275:17

don't need to pass through the name into here or here okay this is a global

275:23

variable and no matter how many times I invoke or qu the function it will just

275:29

use Ana as the name okay this is great as it allows us to

275:36

store things in our file as well so I'm just going to invoke it once

275:44

I could do something like this Ana wake up this is

275:54

your count

276:02

alarm so this is very much like most of my mornings I have multiple alarms now

276:08

I'm going to put let count up here I'm going to start off as

276:14

zero or actually let's start off as one so the first time that I call this

276:19

function I get a message say an your wake up this is your one alarm maybe

276:27

alarm number that makes more sense this is

276:33

alarm number one and I could actually put afterwards

276:42

count plus equals 1 so

276:48

now if I call the function once so let's get rid of that and call the function

276:55

and you wake up this is alarm number one I call the function again and you wake up this is alarm number two again and so

277:03

on and so on and so on and so on so this time we are not passing through a

277:09

different variable into each function however I am using the function to

277:14

essentially add to my count which is a global variable okay so each time I'm

277:19

executing this function I am adding to a global variable which is the count okay

277:26

so I've executed this functions three times so our count is three as you can

277:31

see here our count is three so that is just another example of

277:39

how you can use functions so so I am invoking the function in order to update

277:44

a global variable okay let's move

277:52

on okay now it's time for a little exercise so I hope you're excited it's

277:57

going to use everything that we learned so far about functions in order to move something on the browser so as I

278:04

promised I'm finally going to introduce some browser work we're not just going to be using the console log from now on

278:10

so let's do it okay so here we have a function a

278:17

function here is called move Bob and instead of Simply calling the function

278:24

I've attached our function to an element

278:29

that we have taken from our HTML and I've added an event listener to it don't

278:35

worry if this seems like a lot I'm going to talk you through everything now our goal by the end of this exercise is to

278:42

move Bob to the right you can see that's where he's looking every time we click

278:48

his face okay so I'm just going to talk you through this a little bit

278:54

now up here I'm essentially using document and query selector so I have

279:01

not made these up okay these are ways of essentially picking out so I'm getting

279:07

my HTML document and I'm using query selector this is a JavaScript method

279:13

that will allow me to look in my HTML and look for the class name indicated by

279:19

this dot right here I'm looking for the class name of face and I'm then storing that element as Bob for our Javascript

279:28

file so if we go into here if we look into our HTML I'm essentially looking

279:36

for this div with a class of face that has all these other div Liv inside of it

279:42

okay so if I select the diff face it's going to take the face but it's also going to take both eyes and the pupils

279:49

too I have styled them up for you it's nothing too crazy it's just some simple

279:55

circles essentially that make up my face so that's how we do it I am storing

280:03

the element with a class of face as Bob next I'm getting that element so

280:10

here's Bob I'm getting that element and I'm using a JavaScript method of add

280:15

event listener to listen out for any

280:21

time we click so once again I've not made this up this is a set thing that we

280:26

pass into event listener there's many many more click is just one of them I could do hover I can do so many so it's

280:34

going to listen out to anytime we click on the element with the class name of

280:40

face or in other words Bob as we have sted for this file and if we do click on

280:47

the div or the class of face or Bob then we execute or call the function

280:55

move Bob okay don't worry if this is a lot

281:00

essentially all you need to do is write the function Bob in order for us to move Bob to the

281:07

right okay now what do you think you should do in order to move B to the

281:12

right it has something to do with storing a global variable okay you will also have to get

281:21

the style of Bob and move him to the left so this is something that I would

281:27

suggest you have a pause at here go do some research I'm going to leave this up

281:33

for you here okay so have a look at that if you want to have a look at the index

281:40

HTML all I've done is added that in so I'm going to

281:45

make this bigger so you can see in case you want to take it I'm going to put all of these in the description below so you

281:52

can have a go with them yourselves too okay so that is in

281:58

my index HTML that's all I've done I've put in the face with all these divs feel

282:06

free to copy that I have then linked my style sheet and and then styled it

282:14

up okay so here is the style sheet just in case you want to take it please feel

282:19

free I am going to also include this code in the description but if you just want to take it down now here is what I

282:26

have in my style sheet so I've styled the body with a background color I've

282:31

also got the face I've given a position absolute this is going to be important

282:36

because we need to know exactly where the face is on our screen we're going to have the background color

282:43

and then I made it a circle so the face is a circle thanks to the height the width and the Border radius and I've

282:49

also given it some margin left on top next we have the eye container so this

282:55

is to hold the two eyes and make them display in line instead of stacked over

283:00

each other as is the default for divs and then next up I have the eye

283:06

itself which is a white circle with some margin and the pupils to okay so that is

283:13

the sty sheet let's go back to our index

283:22

JS okay I'm just going to minimize that for now and give us plenty of room for Bob to move so this is a great exercise

283:31

for Googling because there will be some Googling involved in this as a reminder

283:37

for this exercise we are going to be practice what we learned with functions so you will be storing a global variable

283:43

however there will be one aspect that you need to Google and that is how to essentially style an element so the div

283:51

with the class of face using our JavaScript okay so that is a clue I'm

283:57

going to leave you here don't worry this is quite a tough exercise considering you're new and you've never worked like

284:03

this before I really wanted to throw you on the deep end with this because don't worry I'm obviously here I'm going to

284:09

show you the solution in a so let's pause here have a go at doing this yourself hopefully find some

284:16

interesting Solutions online and I'll see you

284:25

soon okay so let's go through the solution well first off let's just start

284:31

out by console logging that's what I would do let's just go say

284:36

hi so now to check that everything's working correctly if I click on the

284:48

face just open that up okay yeah I get a console log that

284:55

says hi so let's go ahead and click that again some reason it's not working very well I think you need to view it in the

285:01

browser so let's go ahead and inspect get our console log up and great

285:09

so every time you click on the face you will get a high so our function

285:16

is working this is looking great it seems to be working here now too the next thing I want to do is

285:22

actually just move Bob so I'm going to move Bob Bob and then I would use

285:29

something called style and then left so by writing style I'm essentially saying

285:36

that I want to access the styling of Bob and I want to add something to the

285:42

property of left so if I just go ahead and write 100 pixels as a

285:49

string that is essentially the same as me going in here and writing left 100 pixels okay so

285:58

that is the same but I'm doing it from JavaScript so now let's go ahead and

286:05

save that if I click on Bob let's go ahead and do that in here

286:12

click on Bob what he's moved 100 pixels to the right see there we

286:20

go that seems to be working however I do want Bob to keep moving 100 pixels each

286:27

time we click him for this we're going to have to use our Global

286:33

variable so once again not sure why it's not working in here oh there we go so it's moved 100 pixels there we go 100

286:40

pixels so now let's actually declare a variable so let's declare let

286:51

count I'm going to put zero now each time we click Bob's

286:59

face I want to get the count and I'm going to use

287:05

our plus equals operator to add let's say 50 okay so now instead of passing

287:15

through 100 I'm going to pass through count plus pixels so now if I console

287:23

log

287:28

count refresh the page here we go 50 so I've got 50 my

287:34

count is 50 so I'm adding 50 to the left click again 100 that means I'm adding

287:40

100 to Bob's left 150 200 and so on all the way to Bob goes by Bob Bob goes off

287:48

our screen okay so that is a great example of how a global variable can let

287:56

us accumulate a value in a

288:03

function there we go once again we've done it okay so I hope that was useful

288:10

for you you I hope you enjoyed working with a browser a little bit more and not just using a console log I'll see you in

288:18

the next section okay now before we move on I just want to show you something extra

288:24

about functions I wouldn't worry about it too much for now just understand what we have learned with functions but I do

288:30

think it's important to show you this example because you might hear about it while you're learning and I don't want

288:36

you to get confused okay so here we have a function

288:42

what I have done here is essentially use document and query selector query selector and documents are things that I

288:48

did not make up this is a JavaScript method that will look for the body so

288:54

I'm literally looking for the body element and saving it as body now I've

289:00

written a function that is called speak so I've chosen to call it speak I have

289:06

told our document this is a function and I have chosen for our console log to

289:12

print greetings okay so that's all our function is doing now down here I have

289:18

taken the body so I've taken literally the body of our browser here and added

289:25

another JavaScript method of add event listener now I've passed through click

289:31

once again I have not made this up this is something that the event listener takes and then the function speak so now

289:39

this means that each time I click the

289:44

body just refresh that I will get greetings pop up in our console log this

289:50

is because we clicked the body and because we clicked the body our event

289:57

listeners listening out for this and invokes or calls the function speak okay

290:04

so that is what is happening here don't worry too much about it for now I just explain this for you because I want to

290:09

show you how you can write functions another way or how you might see functions

290:16

written so this is just the standard function that we're going to be working with for this course however it is

290:22

important to know that I can also write a function as a function expression what

290:27

this means is I would store it as a con so I say con

290:32

speak and then use function here I'm not going to pass through

290:38

anything because we're not passing through anything to work with and then I

290:43

would say console log greetings okay I'm just showing you

290:49

this in case you see it written this way this way is fine too it's just not the way that we're going to be using for

290:55

this course I don't really see many people write uh functions this way but hey it's important for you to know so

291:02

let's check it out let's click the body and yeah everything is working

291:08

fine now a way that is more and one that I like to use uh

291:13

occasionally is using the function expression but with an arrow function

291:19

what this means is that instead of writing function like so I would get rid

291:25

of the word function and then simply put an arrow function here okay so that is just a

291:33

another way of writing function it's just syntax if you like it go ahead and use it but like I said I would recommend

291:40

sticking to this that is what we're going to be using in this course this is perhaps maybe you see it in a bit more

291:46

advanced project but it's still valid okay so this is a function expression

291:52

using an arrow function now the reason that this is

291:57

changed is just simply because this is how functions have evolved with time people like to you know make things

292:03

shorter and shorter as we uh can see in many of our daily situations so this is

292:09

just uh an example of that okay that's all I wanted to tell you for this course

292:15

like I said please do keep using this I just wanted to show you that for now now

292:22

I'm going to talk about the while loop which is different to the for Loop and I'm going to tell you why the while loop essentially Loops

292:29

through a blocker code as long as the specified condition is true what I mean

292:35

by this is this so while this is the syntax so it's similar to an if

292:41

statement while this in here is true we

292:47

execute this so I'm just going to put

292:53

beers on the wall again and then I'm going to put I

293:02

here okay now I'm going to use some of the stuff that we discussed before so I

293:08

am going to get let I equal

293:14

Zer now while I is smaller than

293:21

100 okay so as long as I is smaller than 100 so we already know this is true

293:27

while that is true print out I BS on the wall so you already see some stuff happening here it's going crazy I mean

293:34

it's already counting a lot because it's not stopping I is constantly zero and

293:40

that's that's what it's executing it's executing we need to really stop this otherwise okay yeah we've reached an infinite Loop

293:47

so if I is smaller than 100 print out

293:52

zero beers on the wall but also get I an increment by one okay which means that

293:59

by the time this is run I is no longer zero it's now one one is smaller than 100 True print out one be on the wall

294:06

and then increment again so let's see this in action now let's refresh the

294:15

page so I just had to restart my ID as that infinite Loop broke everything but

294:23

there we go okay so now as long as I is smaller than 100 print out beers on

294:31

the wall and the number and there we go all the way to 99

294:37

beers on the world as you know we start from zero oh

294:42

cool okay so that is just a another sort of cool way to Loop using the while loop

294:50

so as long as this statement is true execute this block of code over and over

294:56

and over again until it is not true anymore okay so say it with me while

295:04

lets you execute a blocker code as long as a statement is true and it will do it

295:10

over and over and over until the statement is not true

295:16

anymore and there we have it ladies and gentlemen the while

295:24

loop okay now it's come to that time in the tutorial I want to talk to you about

295:29

builtin objects JavaScript has built-in objects date math string array an object

295:39

each of these so each of these five have special purpose properties and methods

295:45

associated with it this is the funnest part about JavaScript I think it really

295:50

allows us to be creative with our arrays strings and so on so I can't wait to

295:56

show you what I mean by what I've just said let's do this with some examples

296:02

okay so here we have a JavaScript property that we can use on a string or

296:09

an array and it is length you would have seen it before when we were doing the

296:14

for Loop we used it to figure out exactly how long our array is but you

296:19

can also use length on strings so I'm just going to show you what I mean by

296:25

this let's get a con word and let's make our word be

296:32

banana if I conso log the word well of course we'll get banana but if I add the

296:40

property of length to my variable well I will get six this is because banana has

296:48

1 2 3 4 5 six letters okay so that is a very basic way

296:56

in which you can use length to figure out the length of a

297:01

string a much more interesting way and a way that is used a lot more frequently in JavaScript is using it to find out

297:09

the length of an array so obviously I can do something like this const fruit

297:18

equals banana apple so I'm just putting strings in here

297:25

pair and then if I console

297:30

log fruit just like we did with a string you will get the array with three items or

297:39

three strings strs in it and if I use the property of length well you will get

297:46

the number three because we have three items in our array this is great for if

297:52

you're not sure how long an array is maybe it's got like thousands of thousands of things in it or perhaps

297:58

it's constantly changing okay so a great example of this is the for Loop where

298:04

you want them to iterate for each time there is something in an array so before

298:09

we move on on I just want to show you something that tripped me up when I was learning when I started working with uh

298:16

the browser and perhaps picking out elements this really tripped me up and it wasn't until a while later that I

298:23

realized some JavaScript uh inbuilt things already have length as a property

298:29

so I'm going to show you this example I think it's pretty useful so I've also gone ahead and

298:36

created some UI for us to work with so I'm just going to clear this out now

298:42

what I have done here in this example is created a UI that essentially has three

298:47

BS or to be more precise three divs with

298:52

a class of ball and then I have styled them up in order to look like this and use

299:00

justify content and display Flex to make them appear in line rather than stacked

299:06

over each other as is the default for divs so so now say I want to get all my

299:12

balls so all the dis or the class of ball so I can work with them in my

299:18

JavaScript well once again I would use document query selector but this time

299:24

all okay so once again I have not made this up this is something that comes with JavaScript document so we are

299:31

looking into our index HTML and then we are looking and selecting all the divs

299:38

with the class name so we need to make sure that dot is there because we are looking for a class name if we didn't

299:44

have it there well that wouldn't work we need to look for the class name of

299:49

bull and then I'm storing it as Bulls okay so now if I

299:57

console log balls so when we console log balls

300:04

you'll see a node list show up okay so here is our node list I'm just going to

300:10

expand that so we can see it a little bit better and in our no list we have the

300:15

first div second div and third div we also have a property of length so node

300:23

list may look like an array but it's not okay don't treat it as an array I just

300:28

want to show you this outlier example of how we can also access the

300:36

length of a node list because it exists as property so that is just something

300:41

that I want to draw your attention to even though length can be used on strings and arrays there are many

300:48

outliers such as the one I showed you I'm showing you this as it really confused me when I first started so I

300:54

thought I'd get in there quickly and just explain that JavaScript is quite flexible we've just used length on a

301:01

node list which is not an array or a string we are able to do this because

301:08

the node list has a length property okay I think I've covered

301:14

length enough for us to move on please do pause here and please have a go at

301:19

creating your own examples perhaps have a go at you know recreating this have a

301:25

pause here have a go or if not hey let's carry on next up we have

301:33

concat the concat method is US Toge two or more things we're going to look at

301:39

around rays and strings together so let's go ahead and do that now let's

301:46

look at a string for our first example so I'm just going to get a string

301:54

const word and then I'm going to

302:00

say cheese and then const

302:07

name Ana so we have two words here now what if I

302:14

want to essentially put both of these words together so I'm just going to put say cheese Ania so it's not essentially

302:22

one word now it's a sentence but we are still joining two strings together okay so if there's any confusion one string

302:29

and then second string if you want let's actually just call this string and then

302:35

string two just so we're super clear about what we're doing we are joining

302:41

together two strings so now I'm going to get my console log out and then I'm

302:46

going to get the first string I'm going to use concat so once

302:52

again this is a JavaScript method I am not making concat up let's open up our

302:59

parentheses and now I'm going to pass through string

303:06

two so there we go I have joined into the two strings together to make one

303:13

string that says say cheese an so that is our example with

303:20

strings let's have a look about how this works with

303:26

arays with the ray is pretty similar but I'm just going to type it out for you so you can see now the important thing to

303:33

know when we use this method on arrays is that this method does not change the

303:38

existing arrays but instead returns a completely new array okay so just keep

303:44

that in mind I'll show you what I mean let's get array one and let's say array

303:50

one is I let's use integers this time so our first array is an array of 1 2 three

303:59

values and then our second array so array 2 it's going to be 4 5 6 so we're

304:07

essentially counting to six but it's split in two arrays so once again let's get our

304:13

console log out I would get the first

304:19

array I just spell it right array one and then I would use concat the method

304:24

of concat which I am not making up this is a JavaScript method and I would pass

304:31

through array two and what does that return well it

304:37

returns a new array with all of our numbers in it okay so I'm actually going

304:44

to store this as something const new

304:50

array I'm just going to store it here so you see what I mean by the fact that we

304:56

are not changing any of the arrays at all we've created a new array because if

305:01

I conso log out array one well you will see this array right here if I console

305:07

log out array to once again again you will see that array still exists we have not mutated these in any way and if I

305:16

conso log out new array well you guessed it we got a new array which uses both of

305:22

these arrays great so that is another thing that you

305:28

might want to make note of this method does not change the existing

305:37

arrays it returns a

305:45

new allay cool now we can also concat strings with

305:53

indiges strings with booleans that is completely up to us concat is not going

305:59

to you know discriminate against any of that so go ahead we can also do

306:04

something like this so let's just make a third array array three

306:10

7 8 9 and then by passing through array

306:16

three we are essentially join together all three of the

306:24

arrays okay so it is quite flexible I hope that was useful once

306:30

again please do have a go at writing these Yourself by building that muscle memory is the only way you'll really get

306:36

to grips with learning these JavaScript methods

306:41

okay so I just wanted to talk to you about the join JavaScript method let's get to

306:47

it the join a JavaScript method creates and returns a new string so I'm just

306:53

going to say returns a new string because I think that's important for you

306:58

guys to Remember by concatenating all of the elements in an array okay so not like

307:06

concat it is going to literally take everything in on array and join it together so for this I've actually gone

307:14

ahead and used document and query selector I did not make these up this is

307:19

a JavaScript method that will allow us to search for the div or element with

307:25

the class so we've got a DOT here so we know we are searching for a class name

307:30

of text so essentially we are searching for this div with a class name of text

307:37

so we're going to search for any element with a class name of text and we're going to store it as a const that I have

307:44

chosen to call text display okay so that is how we would get

307:52

that div and then I would grab the text display and use a JavaScript property of

307:59

inner HTML so once again I'm not making this up to assign whatever we want so

308:04

let's just go ahead and write test and there we go you will see the

308:10

string text show up in my div which is in this orange

308:16

body okay now let's use join on an array to try test it out I just want to show

308:21

you how you can use the join JavaScript method and for this I'm just going to

308:26

make another array let's go ahead and call it

308:32

emotions so I'm going to make an emotions array so instead of saying the word text I just want to use emotions

308:38

there so whatever we we type in here should show up in our text display make

308:44

sure that this is at the bottom because obviously we will read this first and then whatever is in our emotions we

308:50

assign to the inner HTML of the text display which is an element with a class

308:55

name of text so I'm just going to put happy there we go happy let's put

309:04

sad and let's put confident I think that's an emotion

309:10

so at the moment we have these three elements in our array they are strings

309:17

so we've got three strings in our array now I can use join to literally

309:23

just Bunch them all up together and make them appear as one word so I could do this easily let's get

309:30

our emotions once again make sure to put it above here emotions and then use join

309:40

like so so you might not be able to tell but if we actually console log

309:47

emotions you will see that is just one long string okay that is opposed to what

309:53

we were getting before so if I just get the emotions that is an array with three

309:59

elements that are strings inside it and once again let's use join and there we go one string so we

310:07

can join up all all of our strings like that if I want to get rid of the commas

310:14

I could do that too so there we go by passing through an

310:21

empty string I'm essentially getting rid of the commas in between so that is also

310:28

quite cool essentially what I am passing through here if I do pass through anything at all will replace the comma

310:35

so because I passed through an empty string it's been a comma has been replaced by nothing I can also replace

310:41

it with that or the number two or three

310:47

or it doesn't matter okay so by leaving an empty string you essentially

310:52

replacing a comma with nothing to get one word that says happy sad

310:58

confident okay now I did say this returns a new string so it won't work if

311:03

I just got emotions and you join on it okay that will not work you will see

311:08

that has not work worked I am not getting all three words as one I would need to store this because this returns

311:14

something okay it like gives something back so we need to catch it and store it something else so const new

311:22

word equals and then I just replace this with new word we've called it back and we

311:30

have assigned it to the inner HTML so once again I can just put that here too

311:36

all numbers it is up to

311:42

me so that is how I would use the JavaScript method of join I hope you can

311:47

see how it's different from concat it is totally up to you when you would like to use each one I think it just depends on

311:55

the problem you are currently trying to solve I hope this has helped so I hope by showing you both you'll be able to

312:01

make that choice eventually okay let's move

312:06

on in this next section I want to f focus on the JavaScript method of

312:12

Pop the pop JavaScript method essentially removes the last element

312:18

from any array and returns that element for this I have already pre-made a

312:25

cinema board for us so we can see some cinema names in our browser and so that

312:31

I can show you the pop JavaScript method in action before we get going I'm just going to explain a little bit about what

312:38

is happening here here so essentially I have made this using HTML and CSS to

312:45

look like a cinema board similar to what you would see if you're going to watch a movie at the cinema I have then picked

312:51

out this lighter red square using document query selector so

312:59

I am not making this up document and query selector query selector is a

313:05

JavaScript method that will essentially look into our HTM ml document and look

313:11

for a element with the class name we know it's a class because of the dot of

313:18

display so let's go in here and you will see a div with a class name of

313:25

display that is style to be like Coral so we know this is the element that we

313:30

mean so I am finding that using query selector and I'm storing it as display

313:38

for us to use in our Javascript

313:43

file okay so let's think of some movies cons movies equal and then let's open up

313:50

an array because we're going to use pop on that array and the movies I want to put in

313:57

are Argo

314:02

aliens and fear so there we have our three movies

314:10

in an array we know it's an array because we open up these square brackets and we have three elements which are

314:17

three strings in our array which we have stored as

314:23

movies if I console log out

314:29

movies and get our console log up you will see we get them back here we don't

314:36

want the console L for Nows I'm just going to put it down okay now let's actually get to putting

314:42

the movies into our display so I'm going to use display so I'm literally grabbing

314:48

this so we're grabbing the light Coral

314:54

Square this is actually a JavaScript property so using inner HTML I'm going

315:01

to set the inner HTML of my div to be the

315:07

movies okay so we can now see the movies in our

315:12

browser so it's going to be easier for us to put pop into action now say I want

315:19

to just remove the last movie from our

315:24

list well I could do this super easily I need to do it above the inner HTML so

315:30

before we assign the movies to our display so I'm going to do it up here I'm going to grab my movies I'm

315:37

going to use pop like so and there you go you will see I

315:43

have now taken this array and essentially removed the last item from

315:50

our array now it is important to know that the pop method changes the length

315:58

of the array okay we're not creating a new one we have changed this array at

316:06

the moment this might not mean much to you but as soon as we start looking at other JavaScript methods for arrays this

316:13

will make a lot more sense for now just remember or make note in your notepad

316:18

that pop changes the length of the array it does not create a new

316:23

one we can essentially do this on whatever we like so I'm just going to delete that for now so we' got all

316:32

three of them back now say I instead of had three strings I had three objects I'm just

316:39

going to create three objects there's one object second object third object you can see one

316:46

object two object three object and in my object I have name Argo it's the name of the

316:54

movie and then length let's just say I don't know how long it is but let's just say it's 136

317:02

minutes same for this one so name aliens

317:09

and let's say the length of the film is 2011

317:15

minutes and name Fe and this one can

317:22

be 1 to 4 minutes so now I have an array

317:28

of three objects movie objects if I console log that out you will see my

317:34

three objects so let's click into the first one as our first object second object third

317:44

object now if I console at Movies there's three objects so as we can see here I'm just

317:51

going to select that and shut it down and if I take the movies and go

317:56

pop and then I console log movies

318:03

again you will see I only have two objects so once again pop works on an

318:08

array no matter what is in the array it can be a string it could be an object it could be a number it will simply get rid

318:16

of the last element in your array so yep as you can see we have this object and

318:22

this object this one has been removed so the last one has been removed thanks to

318:29

pop great okay I'm just going to delete this for

318:37

now now I want to show you the opposite of pop and that is shift let's do that

318:44

in the next section in this section we're going to talk about the shift JavaScript method

318:50

that removes the first element from an array let's do it now in this section

318:57

we're going to look at the shift JavaScript method and how to use it to remove the first element from an array

319:04

using this method we'll remove that item and return the removed element as well

319:10

it is also important to know so make a note of this that this method changes

319:16

the length of an array this might not mean

319:21

much to you now but when we start looking at other JavaScript methods this will make a lot more sense okay so just

319:28

remember that shift will change the length of the original

319:33

array let's get up some movies again so this time

319:39

let's get the movies Good

319:47

Fellas wolf and juman

319:53

G now just like we did in the lesson before I'm going to take the display so

319:59

I'm grabbing the display which is essentially this light Coral Square so

320:05

I'm grabbing it using the document and query s these I did not make up and I am

320:11

searching for the div with the class name so dot for class name of display so

320:17

I'm grabbing that here and using a JavaScript property in a

320:24

HTML I'm just going to whack in my movies array that's a bit too long let's

320:29

change the first one to be another film so I'm just going to go with

320:36

clue there we go now this it okay so this time I don't want to remove the

320:42

last item from my array so I don't want to move jamanji I want to remove clue I

320:49

could do so so once again make sure to do above here because whatever we have above here will be put in the displays

320:56

in a HTML would grab the movies array and just use shift on it like this okay

321:03

so now you'll see that clue has been removed from my array so that's all we

321:09

can see in our display I could also do this with numbers so for

321:16

example just going to make another array const count equal and then 1 2 3 4 five

321:26

so now if I got the count and used shift on it what do you expect would happen if

321:34

I spelled shift correctly well I would expect that the one would disappear let's check that out

321:42

let's assign it to the inner HTML of our display and there we go so our

321:49

array has been taken here and we have taken off the first item from our array

321:55

and then we have put it in the display we have changed the array we

322:02

have changed its length next up I want to talk to you about another JavaScript

322:07

method on arrays and that is unshift I'll see you in the next

322:12

section in this next section we're going to be talking about unshift the JavaScript method that adds one or more

322:20

elements to the beginning of an array and returns a new array so let's do it

322:27

okay so as mentioned the unshift method adds one or more element to the beginning of an array it is also worth

322:35

noting that this will change so this will

322:42

change the array it will change the original array that we are working on

322:48

this might not mean much to you now but once you start looking at other JavaScript methods on arrays this will

322:53

make a lot more sense we are going to be changing the original array so once again let's get a const up

323:02

this time let's pretend we aren't in a movie theater maybe a play theater so

323:07

const play and let's think of some plays so I'm

323:13

just going to put one for now I'm going to put [Music]

323:20

Hamilton and then I'm going to get the display so here we have

323:27

selected the cor light Coral Square so we can use it in our JavaScript and I'm

323:33

going to use a JavaScript property of inner HTML and to it I'm going to assign the

323:40

place so at the moment we just see Hamilton Hamilton is the only play that

323:45

is playing our our theater I want to add some more but I want to add them to the beginning of this array okay I want to

323:51

add them here I could do this with the unshift method so for example to do this I would

323:58

grab the plays so I'm grabbing this original plays array I would then use

324:05

unshift so I'm not making this up this is a JavaScript method and in here I would

324:14

pass through let's pass through another play

324:19

Wicked so now you will see that I have added another element to the beginning

324:25

of my array okay so that is how you would use unshift in a very basic

324:32

form I can also add more than one element to the beginning so let's add another one what's another player that

324:39

we can add let's add in cats and there we have it we have now

324:45

added two new element to the beginning of our original array and if I was a

324:53

console log out plays well I guess we can see here that we have three this is not the same as our original array we

325:01

have changed the original array so if I console log out plays it should show me

325:08

me exactly what we see up here and that is wicked cats and Hamilton we have three items in our array

325:18

fantastic let's get rid of the console log next up I want to talk to you a little bit more about the JavaScript

325:25

method of push on a race I'll see you in the next

325:32

lesson in this section I'm going to talk to you about the push JavaScript method and how it adds one or more elements to

325:39

the end of an array let's do it so the push JavaScript method adds one or more

325:46

elements to the end of an array and Returns the new length of the array so

325:52

this is similar to the unshift method but we are going to be adding elements

325:58

to the end of an array rather than to the beginning so once again we are

326:04

grabbing the display so I'm essentially grabbing the div with a class name so dot for class

326:11

name class name of display from our HTML and that is this Coral box right

326:19

here let's make a const so this time let's do actors

326:26

names const actors and once again I'm just going to have a simple array of

326:32

strings so let's have Brad Pit

326:39

now I'm going to get my display so I'm going to get this element here and using

326:44

a JavaScript property of inner HTML I'm going to just assign the array of axes

326:51

to it so we can see it okay so at the moment we only have one actor being

326:58

displayed in our display inner HTML we only have one actor in our

327:04

actors's array I want to change this array to essentially add two more actors

327:10

to the end of it so I will do this by grabbing the original actors

327:16

array using push okay I'm not making this up this is a JavaScript method and

327:24

by just passing through another actor's name so let's put Rihanna even though

327:30

she more of a singer but she's done a few films I have now added another actor

327:36

another element in to our original array so now we have two items in our original

327:44

array we have changed so this

327:50

changes the original array please do remember that please

327:57

make a note of it just like the others this will become more apparent when you look at other JavaScript methods that

328:03

work on arays okay and just with the unshift we

328:08

can add as many elements as we want so I'm just going to add in I don't know who's got a short name that we can put

328:14

in here I'm going to put CIA even though once again not really not really an actress and let's just put

328:21

BR and there we go so now we have three actors SL singers in our array we have

328:31

changed the original array so that is how push works I hope you can see how

328:38

it's similar to unshift I have one last one that is similar in the way these

328:44

work which works with adding or taking away items from an array and this one

328:49

will deal with if we want to you know add or subtract anything from the middle of our array because at the moment we've

328:55

just looked at the beginning or end let's have a look at the middle this up in the next

329:01

lesson next up we're going to look at slice the slice JavaScript method

329:08

essentially allows us to remove certain parts of an array now it is important

329:13

that it does not mutate the arrays it produces new ones so unlike the ones

329:19

previously this will not change the original array okay so it does not

329:29

mutate arrays it

329:34

produces new on that is important please make not of it this is not like pop

329:40

shift unshift and push it will not change the array it will produce a new

329:47

one so what I mean by this is this once

329:52

again let's make an array so const artists and I'm going to make array of

329:58

artist so let's use

330:04

Shakira Snoop and

330:11

seea let's also say Beyonce and then let's put one more

330:18

in Swift Taylor

330:26

Swift okay so that is my array of artists now say I just want

330:33

to take out Snoop from my list okay because they' all be women so let's do

330:40

that let's get the artist array now I'm going to use slice and to

330:47

use slice you can pass through two things so you can pass through a start

330:52

and an end right so a start index and an end

331:00

index I'm going to show you what I mean by this the star index if I wanted to

331:06

take out Snoop which would be 01 so I'm just going to console log this

331:12

to see what is happening here and then I would pass through a

331:19

two so now I have taken out just Snoop

331:26

this is what I mean that it does not mutate the array the array here is the same I've essentially taken out just

331:32

Snoop so now I can store just Snoop or something so may

331:39

artists and even though there's just one now in here I don't know why it's so

331:44

female heavy but you know that's just the way I did it male

331:49

artists artists Slice on to so now we've

331:55

stored Snoop as a male artist I'm just going to cost male artist so now if I console

332:04

log mail artists I will get Snoop and if I console blog

332:14

artists well the array will be the same we have not changed the

332:20

array so what happens for example I'm just going to clear this out so we can start

332:26

again if I wanted to remove every artist that doesn't start with the letter s

332:32

well that would mean removing the last two artists

332:39

so const not s

332:44

artists please do bear in mind that this is not how you would search for Strings

332:50

that start with the letter s we are just using a static array for this example

332:55

that doesn't change okay we are just giving examples how to work with slice you are not literally search for you

333:03

know strings starting with the letter s this way if we however want to remove

333:09

the last two items of any array no matter what is in the array it does not matter what is in the array we are

333:14

removing the last two we would do it this way and I would do so by grabbing

333:20

the artist's array and then using slice and I can actually just pass through one

333:26

0 1 2 3 oops

333:32

three so now if I console log not s

333:39

ists I would get Beyonce and Swift I don't need to pass

333:46

through a end so as we mentioned we pass through a

333:51

start and an end I don't need to pass through an end because we just want to continue to the end of the array so

333:57

anything from index 3 onwards will get taken off and saved as not s

334:06

artists okay okay hopefully that makes sense just for syntax purposes the

334:12

Syntax for using slice would be array so whatever array we want the JavaScript method of slice so I did not make this

334:19

up and we would pass through a start and an end that's pretty much it make sure

334:26

these are indexes so as if you're starting from Z 1 2 3

334:32

4 great so we have our artists Now using

334:37

what we learned how do you think that I would put in the first three so I just want to display the first three artists

334:44

in my display have a think about

334:52

it well I'm going to store them con as const s

334:58

artists and then I would get the artists I would use slice and pause through zero

335:04

and 0 1 2 3 as we want to stop after the third so here 0 1 2 3 we don't want

335:13

anything past that and then I would get the display use inner HTML so the property

335:21

of inner HTML oops in a HTML like that equals and then s

335:31

artists and there we have it we have Shakira Snoop and sea playing at our

335:37

very exclusive theater that only allows artists to start with us to play weird I

335:43

know let's actually change it to a small s just to be on the side of best

335:52

practice next up we have the JavaScript method of

335:57

splice so the splice JavaScript method changes the content of an array by

336:04

removing or replacing existing elements and and or adding new elements in its

336:11

place okay don't worry if you didn't understand any of that I'm going to show you what I mean now now let's make a

336:19

array I'm going to call it movies so what kind of mov should we

336:26

have let's have Elf Annie and let's have Hero 6

336:38

okay I'm just going to put these movies in our display so I would do this by grabbing the display okay I'm grabbing

336:46

this I'm going to use inner HT HTML to essentially assign the content of this

336:53

array to the inner HTML of the display so I would do so by just grabbing the

336:59

array like so and there we go we get elf Annie and

337:05

hero six so array is essentially showing up in the inner HTML of our display now

337:11

what if I want to remove Annie I could do so with splice what I would do is

337:18

essentially grab the movies array use the splice method so I'm not making this

337:24

up I'm using it on my array and because I want to remove Annie

337:31

well I would pass through a one this is because Annie is in the 01

337:37

first position or index one in my array so if I pass through a one well you'll

337:43

see that Annie and her have been removed but if I pass through a one again you

337:49

will see that Annie is the only one being removed okay so that is how splice

337:58

works I've just removed the item in the array with index number one I can

338:06

actually also add add another parameter to this so I want to replace Annie with

338:11

something else I'm going to replace Annie with

338:18

Mulan and I can do that like so okay let's try a different example

338:26

okay let's do something else just so you get used to using splice so back at our normal array that's the one we are

338:32

starting with now I'm going to get rid of hero and replace it with something

338:39

else so I would do this by finding out where hero 6 is in our array it is the 0

338:46

one two it's the second index so two that would remove hero so I could just

338:52

essentially pass through a two if I wanted and then

339:01

add but then if I try to add hook so I'm just going to add

339:08

hook you will see that will not work okay this is because we need to pass

339:13

through a second parameter this is essentially a third parameter but we're reading it as a second we can replace

339:20

things by the third parameter so for this to work I would have to put in a two just like

339:28

that now what if I didn't want to replace hero six with hook I simply just

339:33

wanted to add hook into my array here so let's do that again well if I wanted to

339:40

add hook here it would be in the second index and then I just want to add hook

339:47

so I would actually just use a zero so there we go obviously it's not

339:53

fitting on one line I'm just going to delete that for it to work I would just pass through a zero into my splice

340:02

method this is because I want to remove zero elements before index 2 okay so I'm

340:08

removing zero elements before index 2 so nothing's changing I'm just simply

340:14

inputting hook into my array I think the best way to think about it is like this

340:21

so let spliced array equal and then we

340:27

get our array and we use splice and then we pass through the

340:34

first parameter which is the start index so just as we before if I wanted to

340:41

replace Annie I would go 01 so I'd po one that is the start index so I go like

340:48

that and then our second parameter is the delete count and it's the delete

340:54

count from the start so if I wanted to then delete any I would go 01 and I

341:00

would delete any however if I didn't want to delete anything at all I just

341:05

wanted to input a element like we did with hook I would put through a zero and

341:11

then after that we would put through the item that we want to replace so for example hook so once again that is the

341:20

start index that we passed through the delete count and then the

341:28

replacement okay so I'm just going to move this out the way so you can read it if you ever need to think about it

341:34

that is the Syntax for splicing in an

341:40

array start delete count replacement okay let's carry

341:46

on next up we have the for each JavaScript method let's do

341:54

it the for each JavaScript method executes a provided function once for

342:00

every array element what I mean by this is that if I decide to change example

342:07

all of these pink flowers yellow backgrounds to Red I could do this in a

342:13

single line of code I'm going to show you how now so first off let's actually get the

342:22

yellow circles in an array so we can work with them I'm going to do this by

342:27

grabbing them first so let's go to document and prary selector all this

342:34

time so I am not making this up wey selector all will essentially look for

342:42

any class name so dot means class name class of circle in our index HTML

342:50

document okay so what we are doing is going in here and looking for any div with the class name of CLE so this one

342:58

this one and this one we need to use all because we are looking for more than one

343:04

and now let's save them as something so I'm going to go const circles because we

343:09

have three so it makes sense to use the word circles so now if I console

343:15

log circles you will see a node list so you

343:22

might remember that node lists aren't particularly arrays okay it's a node list but we can

343:29

treat them similarly for for each so we have our first Circle our second Circle

343:34

and our third circle just going to get rid of that so that is what is stored in our const

343:42

cyclus okay so this is the Syntax for for each we have the

343:48

array and then we go for each and then we open up our

343:53

parenthesis and in here we can call this whatever we want okay it's just the

343:59

first item of the array so it's hypothetical it's made up I can call it

344:04

X and for each item or X in our array I'm going to do something right so

344:14

that is how it would look I'm going to show you this with our actual array so

344:19

it makes more sense but just remember that's the syntax So based on that syntax is what I

344:25

would do I would grab our array in this case node list to be

344:30

precise and then I would use for each open up our parenthesis now for

344:37

each item in our circles node list or whatever array we are working with I

344:45

can I'm just going to get call it Circle instead of X okay so right so for each circle in my

344:55

circles I want to change it to Red so I would use style once again I'm not

345:02

making this up style background color this is something that we did in the previous

345:09

lesson so I am essentially adding a background color to the style of circle

345:15

we have this color right here but I want to change it in my JavaScript by writing that and let's just change it to

345:23

Red amazing so we have now done that I'm just going to minimize this for you so

345:30

once again for each we get an array or a node list we can do a node list too and

345:37

we use four each and then for each item so we can call I can call this glob it really won make a difference it will

345:43

still work it's literally whatever we want to call it and for every item in

345:49

our circles I change it to Red okay so that is one example of how

345:56

to use four each let's go back to bases and just do it for a normal array using a console

346:03

log so if you want to write that down actually make a note of that that that is how you would change each of these to

346:11

a different color please feel free to have a go this yourself pause here if you need to pause longer I'm going to

346:18

carry on just going to get rid of this so let's do another example let's

346:26

make an array so const names

346:31

equals Ania Bob

346:39

B and then

346:44

Melanie so that is an array of names now if I was to get the names and

346:51

for each name okay so for each name once again I

346:58

could call this I don't know dog if I wanted to it really

347:04

doesn't matter it just means for every item in array let's change it back to name

347:10

though because it makes more sense than dog and then if I just want to console

347:16

log out each name individually rather than there's an array I would do

347:25

this so let's get our console log and there we go we've actually done

347:31

a mistake here because it's saying that this is one Element so one two well done

347:38

for anyone that spotted that let's actually fix that and there we go Anna

347:44

bobie Melanie we are printing out each item of an array so each name as we

347:50

chose to call it in our console

347:56

log I'm just going to do one more example and that is with numbers so

348:01

const numbers let's say we have actually let's make it more realistic const scores so

348:09

here we have an array of random scores here we

348:15

go and then it turns out that the person and count of the scores forgot to add

348:21

two points to everyone at the beginning so all of the scores in our array no matter how long the array I mean it

348:27

could literally be like really long you don't know how long it goes let just make it go over our vision so we can

348:34

pretend that we don't know how long the array is using for each I can add plus two to

348:40

each of these numbers so scores for each so for each score whatever we want to

348:47

choose to call it we can call it I we can call it score for each

348:55

score let's just use console log again so we can see it I want to

349:03

add two to each score as we print it out so as you can see

349:09

here let's just look to the beginning going to clear that out so it's easier to read we can also if we want to do

349:17

more things or just have one line of code use kly braces like

349:24

this so that would be the correct syntax with the for each it will work the same

349:30

so you will see here

349:38

then we have added two to each of the scores so 32 1 to 34 5 43 1 2 5 4 five

349:46

and so on and so on and so on

349:51

okay just format that a little bit better and we have finished Okay so we've covered using

349:59

four each four elements in our browser we've covered it for Strings and we've

350:05

covered it for working with integer in arrays too the four each method is very

350:11

powerful it is considered to be a loop just like the four Loop so it's very similar to that it's just your

350:17

preference as to when you'd like to use each one and if it's more suitable for a

350:22

certain problem let's carry on in this lesson we're going to talk about the

350:28

JavaScript method of sum for this lesson I'm going to start off with some simple examples of some

350:35

first and and then end with a more complicated example just to show you the difference between a basic example and

350:43

how you might use some in an actual real life project so let's get to the basic

350:48

examples first the sum JavaScript method tests whether at least one element in an array

350:55

passes the test implemented by provided function so what I mean by this is let's

351:01

get an array and let's call it scores and our score is going to be 23

351:08

56 76 and 59 out of 100 now I want to

351:14

check whether some scores are above 50 okay and if some scores are about 50

351:21

well then let's just say we pass the test okay so these are our overall scores for the year if at least one of

351:27

them is 50 or above 50 I pass that's the sort of score I go to so let's do it now I'm going to

351:38

essentially console log it out so we can see I'm going to get these

351:45

scores so scores my array of scores I'm use the JavaScript method of

351:51

sum so I have not made this up this exists it's a JavaScript method and for

351:57

each score if that score is bigger than

352:04

50 okay well we get are true this is because two of our scores are bigger

352:11

than 50 so now if I change this to be lower than

352:17

50 we get a false this is because none of the scores are above 50 so scores sum

352:25

some of the scores above 50 no false that's how we would read that line okay

352:33

so that is a very basic example of how we would use sum so just remember with sum we are checking if any of the

352:42

elements in our array meet a certain Rule and if any even one even just one

352:48

meet that rule we get the Boolean of true otherwise we get a

352:54

false let's try again so I'm going to some write something else just so you

353:00

get a better understanding of some

353:05

const countries let's get some countries up

353:14

so [Music] Afghanistan

353:19

[Music] Poland South

353:25

America okay so we have an array of three countries now countries

353:32

some country so once again this is very similar to for each this is the

353:39

syntax so I can call this whatever I want I can call this glob and I can call

353:44

this glob essentially it doesn't matter we are just giving this a value so we can check for each item in our array and

353:53

if glob an arrow function for this as well so if glob so for each glob or country

354:00

let's actually change it back country and if each country is we check

354:06

each country and if any other the country deeply equal

354:12

Poland then we want this to return true so we're just finding out if Poland

354:18

exists on our array so console

354:24

log that and we indeed do get true so that is how some works with strings for

354:33

example so we are getting the array then we use some to check if some of the

354:40

elements in our array match our Rule and if some do even one then we return a

354:48

true however let's put another country that is not an array

354:54

Russia then we get a false because Russia is not in our countes

355:00

array great so that is how some works with a basic example I'm not going to

355:06

show you more complicated example to show you how you might use some in a actual real life project don't worry if

355:13

this is a bit too much for you I just want to show you in case it comes up I do use this example in my Tetris

355:20

tutorial so if you want to have a go at that please do make a note of this it will definitely help you understand what

355:26

I'm doing in that walkthrough okay so here we have I'm

355:32

just going to clear this up for us here we have three hearts I have a hole in

355:37

one of the hearts so if you see here I have one div that has a heart but it

355:43

also has a child div in it that has a class of hole which is this black thing

355:48

right here and then another heart and another heart so what I have done is essentially in my JavaScript picked out

355:55

each div the class of heart so if I console log out Hearts

356:02

because we took them all we searched for them in our document we search for them by class name and the word heart so the

356:10

class of heart we use Query selector all and document to do this once again I did

356:15

not make these up this is a JavaScript method and if I console log heart I get

356:22

a node list of these three parts the first one of course having a child div

356:29

inside now unlike before I'm actually going to create an array out of this so I can use another JavaScript method

356:36

called array from which will essentially make an

356:42

array of the divs for me so now it's gone from being a node list to an array

356:49

see one HTML div element another another we have an array ladies and

356:56

gentlemen great so that is what I get back when I cons loog Hearts so now if I

357:02

get my hearts array I want to write something thing that says if there is a hole in any of

357:09

my hearts I am heartbroken so Hearts sum I'm going to

357:16

store this as const is heart broken

357:23

equals heart sum and then for each heart so I am checking in my array of div

357:32

elements for each heart for each div with a class of heart I'm checking if

357:37

that div has child nodes so there's another thing that I'm not making up is

357:43

a JavaScript method that's going to help us check if the heart has

357:49

any child nodes so now if I console

357:56

log is hot broken I get true this is because there

358:03

is indeed a hole in one of my hearts hearts or precisely if I was to talk

358:08

about this in programming languages one of my hearts does have a child element

358:14

inside it okay so that is how I would do it if I was to then get rid of this hole

358:20

so I'm just going to go ahead and get rid of that

358:27

here go back here and once again delete that and console log is

358:33

heartbroken I get false this because I now don't have any child ndes in any of

358:41

my hearts so that is just one uh example of a slightly more complicated way that

358:47

you could use some of the JavaScript method of

358:52

some great I hope that made sense please do write this down and have a go at this

358:58

if you want um once again it is simply just

359:03

checking if any of my heart divs have a child div I could even

359:09

just have it blank and it would pick it up as that is technically a child to the

359:15

parent div but you know because we want to see it I'm just going to give it a class of

359:20

hole which I previously made here okay it's just a simple black

359:30

hole and there we go okay I hope that made sense I hope you've learned a

359:36

little bit more about Su uh we will be using this in projects to really build your muscle memory so don't worry if you

359:43

didn't get it so much this time hopefully it should be a lot clearer by the end of this

359:48

course now I want to take a little bit of time to talk about the map JavaScript

359:54

method okay so the first thing you need to know about the map JavaScript method is that it is quite similar into the

360:01

four each however it creates a new new

360:07

array okay so what I mean by this is that it takes an array and for every

360:13

item or element in the array it will apply a function to it or some

360:18

functionality and then create a new array from it this is unlike for each in

360:25

which if you remember or if you want to have a look back we were just printing out the result each time sort of like a

360:31

loop this will literally create a new array for us but enough chat let me get to showing you with code so the Syntax

360:39

for map looks a little bit like this we have an array and then we use map so

360:45

once again I am not making this up this is a JavaScript method and then we map

360:52

to each item in our values array so for each

360:57

value like so and whatever we do here will affect the value we then have to

361:03

store it as a new array of values okay

361:09

so that is the syntax let's get to actually using it in a real life code

361:17

example so for this I'm actually going to use integers for this I think it will be the easiest to see this with integer

361:24

values I'm going to make an array of pages so this is the ages of everyone in

361:32

my house got 21 I don't actually I don't live with this many people but you know

361:38

it's for the sake of the tutorial so let's just assume I live let's have a young person there too uh in a house

361:45

with six people from the age ranges of 2 to 56 now this was the last time I counted

361:52

everyone's ages it's been 3 years on exactly from now and everyone's aged 3

361:57

years so I need to add three years to everyone in my array but I don't just

362:04

want to console l out I actually want to store this in a new array okay so we can

362:10

say ages it's 3 years ago from now

362:17

2018 and con ages 20 21 so this is what we want we want con

362:23

ages 2021 so I would get the ages from 2018 I would use map and as we said

362:29

remember values array for each value in my array so I'm going to go with age for

362:35

each each age in my array get an arrow function up and for each age I want to

362:41

add three years so now the console log ages

362:51

2021 there we go I get an array with all the ages updated by 3 years so that is

363:00

my household's ages in 2021 so that is a simple example of how

363:07

to use map remember it does different from for each because it creates a new

363:13

array have a go at doing map again if you want have a go at doing this one

363:18

just make sure you know the difference it's super super important okay let's try this out again

363:26

this time I'm going to use objects so to do this let's create an

363:31

array of object this time I'm going to say housem

363:38

and then let's open up an array so we know it's array because we have these two square brackets and in it let's have

363:44

our first housemate our second housemate let's just have three housemates this

363:49

time so I'm just going to do the same that we did before but this time working with objects so I'm going to have the

363:56

name of my first housemate his name is

364:01

Ahmed and his age is going to be 24 so you will see I'm using a string for

364:07

Ahmed and an integer for the age our next housemate is going to be

364:14

Ellen and she's going to be

364:20

35 and then we have

364:26

Woody and his age is going to be 30 so here's my three housemates okay each

364:34

housemate is essentially an OB object with a name and an age now I'm going to do this again so

364:41

housemate 2018 I want us to essentially create a

364:49

new array of just their ages and making sure these ages are up to date so 3

364:54

years later in 2021 so we need to add plus three to each age now based on what we did before

365:03

how do you think we would do this just have a pause here think about it

365:08

remember the syntax that I Told You So map would work with values we get our

365:14

values array and then we map out for each value use aror function and value so that is

365:21

the syntax and don't forget this creates a new array so I need to store this as

365:28

values to so that's just a separate name okay hopefully you've had a go at

365:36

this or at least thinking about how we would do this I'm going to show you the solution now so once again we would get

365:43

our old array housemates 2018 and use map okay so for each housemate this time

365:52

we get the housemate because that is the first item as a housemate or the first

365:58

object as a housemate and for each housemate's age

366:06

we add to so now if I console Log House makes

366:14

2021 let's have a

366:19

look we have indeed added two to each age and return that as

366:27

an array okay so we have got the ages CU for each age we added two and

366:35

that's what we are storing in housemates

366:41

2021 okay great that was a little bit more of a complicated example of how to do it with objects I hope that made a

366:48

lot of sense I'm not going to do anything with the Dom for this one as I don't really feel we need to um but

366:55

again if you want to please do practice this please do search online for more

367:00

examples if you need I will be using map in some of my tutorials so once we get a

367:06

hang of a few more things we will be doing them as well so don't worry you'll have plenty of opportunity to practice

367:12

the map JavaScript method okay great I'll see you in the next

367:18

lesson in this next section we are going to be talking about the filter JavaScript method and how it's

367:27

used so first off it is important to explain that the filter JavaScript method is used for you guess it

367:34

filtering the method essentially creates a new array so make a note that creates a new

367:42

array with all the elements that pass the test implemented by the provided

367:47

function so what I mean by this is we're going to write some code and if our array passes the rules in the code we're

367:54

going to create a new array with those values okay and then we're going to

368:00

stick it in here so for this example I'm going to start off with an array of of shows I've

368:07

put in some shows that I'm already into so lupan kraai 24 and Mr Robot we're

368:15

going to use filter on this array first off to find out which of these show names is less than five characters so we

368:23

can put it in this box right here and it fits perfectly and then we're going to do some more filter work this time with

368:29

objects and arrays so I'm just going to show you the simplest way of using filter and how I would do this is I

368:38

would grab the shows array and then we said that we want to only filter out any

368:45

string that is less than five characters in length Okay so let's do that we can

368:51

easily filter out every single show name that is less than five characters or

368:56

equal to five characters by getting the shows array using filter so I did not

369:01

make this up filter is a JavaScript method

369:07

and then similarly to four each we would grab the word so I can call this

369:13

whatever I want okay I can call this

369:18

I I can call this puppy it's totally up to you this

369:26

is essentially a syntax that essentially means for every element in our

369:32

array I'm actually just going to change that back to to word and for every

369:38

word we're going to check the length of the word and if the length of the word

369:44

equals or so smaller than that is smaller

369:49

because this has to be smaller than five and then we want to store this in

369:55

something because as you remember filter creates a new array so let's go ahead and store that in

370:01

display shows as we are going to be displaying them later on so we have now

370:07

stored this new array in something let's see if that has worked so console

370:14

log display shows let's get our console log out and

370:21

great we now have a new array that has stored all the elements in our array

370:27

that are either equal to five or less than five in length by length I just

370:34

mean the character count that is how you would use length on a single string if

370:42

you remember back to our previous lessons so that is how you would use filter that is a very basic example of

370:49

how to use filter for example I could have equal to five and then I would just

370:56

get lupah I could have greater than five

371:02

and then I'd get cobai and Mr Robot and I can do a lot more other

371:07

things so that is just one example before we go on I am just going to show it in our display so once again how do

371:16

we do this well if we have a look at our index HTML you will see that the display

371:23

is what we need to get so the class of display because that is that element right here you will see that it is

371:30

styled to be pale Violet red so let's grab our

371:37

display we're going to go into the

371:44

document we're going to go into the document search for it using query

371:50

selector we did not make that up that's a JavaScript method and search for the class of display and let's store this as

372:00

const display or if we want we can

372:05

save it as show display it is up to us

372:11

what we save this as and then we will get the show display and use inner HTML so the

372:19

property of inner HTML I did not make this up and just assign it the display

372:28

shows and there we go there they are if we want to start

372:33

this up a little bit let's just change the font size and let's make it 50

372:42

pixels so there's our three shows

372:48

okay let's move on now say instead of an

372:54

array we had an array of objects so I'm just going to console log this out so

373:00

you can keep it there in case you need it and of course we don't have any shows

373:07

for now so I'm just going to comment this out too say we had so I'm going to do shows again however this time is

373:13

going to be array of objects so there's one object there's another object and each object is going to be a show object

373:21

so this is a more realistic way of how you might see this in uh a working

373:27

environment so you'd have your object it's going to have the name

373:34

Lupa we're going to have series well I know it's got one series I'm going to go

373:39

one integer episodes total five okay and then I

373:46

could do the same for all the others so

373:52

Cobra Kai it's third series and let's say in total it has 20 episodes or 30 episodes

373:59

I'm not exactly sure but we don't need to be accurate for this and then let's put

374:06

24 once again I really can't remember how many series this has so I'm just going to be making these up and the last

374:15

one is Mr Robot three and let's put

374:22

24 okay so now instead of just working with a simple array like that I have a much

374:29

more complicated piece of data to work with but we can definitely still use filter on on it so I want you to display

374:38

the shows that have over two Series in the making how do you think you would do

374:47

this I want you to have a pause here and think about it before you move on so

374:53

feel free to get out your code editor have a mess around all you need for this

374:58

is to get something like that and then use filter on this array in order to

375:05

find all the objects or all the shows

375:10

that have series of over two so it would be these three that you need to store in

375:15

a new array okay I'll see you in a bit

375:39

okay so the way I would do it is this let's go here I would grab the shows

375:45

array I would get the filter JavaScript method let's open up and we know that

375:50

the syntax would be this show show because each of these is a

375:56

show one show two shows once again we can call it whatever we want but for the

376:01

sake of readability I've called it show now for each

376:07

show well I can't just do length I need to get the shows series and check if it is larger

376:17

than two and if it is we want to store it in a new array so let's just call it

376:26

display shows again so now if we console

376:31

log display

376:39

shows I would indeed only get three objects back so Cobra

376:46

Kai 24 and Mr Robot okay great that is

376:52

how we would do it that is the solution to using

376:58

filter I think we're ready to carry on

377:06

in this section I want to talk to you about the reduce JavaScript method let's

377:12

do it the reduced JavaScript method executes a reducer function on each

377:19

element of the array resulting in a single output value what I mean by this

377:24

is we can use it to essentially add up loads of numbers together okay so that

377:30

is how the reducer works we add up loads of numbers for example if I get an array

377:36

of numbers so const scores and I want to figure out what my final score is so I'm

377:43

just going to put some numbers in here like so I would get the scores

377:51

array get the reduce JavaScript method and this is the Syntax for writing a

377:56

reducer okay so you have accumulator you have an accumulator

378:05

and the current value let's just put that in

378:11

actual parenthesis themselves and then

378:17

accumulator plus current value so that is the syntax of writing a reducer just

378:23

going to comma that out so we can keep it at all times we have something that will accumulate and the current element

378:31

being processed in the array so if I show you this with with actual code I'm

378:36

going to use reduce and then the accumulator and then I'm just going to

378:42

put through the exact code that we see

378:48

above and let's store it as

378:53

total now if we console log total we can actually get rid of this because we

378:59

don't need this actually we do we need the console log you will see 21 so this

379:06

is just syntax you can of course change these to whatever you want for more readability for example I might choose

379:13

to have the accumulator be called total score and then the current value

379:21

so whatever is being processed is just a score so I'm just going to put score either way the total will be the

379:29

same because 5 + 3 is 8 + 6 is 14 and

379:37

then we add 7 which is 21 we can do this on whatever we want so

379:45

1 2 3 4 that will give us a four essentially if you use this syntax so

379:51

that here you can get the total of any array of numbers okay so make sure to

379:58

write that down it's just syntax you just need to remember it make a note okay now I'm going to actually

380:05

delete this and I want you to try adding these

380:12

numbers together so based on what you have learned so far you can of course

380:19

what's it not liking there comma um you can of course refer back to the previous lesson or if you've made a

380:26

note I want you to have a go writing this in your own code editor okay I want

380:32

you to add all the numbers

380:39

together please have a go at doing this yourself once again feel free to Google

380:45

feel free to go back on your previous lesson just just have a go okay I'll see

380:50

you in a

381:02

bit okay so hopefully got that once again we would grab the array and we use the reduce JavaScript method so once

381:09

again we are not making this up and let's get our syntax so we need one thing here and one thing there I can

381:16

call it X and Y but I really would not recommend that no one knows what X and Y is it's not very readable it doesn't

381:22

help out other developers reading your code and then I would simply put

381:28

X+ Y and score this let's store this as total

381:35

and it's console log total and there we go we get the total

381:42

of these four numbers if we want to check if this works let's make something easier so 1 2 3 4 and indeed we get

381:51

A4 so as I mentioned I really wouldn't call this X and Y I've just done it this

381:56

way so you can see that it really doesn't matter what we put at these two values and what we put

382:03

here but this this is how I would name it

382:08

total and score so we're talking about each individual score and it's

382:14

accumulating onto here each time okay it's going bam add add add add until we

382:19

get a total so there we go that is the reduce JavaScript

382:27

method in this next section I want to talk to you about the every JavaScript method let's do it

382:36

the every JavaScript method tests whether all elements in the array pass the tests implemented by the provided

382:43

function it returns a Broan value so what I mean by this if everything in our

382:51

array matches a rule or a statement return

382:58

true otherwise return false so I'm going to do it once again with

383:05

the scores cons scores equal and then let's have some

383:15

scores there we go I think that's enough we have an array of scores

383:22

now well let's put something else let's put test results sure let's pretend we are a teacher in a classroom and we have

383:29

some test results now someone has asked us to check if all of our students have

383:35

received over 30% okay we just want to know if the students have got over 30% well I could

383:44

do this with every I would do it like this so let's get our array so test

383:53

results and then use every and then check so I'm going to get

384:00

the test results I'm going to get result once again I'm calling this ever I want

384:05

and for each result I need to check that it is larger than 30 okay so that's how

384:15

we would do it once again I can call this whatever I want it really doesn't matter I can call it I I can call it X

384:23

it just means for every item in our array so for the sake of readability I'm

384:29

going to call it result and let's console log this to see what we get so we should get a Boolean

384:37

of true because all our results are indeed over 30 so I know I've put this

384:44

in a console log but another option is to actually save this as something so if I saw this as

384:52

const class pass has class pass has

384:58

class past equal so if I console log

385:06

class or maybe just class pass true that makes more sense readability wise

385:11

console or class past true however if I put one of you to 26 we get a false this

385:18

is because not every one of our items in the array matches this rule

385:27

okay so that is how every Works once

385:32

again I'm going to ask you to do it yourself so make a note of this because this is going in a second this

385:39

essentially is the syntax so this bit right here on an

385:44

array and boom there it goes okay so in this example I'm going

385:52

to make a new array I'm going to say const

385:58

array animals and then I'm going to have a cat

386:04

not C cat a rat a

386:10

dog a mouse and that's it so that is my array

386:16

of animals I want you to tell me if all the animals in our array if all the

386:23

animals length so the length of the string is equal to three so equal to

386:30

three right so you need to write a line of code that will essentially give us a

386:35

true or false value based on this rule okay so

386:42

write code that will return true or

386:50

false if every string in the

386:56

array is equal 2 three in

387:02

length okay so once again I'm going to leave you to it please have a go at this

387:08

yourself and I'll see you in a

387:21

bit okay so the way I would do it is this I would grab my animals array I

387:26

would use every and then I'm going to pass through an animal for each animal

387:35

[Music] anal each animal length so this is a

387:40

property that we used before dly equals 3 and then let's store the answer or

387:47

let's just console log it for now we get a false this is because Mouse

387:56

is five characters long if we however change this to ant then we will get a

388:03

true because of all are animals so all these strings in our array would be three characters in length so once again

388:12

I could also store this as something so I'm just going to cut this out and let's store this as

388:19

const three letter animals or is a thre letter animal

388:27

because it's going return a true or false is three letter animals is three animals true and if we

388:37

change this to an eer we get a

388:43

false okay so that is how every works I

388:48

think we're ready to move on in this next section I want to take a

388:54

moment to talk to you about split and how it works let's do it the split

389:00

JavaScript method divides a string into an Ed list of substrings and it puts

389:06

these substrings into an array and Returns the array the division is done by searching for a pattern where the

389:12

pattern is provided as the first parameter in the method's qu okay so

389:17

what I mean by this is this let's get a string I'm going to say

389:25

sentence and let's put I will have what she is having so

389:33

there is is our sentence now I can use split so I'm just

389:40

going to console log this out I can use split so if I grab the sentence and just

389:47

use split like that so hold on let's put

389:53

a space in between let's get a console log out I have now split this string by

390:01

the spaces so by this Space by this space by this space by this space so now

390:08

I have an array of strings 1 2 3 4 five six seven seven

390:16

elements I have an array of seven strings or seven elements okay because we have split them out and put them into

390:23

an array so that is pretty cool

390:29

okay so I'm just going to get this and instead of console logging out I'm going to save it as something so

390:34

const words that make up the sentence so if I conso log words now I will indeed

390:41

have an array of all the words that make up my sentence and now if I go into that

390:46

array so this is how we go into an array if you remember we open up our square brackets I can get the first word so I I

390:53

can get the second word which is Will third fourth fifth and so on so that is

391:02

pretty cool I can also so I'm just going to conso log words split

391:09

out by individual letter so now I

391:14

have this sentence broken up by letter and spaces to so if you see here I space

391:23

will space have and so on so now if I go

391:29

into I shouldn't call this words anymore I'm going to call it letters

391:35

I can go into the first that will give me an i

391:42

letters and go into the second that will just give me an

391:49

empty I can go into the second which will just give me an empty space I can

391:54

go into the third or index number two and that'll give me a w and so on and so

392:01

on and so on okay and

392:09

finally I could just do that which isn't really useful to us but it will just put

392:14

the sentence in its own array great so just like always I'm

392:21

going to delete this now in order for you to have a go so make a note of this

392:27

and it's gone let's get a sentence up

392:35

so here we have a sentence and it's going to

392:41

be come on baby Light My Fire I want you to get the third word

392:50

out of this for me how would you do that using Code so get the third word from

392:57

the sentence using Code I'm going to pause here where you

393:03

have a good doing this we did cover it in everything we just learned so feel free to have a look back or Google the

393:11

choices up to you I'm going to pause here while you do

393:24

this okay so the way we would do this is I would get the sentence itself use

393:31

split in order to split out by space so let's put in a

393:39

space okay let's save this as something so const

393:45

words so now if I console log words I would get the words and we want

393:54

the third so index 01 2 so I would simply go two and there we

394:03

have it we have the third word in our array so once again I could choose to

394:09

store this as something or like word store that here so now our variable

394:16

word is the third word amazing I think

394:21

we're now ready to carry on okay it's now time for some array

394:27

work we have learned a lot about arrays in these past few lessons and I really want to put it all together so this next

394:36

section is going to be quite difficult so please don't be scared if you find

394:41

yourself really struggling it's meant to be hard I really want to throw you in the deep end the reason why I'm doing

394:47

this is because I'm going to give you plenty of time to solve this by yourself and if you don't get it don't worry

394:52

that's what I'm here for we're going to go through the answers together once you have completed this section or once you

394:58

have watched this section I really would advise to make a note of this section and practice it by yourself there's

395:05

going to be a few ways to solve each of the challenges so practice solving it in loads of different ways if you wish okay

395:13

let's do it okay welcome to this section on array

395:19

workor as mentioned this is going to be quite a tough section so please don't beat yourself up over it if you don't

395:25

get it that's what I'm here for we're going to go through all the answers together so what I need from you is get

395:33

up your code editor and in your index.js file I just want you to write this okay

395:40

so go ahead and do that now pause if you need we are going to be using everything

395:47

we've learned in the previous sections about array work in order to write functions to help us solve these

395:52

problems we have a lot to get through okay so this is going to be a lot of

396:00

fun okay so each of these is going to take the same format I'm going to ask

396:06

you to use a JavaScript method to write a function that does something in this

396:11

case I want you to convert something into something else so convert

396:17

Fahrenheit values into Celsius values you're going to use a function to

396:25

do this and write your code here this exercise or these exercises will involve

396:31

some form of Googling for example your going to have to Google how to convert Fahrenheit to Celsius if you don't know

396:38

already which I definitely don't okay so

396:44

I am going to pause here while you do this the first one will be hard so have

396:49

a go at doing it anyway if you don't get it I'll go through the answer with you and hopefully that should give you a

396:56

clue into how to solve the rest of these as well so pause here have fun Google go

397:03

watch wild and I'll see you in a

397:17

bit okay so the way I would do this is

397:22

well first off I actually need to get an array so I'm just going to use this array right here

397:29

const Fen height I'm going to call it

397:34

and I'm literally just going to copy that so now we have an array of

397:40

Fahrenheit and we need to convert it to Celsius so well you would probably

397:46

Google how to convert one to the other so here we go Fahrenheit in

397:52

Celsius or Fahrenheit to Celsius should I say and we know that we can use this

397:59

formula so I'm just going to copy that

398:06

I'm going to paste it here so we can see it at all times so now we know to get something in

398:13

Celsius that from Fahrenheit I would have this number - 32 multip by 5 9 and that will

398:22

give me the Celsius value so get Celsius

398:28

well Celsius so const Celsius

398:33

array because we have to do this for every single item in our array so grab

398:39

the fahrenheit array and use map so the JavaScript method that we leared earlier

398:46

to map over each of these and apply this logic to change it into Celsius so const

398:54

Celsius array equals getting the Farenheit array so I'm getting the fahrenheit I'm getting this and I'm

399:01

using the JavaScript method of map to essentially change each one of

399:09

these so in my array of

399:14

Fahrenheit I could put value and for each

399:22

value I would take away 32 and multipied by 5 over

399:30

9 just going to put this in parentheses as well so it's easier to

399:37

read now I could do something like this so I could say const or

399:46

let Celsius array and then

399:51

assign so we're going to do our calculation we're going to make a array so changed array of Celsius and we're

399:59

going to assign it here and then that's going to get stored as a global variable so now if I cons so first of all we need

400:05

to actually call the function get Celsius and then let's console

400:13

log cellus array we would get minus 5 60

400:21

105 so we've done it amazing however I'm just going to show you a quick trick

400:28

well it's not really a trick just it's just a way of returning things out of functions that will be useful for this

400:34

section so instead of me getting on new array storing it here and then storing

400:39

as a global so that we can console loger out here after calling the function I could just

400:50

do this so now if I call my function so

400:56

console log get Celsius and call it

401:04

I'm returning this okay I'm returning this

401:09

array so that is a neat way of doing it and once again you will see that indeed

401:15

if we use this array then we're going to get this back

401:21

okay so that is looking good now based on what we have done here

401:30

I want you to have a go at doing the next one are you ready for it let's do

401:37

it I should also say that there are many ways of solving this like you could have passed through the array into here you

401:44

could have done so many things so this is just one example of solving it if you have thought of a different way please

401:49

do share it with me on Twitter I would absolutely love to

401:54

see okay next challenge let's clear this and I'm

402:01

just going to uncomment this out so we don't don't have to see it show up in our console look okay so I want you to solve this in

402:09

the exact same way that we did before so make sure to have a go at this yourself

402:15

please do use Google these are quite hard we are going to be using everything that we have learned so far so also feel

402:22

free to go back to the section about sum or anything that you think might help with this section about dealing with

402:28

falsy values okay so once again I am going to pause here please do have a go

402:35

at doing this yourself and I'll see you in a

402:53

bit okay so once again I would start off by making an array so I can test this

402:59

out I'm going to call it array one or array because we've already have an

403:06

array here oh no we don't we don't call it array let's just call

403:11

this array and then I'm simply just going to take this array that's already pre-made for us and we need to check we

403:20

need this to return a true because some of these are

403:26

falsy okay some of these are falsy so we need a true to come back this for

403:32

example is a falsey see so I would do this by grabbing the array

403:40

and using sum because we are told to use sum and the Syntax for sum so we would

403:46

need to pass something through so an element in our array I'm just going to call it element or item and for each

403:53

item we going to check if it is falsy so if you remember back on our

404:02

lesson about truth or falsy I'm going to check if the item is

404:07

falsy and I'm just going to return this and then let's check for falsy and

404:14

invoke the function going to console log that to so we can see the answer and we get a

404:23

true okay this is because Nan is falsey if I change this to be a one for example

404:31

we get a false because none of the items are now falsy so let's change that back

404:38

to not a number because we know that is falsy and we get a true so that is how

404:44

sum works it checks if any so if some of the items in our array match a certain

404:51

rule then we return a Boolean response and in this case we are checking if

404:57

something is falsy so that was what the bang is doing okay it's checking for a false

405:03

or falsy item so once again you could have done

405:09

this in a few different ways it's totally up to you if you've managed to do this in a different way then please

405:15

do let me know please do share it with me on Twitter I'd love to see your solution I'm all about Creative

405:21

Solutions so yeah hit me up okay I think it's now time to move on

405:27

to the next question so once again I'm just going to get rid of this and let's

405:33

carry on using the reduce JavaScript method

405:41

write a function that will return the total number of characters in an array so that should be of of characters in an

405:48

array of strings so for example this array of three strings rabbit football

405:53

and cracking returns 22 as there are one 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17

406:02

17 18 19 20 21 22 characters in

406:08

total okay so I want you to have a go at doing this please use the reduce JavaScript

406:15

method to do it so we just recently covered that one and I'll see you in a

406:23

bit once again as a reminder this is all you need to write out in your code editor and your code goes here

406:53

okay so hopefully you've had a go at doing that yourself if you haven't quite got it don't worry that's what I'm here

406:59

for we're going to go through the answer together so let's do

407:04

it okay so the first thing I would do is just create an array so const words let's call

407:11

it and I'm just going to get this array and I need the so when I console log get

407:18

total I need to get the 22 value so well first off let's get the array itself and

407:25

use reduce now we know that reduce works with a total and a value and it ACC

407:32

accumulates okay so we're going to put that this is these syntax I'm just going to write these Syntax for

407:43

now so that is it we need an arrow function here and we'll put total and value so that is the syntax if you

407:50

remember oops that should be a plus that is the syntax if you remember from our lessons let's get working on this okay

407:59

so we know that this is the total and this is the value so this going to be rabbit football cracking so what we need

408:06

to do here is get the total whether each time we add to the total we don't want

408:11

to add the values to the string itself we don't want to we don't want to add rabbit and then football and cracking

408:18

that won't really do much it doesn't make sense instead of adding the word or the value itself so perhaps let's change

408:26

this to word now because we know that's going to be a word we want to get the word length

408:36

okay and then one more thing that I need to do is start from zero so this is what

408:41

I said about Googling if you Googled this uh you Googled how to do this you might have got this as a response so

408:49

let's see if that has worked this is because we're going to be starting from zero so

408:54

console log get total let's invoke it

409:00

and of course we need to re something from the function so there we go we get

409:06

22 if I got rid of the zero well that wouldn't really make much

409:12

sense rabbit 88 this is because we are telling it to

409:17

start from zero okay it's an initial

409:24

value once again there are many ways to do this this is just one way that I would do it if you have your own and are

409:31

really proud of it like to share it please do tweet me I'd love to see and I'd love to share your solution with

409:37

others too so go ahead and do that this is how I would choose to solve this

409:43

problem hopefully your Googling is getting a lot better Google is such an important tool of a software developer

409:50

and I hope you can see why this is a total Google exercise and Google would have helped you with this

409:57

okay I think we're ready to carry on so I'm just going to get rid of that console log once again again so we don't

410:03

have anything in our console and let's get to it using the every JavaScript method I

410:12

want you to write a function that checks whether a number or every number in an array is a square number so for example

410:21

this would come back as true as 9 is a square number 3 * 3 is 9 16 is the

410:27

square number as 4 * 4 is 16 and so on this as well 9 * 9 is 81 so they're all

410:33

square numbers okay how do you think you would

410:39

use the every JavaScript method in order to check whether every number in an array is a square number I'm going to

410:46

give you a hint for this this square number part is going to involve some Googling as it is a very useful

410:53

JavaScript method that we have not covered that exists that will help you with this to give you a clue it starts

411:00

with math okay it starts with with math sort of like math random and math round

411:06

and math seal so there we go have a go at Googling this have a go at doing this

411:13

yourself once again this is a Google exercise as well so have fun go for it

411:19

and we'll go through the answer together

411:43

okay so hopefully you've had a go of doing that let's go through the answer

411:48

now so once again I'm going to start off with making an array so cons Square well

411:54

let's just so numbers cuz we don't know if they're square or not that's what we're checking we're checking if all of them are square numbers so I'm just

412:01

going to get this array and we know that it's true so we need this to return a Boolean of

412:09

true so I will get the numbers and I'm going to use every so and get the Syntax

412:16

for every so it's going to include me getting an element from an array and for each element we're going to be writing a

412:24

rule so I've chosen to call this num just because these are numbers you can

412:29

choose to call this I or you can literally choose to call it num number so for each number in our numbers array

412:36

so this one this one this one I need to check if this number is a square number

412:43

so I did say to have a go at finding another JavaScript method that could

412:49

help us with this and there is something called math square

412:55

root so here we go math square root as you can see on the mdn website the math

413:01

square root function Returns the square root of a number so this is going to help us do this so I'm simply going to

413:08

get this right here so I'm going to get that and I'm

413:14

going to put through the number so I'm going to use this to get the square root

413:20

of the number okay so if I put through a nine here I will get a

413:27

three and now I use modulus one so let's get modulus this one because all square

413:35

numbers are made up of full integers so I need to check if the whatever the outcome of this so I can actually

413:42

console log that console

413:49

log I'm just going to put this in

413:56

here let refresh it's console log I'm just going to call check

414:03

squares inoke the function is a three so that is a full number okay that is a

414:09

full number so if the full number modulus one gives no remainder so we are

414:15

literally going to check if it is uh divisible by one and leaves no remainder

414:22

then we know that it is a square number okay so I'm just going to return

414:29

this return I'm just going to get rid

414:38

of that two so now I'm just going to put a one one line I'm going to tell you

414:45

what this line of cone means I'm getting the numbers array and for every number in my numbers array when I'm getting the

414:52

number and I'm getting the square root of the number so as we saw with nine that was a three so that will return a

414:59

three and three modulus one leaves no remain remainer so it is a full number

415:05

we are essentially checking if the square root of this number is a full integer and if it is a full integer we

415:11

know that number is a square number and we can return true as we know all of

415:17

these are square numbers so now if I put through something that is not a square number I will get false this is because

415:24

the square root of 80 is not a full number so it does not pass this Rule and

415:30

we fail this returning a true so let's put it

415:36

back to all square numbers once again this was quite math heavy and it did

415:42

involve you googling this so I do hope you've got it if not don't worry that's

415:48

what I'm here for that's why we went through the solution together if you have thought of a different way of

415:54

solving this then please also do share it with me I'd absolutely love to see

415:59

your solution okay great let's carry on if you are

416:06

thinking like oh how come you've put um parenthesis around this we don't actually have to so there we go I've got

416:12

rid of it there and we can also get rid of it here too and here as well it is not it is not

416:20

necessary okay it's just an option for us

416:27

okay next challenge just going to get rid of this here

416:33

and clear out a console log okay next question using an array

416:42

method so this time I'm not going to tell you which one I want you to write a function that returns these string

416:48

elements of an array that have a given length or larger so for example if I was

416:53

to pass through this array and the number five I should get the words

416:59

Florida and phone back okay so we're going to be using two

417:04

things in order to do this so as a clue I'm going to have const words

417:11

array I'm going to get this here and we have

417:20

con number five and then I would use that in

417:25

my function in order to return something that will give me back Florida and phone

417:31

based on these if I was to pass through a three well I would expect everything

417:37

to be returned so have a go at doing this I'm going to pause here while you

417:44

do it so make sure to take this down in your code editor and go ahead

418:18

okay so the way I would do this is like this I would use so I'd get the words

418:24

array first return the word array and then I

418:30

would use the filter method because we're essentially filtering out we're trying to find which of the elements

418:37

match a certain Rule and then this is the Syntax for a filter so I'm going to get a word or as I've chosen to call

418:44

word this is the syntax it just means that for every item in our array we want to apply a certain rule which we're

418:50

going to write here so if the word

418:57

length equals what is larger than

419:02

the number so in this case it is three well

419:07

return that let's see if that has worked so console log get

419:16

words and let's call the function and there we go Florida dog

419:23

phone if I change this to five we will get Florida and phone now the reason

419:29

it's written like this is that we are essentially writing this function to take parameters or arguments so for

419:37

example if I was to console log out this and now use get words and pass through

419:44

this array and the number

419:55

five and then have an array here and number so once again then

420:02

change this to array and number we will get Florida and

420:10

phone okay so now I can check this function works for many things so once

420:18

again get words I am recycling the function that we have written and I am

420:23

checking it works with different array so let's just have

420:29

pen ason

420:38

copy and then let's pause through the number let's say

420:46

three and we will get all three and if I pass through a six I we'll just get

420:52

astronaut CU astronaut is the only one that has a length of six okay so that is

420:59

how we would check the function many many times we are passing through an

421:05

array and we're passing through a number and then when're using that array or whatever array we passed through to

421:12

filter and check against that number so if you go here I'm literally taking this

421:17

array I'm putting it here and I'm putting it here and then I'm taking this number and I'm putting it here and I'm

421:24

putting it here okay and then running my function great

421:33

okay so hopefully you've got that if you do have another way of solving this I'd

421:38

absolutely love to see so please do share it with me I'd absolutely love to see all your Creative Solutions there's

421:44

many many ways to solve this and let's carry on so I'm just going to conso this

421:50

out

421:58

now using an array method so once again I'm not going to you which one write a

422:03

function that converts an array of centimeter values as strings into an array of numbers so once again this is

422:10

going to be a fun one as you're going to have to Google there is a really Nifty JavaScript function that will allow you

422:17

to convert strings into numbers so I'm not going to tell you what it is but as

422:22

a clue just Google strings to numbers in JavaScript and you should be able to

422:27

find that JavaScript method so have a go doing this just simply copy this out in

422:33

your code editor and let's get to

422:58

it okay so the way I would do this is I would essentially let's get an array

423:04

so con array and I'm just going to literally use this array right

423:12

here and I'm going to return so array three I think we have to call this or

423:17

let's just put centimeter values and return where I would get the

423:25

centimeter values and then I'm going to use map as we are essentially going to be

423:31

mapping onto each element and I'm going to use map so this is my map syntax I'm going to get a

423:39

value and for each value I need to do something right

423:45

I need to change it to a number so I

423:51

don't know if you've managed to find it but there's something called pass float

424:03

the pass float function passes an argument converting it to a string first if needed and then returns a floating

424:10

Point number so it's going to change it to a number for us okay just like that

424:17

so let's go back here and I'm just going to use pass

424:22

float and Surround

424:28

my value in it so now if I conso

424:33

log get values and call the function there

424:40

we go I have now got 30 23 5.6 and 1,000

424:49

brilliant now we can of course go the extra mile in testing this just as we did before so I'm going to comment this

424:55

out for now let's put an array in so I'm just going to put a different array this time

425:01

I'm going to put 34 CM as a string 45 cm

425:07

as a string and 1.2 cm and I want this to

425:16

convert into integers so I would put the array so I'm just saying whatever this

425:22

is I'm passing it through as an array and I'm going to return that so there we go that has

425:30

worked too I've now converted this other array into integers let's do it again so

425:37

console log essentially any strings or array of strings I pass

425:44

through into the get value function now should come back as integers so 3

425:52

cm 4 cm

425:58

oops 4 cm 7

426:04

cm console log get

426:11

values and there we go we've done it we've written a function that will literally take any array of strings as

426:21

values and turn it into integer values cool let's move on

426:33

using split and filter write a function that counts the number of vowels in a

426:39

sentence so for example here we have a function and if you pass through in West

426:45

Philadelphia born and raised it will come back with 12 this is because there are 12 vowels in this sentence so I want

426:54

you to have a go at doing this it is a bit on the hard side but it does use

426:59

everything that we have learned so far so I want you to have a goat doing it I'm going to pause here while you do

427:04

this and I'll see you in a

427:30

bit okay okay so hopefully you've managed to do that if you haven't don't worry that's what I'm here for we're

427:36

going to go through the answer together so the first thing I would do is let's get our

427:43

const saying I'm going to call it a saying let's get this

427:50

string okay now what exactly are my vowels so const I'm going to find out

427:56

what my vowels are my vowels are a

428:03

E I O U but I also need the capitals as well

428:10

so a b i

428:17

o u okay because we also need to count the capital vowels in this saying so

428:24

those are all my vowels it's an array of all the vowels as strings split out

428:31

okay so how would I do this well I would of course grab my saying or my string

428:38

essentially and I'm going to use split and I'm going to use split to split out

428:43

all of this by individual letter so if I console log this out if I console log

428:51

out saying and split it out like so you will

428:58

get there we go so we split it out into array of

429:03

individual letters this is going to help us now because now we can use filter to

429:08

check if each one of these matches a certain rule so we've done that we split

429:14

it out now I'm going to use

429:20

filter to essentially filter out letter by letter so I'm going to grab the letter and letter by letter I am going

429:28

to check if that letter is included in the

429:34

vowels so if you remember back to the include JavaScript method I would grab the vows array use includes to check if

429:43

that letter exists in my

429:49

array okay so once again I am splitting up

429:54

this to be an array of individual letters like so and then I'm going to filter out and I want to save every

430:01

every single letter that is included in this array so if it is included in this

430:06

array I want to save it as something so I'm just going to save it or I can I

430:13

save it so const just so you can see what's happening actually I'm just going to

430:19

console log

430:24

this and let's call the function so I'm going to conso the function get

430:32

vowel count so there we go I have now an array

430:38

of just the vowels from this sentence return to me okay there we go

430:45

we filtered them out we've collected all the vowels the next thing we need to do is finally just get the length of this

430:52

array now because that's what we wanted we wanted the count of how many vowels

430:57

exist in this sentence and it should be 12 and that's what we're getting we're

431:03

getting 12 brilliant so that is the solution I've of course written it in

431:10

one sentence and I also actually need to return this for this to work so I'm

431:15

going to return that like so and now if we pass through any sentence into here

431:22

we should get the vow count okay once again I know there's many ways you could

431:27

have solved this this is my way that I've written but of course please share

431:33

your Solutions with me share them with you on Twitter I love to see them and share them with everyone else cuz I'm

431:38

sure they would really appreciate it too so now if I pass through anything I

431:43

can pass through I am a

431:50

dog so that is a sentence I'm going to CL through a sentence and whatever the

431:56

sentence is I want you to check if it

432:01

has vowels and how many so I get four 1 2 3 four that looks right let's try

432:07

something else console log hello there

432:12

everyone and that has eight vows amazing we have now written a function that will

432:18

literally return back the amount of vowels we have on any sentence let's

432:23

carry on once again I'm just going to comment

432:29

these out and we have got to our final question in the array work section in

432:36

this one I want you to use split map and join in order to write a function that

432:41

capitalizes the first letter of each word in a sentence so for example here

432:46

we have a string the Queen's Gambit I want to change it to the Queen's Gambit

432:52

like so not in an array that is not necessary so once again get to your code

432:59

editor write this out and try solve the solution by writing your code

433:05

here okay let's pause here feel free to Google of course or look back on our

433:11

previous lessons that is absolutely fine too I'll see you in a bit

433:34

okay so the way I would do this is so let's return

433:39

something let's get something so con words

433:48

equals words identified words

433:53

two and there we go now I want to capitalize everything in here so I'm going to grab the words string and I'm

434:02

going to Let's maybe call this something else let's call it a title cuz it's a title of a film I just don't like using

434:08

numbers in um variables and I'm going to use split again this time but this time

434:15

I want to split it by word so I'm going to literally split it out by word if I console log this so

434:23

actually console log capitalize and let's call

434:29

the function I would get a array with the three words

434:35

split out so just like that now I need

434:40

to change each of these in order to have a capital letter so I would do this like

434:47

this I would get map because we're changing each one and then for each word

434:53

or element in my array so once again for each word I want to apply this whatever

434:59

is written in here now this is something that we haven't used before that I'm going to use in

435:06

order to solve this it's called chart at and it just means the first character so

435:12

if I po zero I just mean the first character in my word so there we go you

435:18

can already see I've got about T Q and G if I just left it like this and I'm

435:24

going to use some in called to upper case so once again this was a great one for Google because I'm using a lot of

435:31

stuff that we haven't discovered yet but by Googling we have found them okay so

435:39

I've just taken the first letter of each word and changed it from small to

435:46

capitals okay now I need to put it back in my word so for this I'm going to use

435:53

plus word so I'm getting my word again I'm going to use something called substring to essentially

436:02

add it to the beginning of my word so word substring one and replace the first

436:09

one with it so that's what it looked like with just substring you can see the capital T and

436:16

the original word but if I put one I'm essentially substituting the first

436:22

letter Okay so we've done that and the final thing we need to do is use

436:29

join oops join on the whole thing however so I'm

436:35

just going to wrap all of this in like that so I'm joining the

436:40

whole array now I've joined it but I want to join it like so so I want to join it without

436:50

the commas and taada we get the Queen's Gambit as a string returned to us just

436:58

like we wanted and once again I can pass through anything into here

437:05

so Life of Pi just going to comment that out and then pass through a title in

437:11

here so Life of Pi is now capitalized let's try something

437:17

else The Incredibles and there we go okay I hope

437:25

this was useful I think this exercise is really good as I said it was a bit on the the hard side and it did involve a

437:33

lot of Googling in order for us to get the solution just like with the last one there was a lot of Googling that you

437:39

should have done there as charat is a new one for us and so is substring you

437:44

would not have seen them in this course but with the help of Google you hopefully got the right answer or you've

437:50

come up with your completely own version of how to solve this as mentioned if you have I would absolutely love to see your

437:56

solution I'm all for creative thinking and I'd love to see how you solved this

438:02

challenge okay let's carry on in this section I want to talk to you

438:09

about the add event listener the event Target method add event listener sets up a function that

438:15

will be called whenever the specified element is delivered to the Target what

438:21

I mean by Target is an element itself a document or a window don't worry if this

438:27

doesn't make sense I'm going to show you this in code so for those of you who have been carrying along with my course

438:34

we would have used Advent listener a few times by now however we haven't really delved into how it works so let's do

438:41

that now the ad event listener essentially can work on a

438:50

Target and then we pass through a event such as a click so I'm

438:56

just going to put through event and the function that we want to invoke when the

439:02

event is triggered I'm just going to show you this with an example for the Target I'm

439:09

going to choose this green square right here so let's go ahead and pick it out

439:15

from our HTML file so I want to choose this with the ID of hexag again so I'm

439:21

just going to copy that and in here I'm going to use document I have not made up document or get element by ID that is a

439:30

JavaScript method that will allow us to look in our HTML document and find the IDE of

439:35

hexagon now let's store this as something well I'm going to store it as

439:41

hexagon so that we can use it in our Javascript

439:46

file so now we have a Target so I'm going to get the hexagon and I'm going to use ad event

439:54

listener so the JavaScript method of ad event listener so that each time we

439:59

click on the hexagon but only the hexagon so I'm going to pass through a

440:06

click here once again I'm not making this up this comes from a long list of things that we can pass

440:13

through and once I click the hexagon I'm just going to get a function

440:18

so let's write a function alert me I just want to say console log

440:29

clicked so now we need need to pass through a function and that function is alert me so let's clear this and see if

440:36

that has worked let's click on the hexagon let's get our console log out

440:43

refresh that and there we go clicked clicked clicked so everything is working

440:51

here let's break this down a bit further so my target is the hexagon itself I'm

440:57

using ad event listener I'm passing through an event to invoke a function

441:03

when the hexagon is clicked we are listening out to anytime someone

441:10

interacts with a hexagon and if that event is a click we invoke the function

441:16

here so I mentioned that I did not make this up uh there are plenty of things we

441:21

can pass into ad event listener here are just a few so here we have click we have double

441:29

click we have Mouse down we have so many this one's depreciated let's choose another one so

441:36

perhaps we can work with mouse

441:43

over so I'm going to replace with this mouse over now let's refresh and as soon as I

441:49

just hover my mouse over we invoke the function so that's pretty cool I'm not even do anything I'm just hovering my

441:55

mouse over it and it's invoking that function

442:01

so that is how ad event listen works as mentioned I could do it on the window or

442:07

I can do it on the document itself as well so this is probably a good time to show you I'm just going to comment this

442:14

out for now now I'm just going to get rid of all

442:19

this here at the moment in our index GS file we have our script to our Javascript

442:27

file at the bottom of our body so we always keep it here we make sure that

442:32

all the HTML elements are above it cuz we need to load the HTML elements before

442:38

reading the JavaScript however sometimes people like to put the

442:44

script tag in the header with the CSS file okay so if I move that here none of

442:52

my JavaScript would work this is because we have not read any of the

442:57

HTML okay so what I would do do is essentially use get the document and add event

443:05

listener and make sure that the Dom

443:11

content has loaded before and this is an aror

443:18

function and once everything has loaded so once all the HTML has loaded

443:23

then and only then can I start to pick up my JavaScript okay so that is another

443:33

way of uh picking up JavaScript from our HTML file and it is using the document

443:40

Advent listener a lot of people will tell you that this is the more secure way of doing it so it's totally up to

443:46

you how you'd prefer I'm going to get rid of this for now but I do use this approach in some my games so just be

443:52

aware of that both are completely correct so I'm just going to put this down to the end below all of my HTML

444:03

elements so that was a great example of using document with the ad event

444:09

listener once again just to recap the ad event listener takes a Target and then

444:14

we use the ad event listener so the JavaScript method add event listener and we pass

444:22

through an event and the function that we want to call if the event is

444:28

triggered so I'm going to ask you to have a go at this

444:36

yourself so I'm going to pick out uh another element so I'm going to get the

444:43

body this time so I'm going to

444:48

use I need to pick it out first so I use document query

444:54

selector to pick out the body let's store this as something const

445:02

body now how would I make something show up in my console log so just the word

445:09

clicked if I click anywhere on the body so anywhere in

445:14

here just use what we learned before it's exactly the same have a think about it I'm going to pause

445:25

here okay so I would get the body and I would use ad event listen

445:30

to pass through a click event and then invoke a function so I can write the function up there or I can simply write

445:37

function and then in curly braces console log clicked so there we go I've

445:45

just written in one line but it's exactly the same as what we did

445:51

before and now if I click the body you will see I'm

445:57

getting a message in our console log that says clicked okay

446:03

great I just have one more thing to show you about this before we carry on next

446:09

up I want to talk about removing event

446:14

listeners okay so the remove event listener method removes an event handler

446:19

that has been attached with the ad event listener method don't worry though I'm going to show you what I mean by writing

446:26

this in code so before we looked at ad event listener so I'm just going to use that once again

446:32

I want to add an event listener to my cycle to essentially toggle it from being blue to another color so I'm going

446:40

to go into my document and use Query selector to find the circle so I'm

446:47

looking for the class of circle so the class of circle and let's score this as

446:54

Circle so we can use it in our Javascript file now let's write a function to do

446:59

this toggle so function toggle Circle or toggle color maybe the

447:06

American color and I'm simply going to grab my circle and then use a JavaScript

447:14

property of class list so I'm not making that up I want to toggle toggle is a method once again I'm not making that up

447:20

I want to toggle the class list of circle and I want to

447:25

toggle CLE so now let's grab the circle and use

447:32

add event listener on click let's

447:38

say to toggle color so now if I click on

447:43

the circle well the circle class will disappear so let's change that to be

447:50

something else so I'm going to toggle it got the circle and I want to say red

447:58

circle and simply just copy all of

448:04

it red so now if I

448:09

toggle red circle there we go I'm adding and

448:15

subtracting the red ccle class from the div which already has a class of circle

448:21

so that's our default and then we are simply adding red circle taking away red circle adding red circle taking away red

448:26

circle from it so that is our function at the moment everything works however I want it to

448:33

stop working after 10 toggles so when we click on this nothing

448:41

will happen so I can do this like this so we need a count have a

448:46

count let count equal zero let console log count to see what's

448:52

happening too it's nice to do that and if count is

448:58

suddenly larger than

449:04

10 I want to get the circle and I want to remove event

449:12

listener I'm just going to remove the same thing so now let's try it out let's get

449:20

our consor log 1 2 3 4 5 6 7 8 9 10 11

449:27

and suddenly no matter how hard we click we can't toggle the color anymore and we

449:35

can't add to the count that is because our count suddenly got over 10 we got to

449:41

11 that's over 10 so we have written that we want to remove the event listener from the circle that says that

449:48

when we click we toggle color we have removed it so that is a very basic example of

449:54

how to use remove event listener I hope you've enjoyed it because I'm going to

450:00

make you write your own now so I'm going to keep the circle

450:08

here this time I want you to use what we've done in the previous lessons and

450:13

if our circle gets to here so about I don't

450:20

know 100 pixels below itself I want you to remove the event listen n so that we

450:26

can't click it anymore and nothing else happens okay so we did do this previously in

450:32

these set intervals so there'll be a little bit of a clue there I want you to have a go at doing this yourself don't

450:38

worry if you don't get it done that's what I'm here for I'm here to help if you want to have a look at the

450:43

stylesheet all I have done is simply got a circle that you are going to be working with that we have picked out to

450:49

work with and that is my index HTML file and of course my folder

450:57

layout okay I'm going to pause here where you have have a go at doing this I'll see you in a

451:09

bit okay so first thing I would do is write a function let's say move

451:15

Circle and then well to move the circle let's actually let height equal

451:23

zero now for each time I want to move the circle I'm actually going to also add a

451:30

height of 50 and then we need to assign that new height to the circle itself so let's

451:36

grab the circle I'm going to use style so this is not made up I'm going to use

451:42

style and then top and assign it a new

451:47

height and get the pixel so in here I just need to make sure that the position

451:53

of this is absolute in order for this to work so position absolute and

452:00

essentially what we have written here so we're getting the circle then we are manipulating its style and we're

452:06

going to be adding a top so it's just the same as me writing top 100

452:12

pixels so I've just moved it down a little bit so that's what we're going to be doing but in our

452:19

JavaScript okay so move Circle let's attach this to an event listener so let's grab our Target I'm going to use

452:27

add event listener to essentially on

452:35

click move the circle so maybe this isn't enough let's

452:40

do 100 why did I add event

452:46

listener okay so now click click click

452:52

it's moving down it's good but it'll carry on doing that okay so we'll carry

452:57

on clicking it and I'll carry on moving down we need a rule that says

453:04

if height suddenly gets over 300

453:11

pixels you want to get the circle and remove the event listener that we added

453:18

so let's pass through these rules again and save so now I get to

453:25

300 we can't click it anymore we are over 300 pixels in height and we can't

453:32

move it so there we go okay I hope you found this useful

453:40

please do write this down please do make a note of it I do hope you're coding along with me as I really do think

453:45

that's the best way to learn by coding and not just watching so I hope you enjoyed this and learned the most you

453:53

could I'll see you in the next lesson so next up I want to talk talk to

453:59

you about the query selector as we're going to be using a lot in this course let's do

454:06

it the document method query selector Returns the first element within the

454:12

document that matches the specified selector what I mean by this in code is

454:19

this so we're going to be using query selector in order to pick out elements

454:24

from my HTML you might have seen this in a few examples already but I really want to talk to you in depth about this so

454:33

here for example we have a div with a class of circle well we can actually

454:39

pick out this div by the div itself or more specifically by its class what I

454:47

mean is this so I would get the document as we need to pick it out from the HTML

454:54

document and use Query selector so this is a JavaScript method

454:59

method I am not making this up and I would pass through so for

455:05

example if I wanted to pick out the div at the moment there's only one div in

455:10

here so I don't see a problem with that I've picked out the div so now if I console

455:18

log this out you will see a div with a class of

455:24

circle that's what we have I've picked it out so now I can work with it in my

455:31

Javascript file so that is pretty cool let's go ahead and save it as something I'm going

455:37

to save it as a circle okay so that is done however what

455:43

if I start having more and more divs in my HTML file well then I wouldn't really

455:49

want to choose to pick it out by the div element I would want to pick this out by

455:55

the circle class so you would think I would just pass it in through here like this but

456:01

that is wrong if I write that nothing will get picked out so if I console

456:09

log Circle I get null this is because we are

456:15

not searching for a HTML tag or element of circle that doesn't exist we are

456:21

searching for the class of circle so just like in CSS we need a DOT to tell

456:28

our file that we are looking for a class name of SLE and then you will see that

456:35

work so that is essentially how I would use Query selector there is also query

456:42

selector all this is for if I want to pick out more than one so if I for

456:49

example had not just one Circle but two three

456:54

circles let's just get rid of this absolute styling

457:05

get of this to refresh our page so now you will see

457:12

three circles I can pick out all of these circles with document query selector

457:20

just going to get rid of that or so now I essentially have a node list

457:29

of three circles or three divs with a class of circle so once again if I just

457:37

had query selector it would pick out the first div with a class of circle but if

457:42

I want all of them I would need query selector or to get a node list a node

457:50

list is not to be confused with an array a node list is something

457:55

different okay so we have all our s

458:01

here I can also use Query selector to pick out IDs so I'm just going to make

458:07

let's get rid of these for now I'm going to pick out so I'm going to make a

458:15

ID of Main and let's give this a red circle class let's just get rid of let

458:23

get that red circle back so now we know that our yellow

458:29

circle is here and we know that our red circle has an ID of main however our

458:36

JavaScript doesn't know that I can pick out that Circle by grabbing its

458:43

ID like so so you will see here I've grabbed the element with the ID of main

458:51

so just like in CSS I would tell our Javascript file this is an ID by using

458:57

this hash right here and then I'm storing a circle and if I console log

459:02

out Circle well we indeed get the div with the class of red circle and the ID

459:08

of main so I like using query selector we

459:13

can also use get element by ID in which case we don't need the ID as we already

459:20

know it's an ID the method already tells our file that we're looking for an ID so all I need to do is path through main so

459:29

that is me using get LM ID once again this is a JavaScript

459:34

method and I did not make this up there are in fact a few of these

459:41

there's get Elements by class name get element by tag name so there are a few

459:46

however those are the most popular three that I tend to see when I work on these

459:52

kind of projects okay I hope that was useful let's carry on

459:59

okay and Welcome to our first external project in this project I'm going to ask you to make a dropdown using JavaScript

460:07

CSS and HTML it is going to be a great project as it's going to use everything

460:13

that we have leared so far in order to complete the challenge if you want to have a go at this please do click the

460:20

YouTube card right here otherwise let's carry on with the course the choic is

460:27

totally up to you good luck

460:32

okay so I've already shown you some methods and properties that work on the array JavaScript built-in object however

460:40

I want to show you some that work on the math buil-in object too so I'm going to

460:46

show you the most popular I'm going to show you the three most popular ones let's do it first up is math

460:55

random the math random function essentially returns a floating Point suit a random number in the range of 0

461:02

to less than one what I mean by this is

461:07

so if I just go ahead and conso log math random making sure to spell it

461:14

correctly and invoke it or call it like this I will essentially get any number

461:22

from zero to anything less than one so if I keep refreshing it it will never

461:29

really get to 1 0.8 0.4 it'll just keep going forever giving me completely

461:35

random numbers so that is it essentially in a nutshell but how is this useful to me

461:42

you might ask well I actually use this quite a lot especially when I need to get a random element from a array or

461:51

random number I do this a lot in Tetris so I'm going to use the tetris example

461:57

to show you now so I'm going to make a array of

462:04

tetraminos so I'm just going to put in three let's have the L tetraamino usually I would have this as an object

462:10

but I'm just putting it as a string for now as that's all you need Z tetraamino

462:16

and I tetraamino so we have three

462:22

tetraminos now how do you think I would get a random tachino from my aray

462:29

completely at random well just going to keep this up here for

462:35

now for you I would need to get a integer a full

462:40

integer and pass it through into my array in order to get something back

462:46

right so that would be the equivalent of me writing tetraminos and then passing through a

462:52

zero to get by the AL trino so I'm just going to console log that for you so you can see what is happening

463:00

so you'll see I get the L touch fromo pass through a one I get the Z touch fromo if I pass through a two I get the

463:05

I touch fromo if pass three I get undefined because there's nothing there let's go with one so how do you

463:13

think I can use math random which splits out essentially at the moment any number from0 to less than one to give me a

463:20

random number I can pass through into my array but it also has to be the correct length

463:26

well just going to get this back for now I can actually use math random to

463:32

essentially multiply by any number so if I multiply this by

463:37

20 I will get any number That Is Random from 0 to just under 20 so less than

463:47

20 if I keep refreshing this that is what you will see it will give me

463:52

numbers that are anywhere from zero to just under 20 so under 20

464:00

now I'm going to use this to get a random number from 0 to 3 but just under

464:08

three so I would do this I could just pass a three like that or I could use my

464:18

tetraminos length property so that is essentially a three so now if I keep

464:25

refreshing I will get a random number anywhere from zero to less than three it

464:30

will never get to three so we're close we're nearly getting there but I'm going to have to

464:36

introduce another math related function and that is math

464:45

FL math flaw essentially rounds

464:51

numbers numbers down to the nearest

465:01

for integer okay so now let's get

465:11

const for const integer or maybe random

465:19

integer I would essentially let's also store this const

465:25

random number and I'm just going to store the number we're getting

465:33

here so now I would need to use math floor to essentially wrap our random

465:43

number so now if I console log random

465:48

integer well you guessed it I'm just going to clear a few of

465:54

things out so I'm just going to comma that out here I'm actually going to console

466:00

log random number for you here so you can see what is happening I'm going to get R of that so

466:08

it's clear everything refresh so here you will see we get the

466:14

random number of 0.27 and we are rounding it down to the

466:19

fullest inure so we've rounded it down the rounding down is important as we

466:25

don't really want to get a three okay so for example if we got a okay a 2.2 if

466:32

you round this up we will get a three and of course 0 one 2 three does not

466:38

exist on our array so we will get undefined we can't round up we need to

466:44

round down in this situation and that's why math floor works this is opposed to using math

466:56

seal which will run round up

467:02

and oops math round which will just round to

467:10

any round to nearest integer okay so it

467:15

will choose which one it's closer to and we don't want that either we want to round

467:21

down okay so we have our random integer that has been rounded down so now now

467:29

instead of passing a one well we can just pass that random integer through

467:34

here because this has a value now it's a full value and the random tetraamino that we get is the Zed tetraamino this

467:41

is because it's the 01 one index in our array so one we got

467:47

a random number of 1.21 we rounded it down to one and we got the

467:53

Zina I could keep refreshing this and never get an undefined because we will always get either a z 1 or a two so

468:03

that's perfect that has now worked I hope you can see how useful

468:10

this is there are many many more math uh functions for you to use however I do

468:15

think these are the most popular so these and this one feel free to have a look at yourself on the documentation

468:22

there's so much documentation out there on JavaScript however I do want to focus on these for now so I'm going to give

468:28

you a little exercise first so I'm going to keep this notation just so you can

468:34

have

468:39

it okay let's pretend we are at a bar and

468:44

there is a drinks menu so drinks menu and then let's have a

468:51

vodka tonic let's have a white wine a beer and a mocktail for

469:01

those who don't drink mocktail so your friend essentially ask

469:08

you to get him a drink from the menu you ask him what he wants and he says surprise me anything from the drinks menu pick up random how would you use

469:16

JavaScript essentially pick a drinks menu at random from this

469:22

list I'm going to leave you to it please do use everything that used before in

469:28

order to solve this and get a random drink from the drinks menu don't worry if you want to go back and view what we

469:34

did before that's absolutely fine just focus on getting this done and if you don't also don't worry because we will

469:40

go through the answer together so have a go at that and I'll see you in a

469:53

bit okay so what I would do is I would essentially get the drinks menu itself

470:00

and I would open this up because we need to pass something through and then I would use math

470:07

random invoke that and multiply it by my drinks menu

470:13

length and then wrap all of this in math floor so that is essentially the

470:19

solution in one line of code let's console lug that to see what we get

470:33

and we would get a vcat tonic we would get a beer we'll get a beer again there's a lot of beer showing up and

470:39

mocktail so we are getting everything we've got a white wi that is all the items on our drink menu then we are

470:45

getting it random okay I'm just going to break it down for you step by

470:51

step so once again we would we need to get a random

470:59

number so to get this random number we would use

471:04

math random and then we would multiply it by the number of items in our array so I

471:11

can either multiply it by 1 2 3 4 or I could use the drinks menu array

471:18

length property so now if I console log random

471:26

number okay so we're getting that random number we just need to round it down now so

471:31

const Random integer and to use this I would use math

471:38

floor because remember we want to round down and then I would pass through the random

471:45

number okay so let's console log that to see if that has worked

471:50

random integer okay yeah it's rounding down we got 3.5 and we rounded it down

471:55

to three and then finally we would get our drinks menu and pass through the

472:04

random integer so let's console log

472:10

that and great once again we are getting random drinks from the menu let's try

472:18

using math

472:24

seal so it's working it's working however

472:30

we get undefined this is because we rounded up they got we got 3.14 but we

472:36

rounded up to four there is no fourth item in our array so we get undefined we

472:41

would also never get VOD catonic okay so no matter how hard you tried your friend would never get a vodka

472:49

tonic okay so that was fun I hope you enjoyed that uh that is it that is all

472:54

I'm going to cover for the math inbuilt JavaScript objects I think that's fine

472:59

for now I mean this is a crash course so I think we're ready to carry

473:07

on in this next part we are going to go back to our website to give it a Final

473:12

Touch by creating a responsive Burger menu Nappa this is going to be great as

473:19

we will be implementing some JavaScript functionality to our website for the first time so what are we waiting for

473:27

let's do do it okay so I'm really excited about this

473:33

section because we are going back to the project that we started building in our HTML and CSS but we're going to start

473:41

applying some JavaScript we are going to start doing this by making our navbar

473:47

responsive what I mean by responsive is that it's going to have a different view

473:52

in mobile than it does to tablet and desktop so what we are going to be

473:58

making is a simple responsive nav bar that turns into a hamburger bar if it is

474:04

a mobile and is the way it looks as it is now when it is tablet and desktop

474:10

okay so let's get to it the first thing we

474:16

need to do to build our hamburger responsive Navar is go into our index

474:22

HTML and find our nav bar that we have built out so it's this this section up

474:29

here it's got a logo and our unordered list that is called

474:34

Navar so in between them is where I'm actually going to put my hamburger uh button so it is a button so

474:41

I need a button tag for this and I'm just going to give it the class

474:47

of hamurger I'm also going to give it an ID of

474:55

hamburger as well great now in here it's going to be a

475:02

lesson back to our font awesome icons so I'm going to use an

475:08

icon so an icon tag and I already have found a hamburger uh icon for us to use

475:16

so I'm just going to type it in here for us now and hit refresh so there it is it's

475:24

currently in a button it doesn't look great so let's sty up so I'm going to do this right at the

475:32

very bottom even though we will be using this nav bar so I'm just going to cutor out that's our current styling at the

475:40

moment just going to put that here okay so let's grab our hamburger by

475:47

its class and I'm just going to get rid of the border so I'm going to give it a

475:53

border of zero and a background color cuz I don't

475:59

like it being white at the moment I want to make it transparent so immediately that just

476:05

looks a lot better let's perhaps move it down a bit so it's in line with the

476:12

text margin top 20 pixels it's a bit much maybe let's say

476:20

15 pixels okay perfect so our hamburger is there however we already wanted to

476:28

appear if it's in Mobile not when it's in tablet or

476:34

desktop so we can do that using the media query so as a refresher we use the

476:39

media query here I'm going to use the same logic just so everything's consistent so what this means is that

476:47

anything that we hold on apply in here will essentially change

476:56

any element so for example the hamburger element or the element

477:01

with the class of hamburger it will apply this styling to anything above 500 pixels in width okay

477:10

so we know we don't want to see the hamburger when it's above 500 pixels so I'm simply going to put

477:17

display none refresh so now you will see our

477:25

hamburger disappears when we go over 500 pixels

477:31

great now we want the opposite for this right so as soon as we see the hamburger

477:38

we want the Navar to disappear so I'm going to do this by actually we need to make the nav bar

477:45

disappear up here so I'm going to get this nav bar and put that in here and above

477:54

this I'm going to make nasar display

478:01

now okay so there we go under 500 pixels

478:06

above 500 pixels under 500 pixels above 500

478:12

pixels great that is because the styling that we have for anything above 500

478:17

pixels involves the burger deleting Burger disappearing and the

478:23

Navar having styling and the opposite for when we're outside of this so when we're in Mobile form we are designing

478:32

mobile first okay so this is like the default and anything above that needs

478:38

specific styling yeah so that is mobile fast design is the most popular way of

478:43

Designing anything now as we do view most of our sites on

478:49

mobile okay so now we have that done let's actually get to implementing some

478:55

JavaScript to give our buttons some functionality and by functionality I mean I want there

479:00

to be a drop down if I click on the hamburger

479:06

icon so let's do it the first thing that we need to do if we remember from our JavaScript lesson is actually create a

479:13

Javascript file so just as before I'm going to create a directory called

479:19

source which is going to store our index JS file so let's add a file called index

479:26

JS if you if you've done it correctly you'll see a JavaScript icon show up this is because we are using the

479:32

JavaScript extension we are telling our IDE that we want to be working with

479:37

JavaScript I'm actually also going to put my Styles CSS file in here which is

479:42

going to break everything for now so we need to actually fix that so

479:48

we need to go in here and instead of linking to our Styles CSS I'm going to link to the source Styles CSS

479:58

and I'm also going to have to link our index GS file so I'm going to do this at the bottom of my file I need to do it

480:06

after any or all the HTML tags I need to put the script tag last so I'm just going to

480:13

put the script tag like this and as the source I'm going to give the path to the

480:20

index GS file so because we on the root of our project we need go into the

480:25

source file and get the index CS4 so that is now done once again if

480:31

you do remember from our introduction to javascripts with the very first lessons of our JavaScript section I don't have

480:39

to use the script T at the bottom I can also put it in the header okay so that

480:45

is an option two however if we do put in the header we need to have an event listener for this file so I haven't done

480:51

it for here but I do do it in a few tutorials so please go check out some of my game tutorials where I do that so

480:57

just be aware that there's two ways of linking your JavaScript bar okay now the first thing I want to

481:04

do is actually grab our hamburger so we can work with it so for this I would use document I'm going to use get element by

481:12

ID because our hamburger here does have an ID so I'm going to use

481:18

that so I'm just going to pass through the name of the ID and of course we need

481:24

to store it as something so let's store it as hamburger

481:31

button so there we go we've got a hamburger button that's great the next

481:38

thing we also need to grab is the nav uh unordered list itself so I'm going to go

481:45

const nav and then document once

481:51

again and then let's go back here does it have an ID has a class I'd rather just give it an ID we don't have to but

481:59

I think I want to show you um that you can have classes and ID so I'm going to do it and I'm just going to put nav list

482:08

because it's an unordered list so let's go back here let's store nav list

482:15

document get element by ID and then nav

482:22

list okay so we have those two things picked out the next next thing I want to

482:28

do well what do you think we need to do apart from save this file the next thing

482:33

we need to do is actually add an event listener to the button itself so if you

482:39

remember I would get the hamburger button and use add event

482:48

listener and we're going to be listing out for a click so once again I did not

482:54

make this up this is one of the options that we can pass into an event

482:59

listener and once we click it well we want something to happen we want to

483:04

toggle button so that is a function that we have not yet

483:10

written so once again what I'm saying here is I'm grabbing the hamburger element I'm then using a JavaScript

483:17

method of ad event listener to listen out for any clicks for anytime we click

483:22

the hamburger element itself so just here and if we do click it well I want

483:28

to toggle the button so let's actually write that toggle button function now let open up

483:35

our parentheses and there we go so now we need to actually grab the nav list

483:41

itself and then use a JavaScript property of class list so I did not make

483:48

this up I'm essentially going into my stylesheet okay and I'm going to search

483:56

for a class which at the moment doesn't exist I'm going to toggle once again I

484:03

did not make this up this is a method that will act on the class that we find I'm going to toggle the show

484:10

class so yeah we have not written it that's why we're getting a lot of red here we need to actually write it and I

484:17

want to attach it to the nav bar so I'm going to get the nav bar and

484:24

show and instead of having display n I'm just going to put display

484:32

Flex okay so now if we refresh and we click the button there we

484:39

go we are seeing our navbar show up it

484:44

hasn't been styled yet so don't worry but let's just make sure that works so nothing on desktop nothing on tablet we

484:51

are on mobile and then let's click so we're literally toggling the show class to be

484:57

on off on off display Flex display none

485:03

display Flex display none okay now let's get to styling this a little bit more so

485:10

once again I'm actually going to let's make sure to get rid of

485:17

the outline

485:24

so hamburger

485:32

Focus outline

485:38

none okay so that gets rid of that weird outline that we had before that blue

485:44

one now let's make sure that these display stacked so in here I'm just

485:50

going to put display actually no flex

485:56

Direction column there we

486:02

go and it's totally up to you how you want to style this so I think I'm going to keep it consistent with

486:12

uh most of the things in here so that's already looking better and perhaps let's

486:19

have the nav bar to the right instead so let's go back in here I'm going to move

486:26

this under here it's totally up to you how you want it but I think that's looking

486:32

good I'm really liking how this is looking so far you can of course really

486:38

sell this up however you wish so let's perhaps outside of here so in the

486:46

default so in the mobile view give our list items some styling so I'm just going to go back on

486:52

color white and there you go they have have

486:57

white background colors and now

487:03

padding 30 pixels so you can really go crazy I'm

487:09

going to say that I

487:18

want 5 pixels and 30 pixels okay so like

487:24

that bear in mind this will style anything um below here as well so just keep that

487:31

in mind too or you can simply go into the KN

487:37

bar like so and this will mean that only the list

487:44

items in the element with navbar will be styled in a

487:49

certain way so all of these list items because they're in the unordered list with the class of

487:56

navbar I'm going to be style that have a background color white so you will see these are uneffective because they are

488:01

not in the Navar even though they are list items so that's a cool uh tip for you

488:09

let's also give them maybe a border

488:14

radius border radius four

488:20

pixels and a margin of Zer

488:25

pixels which may margin of five pixels so there you

488:33

go styling really is a lot of fun you can really spend loads of hours on this let's just check it's working for here

488:39

and that styling is not applied ah it has been

488:45

applied that is because we need to once again go in here so nav bar this

488:54

item and then remove the

489:00

styling or we can just take the styling from up here that was our

489:18

default so apply that and background color transparent

489:32

zero pixels padding

489:40

zero padding padding 10

489:46

pixels okay so let's try that out again and yeah everything is

489:56

looking great great we have built our

490:01

responsive navbar let's carry on next up I want to talk to you about

490:09

the JavaScript date object the JavaScript date object

490:15

represents a single moment in time in a platform independent format date objects contain a number that essentially

490:21

represents milliseconds since the 1st of January 1970 UTC but enough talk I'm

490:28

just going to show you how it works first cuz I think it's better to show it

490:33

visually so first off I'm actually just going to use it as I would use it

490:39

normally so there we go console log I'm just going to talk you through this so

490:46

what I am using here is the Constructor so I'm creating a new date object so I

490:53

did not make this up this is a Constructor and it is how we we essentially get today's date but not

491:00

just today's date I've stored it as today so I can show you we get all of this so currently it

491:09

is Wednesday it is indeed 2:00 p.m. here over in London so we are granich

491:17

meantime that is the simplest way of showing you date it's pretty cool it will work wherever you are and you can

491:24

use it to get today's date now there are plenty of other things that we

491:30

can do so for example I can also

491:36

get the day cons day I can get today and

491:41

use get actually let's get the date first so

491:47

date console log date this will give me the date so as in

491:55

today today is the sixth of the month I can also get the day so once again I

492:03

would use today and get day which will give me the day of the

492:13

week so let's go ahead and consel up day and that will give me three because it's

492:19

a Wednesday so we do get them in uh integer values because you never know what language someone is speaking

492:27

we can also get the full year so full

492:32

year and I would just simply get today again and full

492:39

year such as that we need to get it get full year so let's console log full

492:46

year and we get the year 2021 there's so so many we can use as

492:53

well I'm just going to show you one more which is

492:59

hours and once again I would use today so what we've stored as new date and get

493:08

hours and console log hours to get the hours so today at the

493:16

moment it is 2: p.m. so essentially what we're working off is this okay that's

493:21

what we're using it's absolutely great I love using this it is very useful for so many so many reasons for example we can

493:29

use it to find out how much time we have until a specific time so like a

493:34

countdown so that is what I'm going to show you now actually one more I'm going to show you CU it is useful as well is

493:41

the iso string so ISO string date and I would also get today and to

493:49

ISO string because this is quite a popular one to use for programmers uh to really sort of standardize how we deal

493:56

with dates and there you go you get it as sort of like a numeric and alpha numeric value so that is a really useful

494:04

one a useful one to know too I use it for when I work with apis for example to

494:09

give something a time stamp okay so let's actually do this so say we want to build a countdown we want

494:17

a countdown to next Christmas okay so how would we do this

494:23

I'm going to actually do a countdown here so we know that

494:28

Christmas is should we do it in this format

494:35

here so I'm just going to use it in ISO string format actually so this is Christmas let's just

494:42

set it to 2021 so the 12 month and for me it's the

494:47

24th and let's just keep the time the

494:52

same I'm just going to put as a string let's clear that and then also need

494:58

to put this in the Constructor okay so now we have our

495:07

Christmas now if I have the console log and get

495:12

Christmas and just minus today or what we have stored as today in our console

495:18

log we get the difference in milliseconds okay so that is the

495:24

difference in milliseconds we can even use this create a timer to count down the minutes until next Christmas so

495:31

let's do this now const minutes equals so I'm just going to get

495:39

Chris should we store this as something okay const Mill

495:46

second to Xmas Christmas minus

495:54

today and then 2 minutes or we get milliseconds to

496:00

Christmas and divide the value by

496:07

60,000 this going to be a minus okay so that is exactly how many

496:13

minutes we have left I'm just going to get rid of that so it's less confusing console log minutes to

496:24

Christmas and now let's make our time so I'm just going to use I'm going to

496:29

pick out the purple element which I've already made as date so I'm going to use

496:36

I'm do up here don't need all this space so let's just condense it a little bit I'm going

496:44

to have cons display equals document query selector not all we just

496:52

need one and find the element with a class of date and then use

496:59

display inner HTML so the property of inner HTML to display the

497:08

minutes one thing I can do I don't have to do is change this to a string so I would use two string which is a

497:15

JavaScript method so maybe change this to

497:21

date display date display

497:34

sure what's happening here it's very strange date display inner

497:40

HTML let try text

497:45

content ah we're looking for the date class that's my fault okay so let's put

497:51

the minutes back in okay great great so we have our

497:58

minutes there we let's change we don't need to do this as a string then but we do get a very long uh number so let's

498:04

actually break it down I just want it to these minutes so once again let's use what we've done before my round this

498:11

time I'm just going to round it to the nearest minute let's go in here just going to

498:18

make the color of the font white and font size

498:28

pixels text align Center

498:37

oops so there we have it that is exactly how many minutes we have until Christmas

498:44

great so that is why I like the date if you check on this tomorrow it will

498:49

obviously change if we wait a minute as well this will go down that's exactly

498:55

why the new date is is so

499:00

cool so there you go you've seen it changed okay great uh I think this was

499:06

really useful I hope you enjoyed it I really like working with the date so yeah hope you learned a lot and I'll see

499:12

you on the next lesson Okay so we've come to the part

499:17

about the course where I want to talk to you about timers there are three timers that I want to focus on and I'm pretty

499:23

excited they are really useful let's get to it first up we're going to talk about the set

499:29

timeout the set timeout method essentially calls a function or evaluates an expression after a

499:35

specified number of milliseconds has passed what I mean by this is this we

499:42

use the set timeout in this syntax we essentially

499:48

pass through a function and then the amount of milliseconds that we need to pass or we want to pass in order to

499:55

execute that function so that is the syntax please keep that in mind we're going to use it in order

500:02

to display some text in our speech bubble after 3 seconds so what do we

500:11

need for this well we need to know what 3 seconds is so con

500:17

time and 3 seconds is essentially 3,000

500:22

milliseconds so that is the time we need to pass we already know what we're going to put through in

500:29

here so let's do that so set time out I did not make this

500:35

up okay and I did not make up the Syntax for it so we need to put in a function here and then the time because we'

500:43

stored that as a variable we could just as well put through 3,00 but we are

500:48

going to put through time instead and well what do we want to happen well we want to in a function so let's write the

500:55

function now show Bubble Show

501:02

text let's open up our C braces and this is the function that we want to invoke

501:10

so I'm just going to put it through there so at the moment it doesn't really do much let's just check this is working

501:16

though console log all good save and let's wait 3 seconds

501:28

let's clear it again so just change that save one 2

501:39

3 refresh one 2 three all good okay so

501:45

that seems to be working let's actually get our text Shing up so for this once

501:51

again I need to grab so I'm going to grab the bubble

501:56

so what I would need to do is document so I'm not making this up

502:03

use Query selector to search for the class so dot for class of bubble and

502:10

let's save this as speech bubble so that is essentially our speech

502:17

bubble now now in the function I essentially want to get the speech

502:22

bubble and in the inner HTML I want to put some text so let's

502:28

put the text hey

502:36

dude and safe and there we go we are indeed

502:44

getting the message hey dude I'm just going to start that out perhaps a little bit so it looks a little bit better

502:51

let's give it some padding 20 pixels

503:00

00 okay so there we go we are getting hey dude show up after one 2 3

503:08

seconds let's refresh that one 2 three hey dude brilliant so that is how we

503:16

would use set timeout to essentially make something happen after 3

503:23

seconds we could also make another I'm just going to do something else so

503:29

let's make the texture up after 3 seconds and after

503:35

10 seconds let's make the whole thing disappear so I'm just going to use

503:42

function delete

503:50

text so I'm just going to do it in the same way that we did it before set timeout so we pass through a function so

503:58

I'm going to pass through delete text and the time that we want this to disappear after so I could just put

504:05

10,000 milliseconds so is that 10,00 10,000 milliseconds so that is 10

504:10

seconds so that is another way of writing that just passing through the number itself and in

504:17

here just put speech bubble inner HTML and I'm just going to leave it as

504:24

blank so now 1 2 3 hey dude 4 5 6 7 8 9 10 and then

504:37

that disappears okay so that is pretty cool

504:43

another way you might see this written is actually instead of the function so I've taken out the function here and

504:49

written it like so I have seen it written like this as well so I'm just

504:55

going to comment this out for now I could essentially get this set

505:01

time out open up our parentheses so we need to pass through a function here and then

505:08

let's pass through 10,000 seconds again 10,000 milliseconds sorry and instead of just passing through the function like

505:14

this I could literally write the function so function invoke the

505:19

function CP curly braces and then put in

505:24

what we want to happen so so that is the same as me writing that I just written

505:30

in one line it is totally up to you as to how you want to do it I prefer this I

505:36

think it's more readable but of course this is an option too so let's check it

505:42

out 1 2 3 hey dude 4 5 6 7 8 9 10 and

505:53

there it goes okay so that is all I really want to show you

505:58

on set timeout I just want to maybe show you one more uh example with an exercise

506:06

that you can do yourself so hopefully you made a note of that if

506:12

you haven't paused here I want you to use the set timeout

506:18

to get rid of the whole bubble after 5 Seconds have a think about how you would

506:25

do this if you don't know or just want to see me show you the answer that's fine I'm going to pause here for those

506:32

of you who want to have a go at doing this anyway so I'll see you in a

506:38

bit so have a go at doing this yourself build out the HTML and CSS you need for

506:44

it to work you can simply just build out your own we are just testing if the

506:50

JavaScript that we wrote works okay so the way I would do this is

506:58

once again let's get our set time out we know that we want to pass through a

507:03

function after 5 seconds so 5,000 milliseconds but what is the function

507:09

right well I would get a function and let's call it delete

507:15

bubble and then let's open up our curly braces and then this time well I would

507:21

still need to go in so I'm still going to go in to our document

507:27

and use Query selector to find the div or is it a div

507:33

yeah div with a class of bubble so I'm just going [Music]

507:42

to get that and let's store it as bubble

507:47

bubble okay so delete bubble well I would get the bubble and then I would

507:53

actually use Style

508:00

display and pass through none okay so that's how we would do it and then let's

508:08

actually put this in here click save 1 2 3 4 5 and taada the

508:18

bubble has now gone we still have this little speech thing so we could have

508:23

actually maybe given this a class and let's just say

508:30

speech bubble save that and go in here and put

508:36

speech bubble instead and once again one 2 3 4

508:45

5 and the whole thing has now gone okay so I hope you now feel comfortable using

508:51

set timeout because I want to introduce another timer for you

508:59

next next up I want to talk to you about the set interval and how it's different to set time

509:06

out the set interval essentially calls a function or evaluate an expression at

509:12

specified intervals it will continue calling the function until the interval

509:18

is cleared or the window is closed so what this means is essentially unlike set timer which will invoke something

509:25

after X x amount of milliseconds this will keep calling the function okay it

509:31

will keep calling the function say every 3 seconds if we tell it to keep doing it and doing it and doing it until we tell

509:37

it to stop or we close a window down so I'm going to show you this with an

509:43

example set interval so let's open up our

509:49

parenthesis again similarly it takes a function and then the

509:57

milliseconds that we need M seconds that we want to

510:05

pass until we can invoke the function but we keep doing it over and over and

510:11

over again so I'm going to show you this now

510:21

milliseconds so let's keep that there I'm just going to comma that out so you can keep seeing it let's say for example

510:28

that I want to get some text in here again but I want it to keep flashing at

510:33

us so I wanted to say alert so conext equals

510:41

alert and then let's get an oton so I'm just going to use that for

510:46

the text now let's say that we wanted to keep going every 2 seconds so cons time

510:53

= to 1,000 milliseconds so there we have our two things that we need in order to get this working let's

511:00

write a function called show alert open up our Kylie braces and then

511:08

let's grab this again so we need to grab the bubble up here I'm going to say const

511:16

bubble equals document query

511:22

selector we need to find the bubble so we're looking for the class of

511:28

bubble now in the bubble and this time I actually want to append child so I'm

511:35

appending so in here here's my bubble I'm putting something in here okay so

511:41

I'm appending something inside uh before we do this actually

511:47

let's just check everything's working so I'm just going to console log

511:54

working and then let's get at our set

512:01

interval and then we need to pass through the function so show alert and the time so 2,000 milliseconds and save

512:11

and you will see here in the console

512:18

log 2 2 one 2 so each time after 2 seconds

512:25

we're going to another working getting printed okay and this will carry on doing that okay it will keep going and

512:32

going and going until we tell to stop so we know that is working now for each two seconds I

512:39

actually want to put a div inside here so I'm going to create a

512:46

div const text

512:53

display and I'm going to use create element another JavaScript method

513:01

create element and I'm going to create a div and with that text

513:09

display I want to give it the inner HTML of the text so that's a lot so I've

513:18

created a div we need document here

513:23

document so we need to make sure the document is before the create element so there's a lot of new things working with

513:29

here this is an advanced example that I want to show you so create element I did not make up document I did not make up

513:36

div I did not make up we want to create a div that we are storing as a text display and then is and then in this div

513:44

we want to put the inner HTML of alert and then we want to get the bubble and

513:49

use a pend child again I did not make this up this is a JavaScript method to

513:54

put in the text display after we have given it the text

513:59

so just going to refresh that and there we go two seconds alert alert alert

514:06

alert it will essentially keep on going and keep on going until we tell it to

514:11

stop we are appending we are essentially putting in so each time I'm putting in a

514:18

div here again and again and again and again that is essentially what I have

514:24

written okay but in code and this will keep happening over and over again so I

514:32

hope you've enjoyed this example let's finish off with a little exercise I'll

514:38

make it a lot easier I think it's good to start off with a complicated example and then start off easy so using set

514:44

interval I simply want you to print out in the console log your

514:50

name so how would you do this just going to clear this so it stops running

514:58

well you would get these set intervals so you do not make this up set interval is essentially a function that we can

515:05

use and then we pass through a function okay so a function and the time that we

515:11

want to invoke it so say we want to print our name in the console log I'm going to call this function print

515:20

name let's go a console log and then I'm just going to print Ana

515:25

so now I can pass through this function name and then let's invoke it

515:32

every 5 milliseconds so that is 5 seconds in

515:37

milliseconds let's refresh and see if that worked scale console log

515:44

here there we go 1 2 3 4 5 1 2 3 4 5 so

515:54

it's going three Now 1 2 3 4 5 and we'll

516:00

keep doing this until we clear it so that is how use set interval next up I'm

516:05

going to show you how to clear this interval using another JavaScript method okay so in this section we're

516:12

going to focus on clear interval we're going to use this to clear a set interval that we have running so let's

516:19

do it so here I have the set interval that we were working with before I'm going to

516:24

introduce another interval called clear

516:30

interval using clear interval will stop the time running in my example up here

516:37

so I would essentially stop this from running by assigning this to a variable

516:44

or an ID I'm going to call it I'm going to call it a const timer

516:49

ID okay so if I console log timer ID

516:57

well we would simply get just a simple number okay it's just an ID for

517:07

us to work with like so we can now use this ID that

517:14

JavaScript has given us to clear the time interval so at the moment you can see we're up to

517:21

4 if I essentially then get this timer ID and put it in clear interval

517:28

well we stop this whole thing from running okay so that's how that would

517:33

work but let's see it in a more real life

517:39

example okay so in this example I want to essentially

517:46

move my bubble down and I want this to happen every 1 second I want you to move

517:53

it down to around here okay and once it gets to here I want it to stop so I want

518:02

you to have a go at doing this yourself one thing that I will help you

518:07

with however as I do think it's important as in this exercise you're going to be manipulating the style using

518:15

JavaScript is that I'm actually going to give this speech bubble div so this whole

518:21

thing here that holds these two together a position AB absolute this is a tip we

518:28

need the position of the speech bow to be absolute in order to give it uh a top

518:34

left right or bottom pixel in the CSS so for example

518:41

if I was to do this 50 pixels then it would move up 50 pixels but without the

518:47

position absolute nothing will happen we need position absolute not

518:53

relative for this occasion we want absolute for this to work so

519:00

now can move it around wherever I want okay but that is its

519:09

default okay so we're going to be using this syntax we're going to be using set

519:15

interval to move the whole speech bubble down to around here we want this to happen every 1 second and once it gets

519:21

here I want to stop so that is your exercise please please feel free to have a pause here and think about it if you

519:29

don't really want to pause and you just want to see the solution that is what I'm going to do in a minute so I'm going

519:35

to let you have a go to anyway and I'll see you in a

519:47

bit okay so the way I would do this is like this I would of course get the set

519:53

interval and we need need to pass through a function and the milliseconds so we already know we want this to happen every 1 second so I've gone ahead

520:01

and put 1,000 milliseconds and let's write a function called move

520:08

bubble okay so we know that's going to be the function I'm just going to put it in here now in our function what do we

520:16

want to happen well as long as the height let's

520:24

say okay so let's get height here let height I'm start off with zero

520:32

and then I'm going to actually pick out this so I can use it so document query

520:38

selector once again I'm not making this up these as a JavaScript method that will allow us to look in here and pick

520:46

out the div with the class of speech bubble so we can use it in our JavaScript so class do for class and

520:53

let's store this as something so so we can use it in here I'm going to call it a speech

521:00

bubble so now if I got the speech bubble and use style so by using style

521:08

I'm essentially saying I want to get the style of the speech bubble I want to get

521:13

this I want to give it a top and let's say 100 pixels so I need

521:20

to this needs to be on a string actually

521:25

so they you go see I can move it around now from my JavaScript so I'm also going to use the

521:32

height to do this so instead of 100 here I'm just going to put height plus 100

521:37

pixels so at the moment it's zero it's up there cool let's maybe put it back where it

521:45

was like 100 now I want to increase this height

521:50

every 1 second so I would do this by essentially getting that height and

521:56

using the assignment operator to add I don't know 50 pixels to it each time and

522:03

then each time that happens I want to assign it to the speech bubble so I'm assigning the new height to it oh and

522:10

it's already going see they go

522:16

wo however it's not stopping so let's fix that if height dly equals say I

522:23

don't know 300 then we want to clear the interval and we clear the interval by

522:29

typing through or passing through an ID so we need to put this on an ID let

522:36

timer ID equal so that we can stop this set interval so I would then get this

522:43

and pass that through so

522:50

now it would stop there okay I'm just going to console log it to see what was

522:55

happening so console log

523:01

height 150 200 250 300 and

523:06

because height deeply equals 300 we clear the time ID and this has all

523:13

stopped I could all make make also make this you know when height is bigger than 300 if you're not sure if it's going to

523:19

be a specific amount that will essentially work too so when the height is bigger

523:26

than 300 that will

523:31

stop okay obviously it's stopped in a different location because we managed to get to

523:37

350 you can do bigger than or equal than and that will be the

523:44

same response it will stop in the same place great so that is a more

523:50

complicated and more real world example of how do you set interval it is one that using my games I use it in Doodle

523:57

Jump and Flappy Bird so if you want to check those out please do now would be

524:02

the perfect time to do so okay that's it for timing events I will see you in the

524:10

next lesson we have got to that stage in the course where I'm going to talk to you

524:15

about classes in JavaScript this part is a bit more advanced so I'm really

524:21

excited that you got to this part there's a lot of learning to do so let's get get to

524:26

it in JavaScript and in many other programming languages classes are the template for creating object I actually

524:34

like to think of classes as special functions okay so I know that doesn't mean a lot to you now but just as you

524:41

can Define function expressions and function declarations the class syntax actually has two components class

524:48

expressions and class declarations as a beginner this is a lot

524:53

so I'm going to break break it down for you now so one way to define a class is

524:59

using the class declaration to declare a class you

525:06

simply need to put the class keyword with the name of the class after it so

525:12

I'm going to put for example

525:20

rectangle okay and then we need to get a Constructor because this is how we're going to construct our rectangle we're

525:27

going to have a height and a width okay so this is the syntax we're

525:33

going to use we're going to introduce the this word this height equals

525:38

height and this width equals

525:44

width so you don't know yet but we've essentially made a sort of template

525:49

whatever we pass through into the class so for example if I want to make a a new

525:56

rectangle as rectangles come in many widths and many heights I would simply

526:01

use new rectangle and pass through a height so let's put 300 and a width of

526:09

100 so let's have a look at this we are making a new rectangle and essentially thanks to this

526:17

I know that this is the height and this is the width of the rectangle because we're getting this 300 that's passing

526:22

through it's going into our Constructor and it's going here and we assigning it to this height so this

526:31

whole classes height and the same for width so we're getting this value going

526:37

width this is now assigned to the rectangle width the rectangles width okay so

526:46

console let's STW this as something const new

526:53

rectangle so if I conso log new

526:58

rectangle I get Tada so I get a new rectangle based on what we wrote this

527:05

based on this template I have a new rectangle so now if I go rectangle

527:12

height I get 300 and if I go rectangle width I get 100 so it's a

527:21

template in fact I think the easiest way for us to really get to grips with this is to just do it over and over again so

527:27

one example of where I use this is Pac-Man I essentially make a

527:35

class and I call it a ghost class because I use it in order to make my

527:41

four ghosts so here we have our ghost

527:47

and then I use a Constructor and in it I pass to a name a speed of the ghost because each

527:54

of my ghosts travel at different speeds in my game and then a color of the ghost

527:59

as well and then a starting point of where I want each ghost to start at the

528:05

very beginning of my game and for this so I know I have a name so this name

528:12

equals name because whatever I pass into the Constructor and then need to assign

528:17

to this ghost's name okay this speed equals speed

528:26

this color equals color and this starting

528:32

point equals starting point okay so if I just conso

528:42

log the class of ghost nothing is going to happen I just get essentially what we

528:49

have written so very boring now say I want

528:55

Blinky con Blinky or actually maybe say

529:03

const no okay fine let's go Blinky and then I create a new ghost so

529:10

I'm using my class I'm using the Constructor so I need to pass through these things blink is going to have a

529:17

name of Blinky and then a color of

529:25

blue I think he's blue can't really

529:30

remember blue he's also oh wait we missed speed so it is important to keep these in the

529:36

right order otherwise different things will be assigned different things and it will be wrong he moves at a speed of

529:42

300 milliseconds and then it's starting point on a random board it's going to be

529:47

position four in onay okay so now con Blinky Inky once

529:53

again I would have to get a new ghost and pass through Inky so we

530:00

use the name we can also call this a class name as that's what I used it for in my game so then class name class name

530:09

so that we can use it to essentially assign class names in the

530:17

game whever ink he was that would be the color of the square where's in and then

530:23

let's give him a speed of 250 50 milliseconds he travels at 250

530:28

milliseconds uh which is faster than Blinky and then gave him a

530:35

color of actually this one's blue isn't it and then he'll start position

530:43

10 and the same for the other two so Blinky inky

530:49

pinky and cide so Pinky

530:56

applied let's just make these up well we know that it's

531:01

pink we know that is orange so this one is

531:09

red let's just say 20 and position

531:14

15 Okay so we've stored our ghosts we've created all these ghosts it's great we use a template to do this so now if I

531:22

console log if I want to find out what is blinky's

531:28

speed I get 300 because that is indeed Blinky speed if I want to find out

531:39

Clyde's starting point I get 15 and that is indeed correct so that is

531:47

how I used classes in my packman game it was super useful if you do do want to

531:55

take a moment to try our project with all you learned so far now is the perfect time after learning classes you

532:00

are all set to go and try learn Pac-Man so I really suggest you do Pac-Man at

532:06

this moment in time I hope you enjoy it or if you'd rather just carry on learning please carry on watching this

532:13

tutorial see you in the next lesson well done everyone you have just

532:18

completed your lesson on classes as promised I provided you with an external

532:23

project and that is my Pac-Man game in this game of Pac-man you will learn how

532:29

to use classes by building out ghosts and using each ghosts properties in

532:34

order to move them at different speeds start them off at different positions asking class names and much more if you

532:42

would like to try this project please click the YouTube card right here

532:49

otherwise let's carry on the choice is totally up to you you can save this project and comb back to it if you wish

532:56

as well okay so in this next section we're going to focus on keys or keyboard

533:02

events what I mean by this is we're going to link up the keys on our keyboard in order to move things in our

533:09

browser so let's do it so I think the best way to show you

533:14

this section is just by doing so let's get straight to it here we have our body in our CSS file I also just have a

533:22

simple index HTML file with with nothing much in it apart from our body and then

533:27

our index GS file let's just make sure to save all of these so the first thing I'm going to do is actually just make a

533:34

circle in here because it's the circle that we're going to move when we press a key on our keyboard so I'm just going to

533:40

give it a width of 100 pixels height of 100

533:46

pixels order radius 50 pixels and background color

533:54

Let's Go Blue Violet now let's actually put it in so

534:00

I'm going to just put it in here above the script tag as a div with the class of circle so

534:08

class Circle and there we go now the first thing I want to do is

534:15

actually pick out the element so that we can communicate with it so let's go

534:21

ahead and do that now const cirle equals document query hope you are used

534:28

to using these by now query selector I'm going to pick out the class of

534:34

circle now I am going to write a function that essentially if I press the

534:39

arrow to the left I'm going to move my circle a little bit to the left let's say 50 pixels to the left by grabbing it

534:46

and manipulating its style from the Javascript file if I press the arrow right it's going to go right if I press

534:53

the arrow up it's it's going to go up and if I press the arrow down well you guessed it it's going to go down so I'm

535:00

going to write a function for this I'm going to call the function control now through it I need to pass an

535:06

e for event okay so I can either pass through the word event or E that is totally up to us and then if event

535:18

key deeply equals and then let's say

535:30

Arrow left just going to console log this out

535:36

for now press left to see if it works and save now of course we need to attach

535:42

this to an event listener because we need to actually listen out to things happening so for this I'm going to use

535:48

document add eventness I'm going to listen up to the whole document this time so I'm not attaching it to the

535:54

circle I'm not attaching to the body I'm listening out to the whole document to listen out for any time there is a key

536:01

press up so once again I am not making this up key up is uh something that we

536:07

need to pass through into the event listener I could also have key down that will just mean that we're going to

536:12

listen out for a key down instead of when we lift our key up off a key on our

536:18

keyboard and I'm going to pause through control so I'm literally passing through

536:24

this function here so we're going to listen out to any time we've pressed the key

536:34

down so now if I press the arrow

536:42

left you will see press left this is the Syntax for doing it I

536:47

would need to pass through an event so I've written a function I've passed through an event

536:54

I can even put e for short that is totally up to us and if the key that I

537:01

pressed deeply equals Arrow left well we know that we have pressed the left arrow

537:07

on our keyboard okay so that is essentially how you

537:12

would listen out for Keys being pressed on your entire web page Okay so we've got our

537:19

Arrow left Let's do let's listen out

537:27

for an arrow

537:34

right console log press

537:40

right else if the key deeply

537:46

equals Arrow up console log

537:56

pressed up else

538:02

if arrow down oops

538:07

e key deeply equals arrow

538:12

down console log Arrow pressed

538:22

down okay so let's try it out let's make that deeply

538:27

equals hit refresh and just try pressing the arrows to see if you

538:35

get each one so up down left and right

538:43

perfect now I do want to mention one thing and that is uh the E key code so

538:49

this is one way of writing it I could also be very specific and have different different key so I can have the a key so

538:56

let's refresh that and if I press the a key this time well then I would get the

539:02

Press left so I can do anything I want really um just make sure to get

539:08

the spelling right on these before this before the E key there was something

539:14

called e key code in which you would have to actually get the key code for

539:20

the keys on your keyboard this would involve researching

539:25

what key has which code so for example I would have to research that the left

539:30

arrow on my keyboard has the key of the integer value

539:37

37 and that the key for right would be 39 so that's the key

539:45

code and then the up Arrow well that would have the key code

539:51

of 38 key code and then the arrow down would

539:58

have the 40 integer key code so once

540:04

again if I was to try this out on my

540:19

keyboard let got our console log up

540:27

you will see everything works exactly there same

540:35

however this approach is uh nearing

540:40

depreciation so we are moving on with this you might see it in a lot of

540:45

exercises I know I've used in the past for some of my projects so just be aware

540:51

that this um is now being replaced by by E key and then the string of Arrow left

541:00

okay so it's just something for you to know I'm just going to switch these back to the way they were so e key deeply

541:06

equals Arrow right an e key not key code deeply

541:13

equals Arrow up the last one e key deeply

541:20

equals arrow down so's just check that again to see if that works conso press right press up

541:29

press left press down perfect one thing you can also do is

541:35

make this a switch case so I'm going to talk a little bit about switch cases

541:43

now so here we've got the whole function written as an if statement however I'm just going to

541:49

comment that out for now because we're going to talk about the

541:55

switch the switch statement evaluates an expression matching the expression's value to a case clause and execute

542:03

statements associated with that case what I mean by this is this so we've

542:09

just written our uh Control Function with an if statement however I can also

542:14

use a switch statement which might be a little bit neater for this example and we can definitely use it so a switch

542:21

case would look like this I would use the word switch to let our JavaScript know that we are going to be writing a

542:27

switch case I will then pass through the common denominator of all these if

542:33

statements so that is the E key because the E key equals something

542:40

each time we are ready to do a switch case for this so if the E key deeply

542:47

equals let's write a case of Arrow left

542:57

but then we want to

543:04

console pressed left and break out of this okay we don't want anything else to

543:15

happen now let's do the same for case Arrow right so this is just the

543:23

same I'm literally rewriting all of this with a switch case it's the same we are

543:29

getting our e key and we are checking if it equals Arrow left and if it doesn't we are moving on to the next case so

543:35

Arrow right and then we want a console

543:41

log press right and again then break out of

543:48

this next up we have the arrow up

543:54

[Music] up and if it is an arrow up or if it

544:00

deeply equals the arrow up you want to have pressed up and break out of this

544:05

switch case and finally

544:10

case arrow down we want to console

544:17

log arrow press down break out of the switch case and finally we need a

544:28

default so as you will see it's expecting a default

544:34

case so let's go ahead and do that as a

544:39

default I'm just going to say console

544:50

log key not recognized okay so let's try that now let's get our

544:58

console log up refresh let's press the left key right key up key down key let's

545:05

press a random key and key not recognized so great we have now written

545:11

our if statement with a switch case which I think looks a lot

545:18

neater okay so I'm just going to get rid of this for now if you want to make a note of that please do

545:24

otherwise let's carry on so we have our console log saying the

545:30

right thing that's great however we're still not moving the circle anywhere so let's go ahead and do that now well I

545:37

would grab the circle and first off let's actually give our Circle a position of

545:44

absolute okay this is so we can know where it is on our screen at all times

545:49

so that is its default position I'm also going to just common this out

545:55

for now so we know what the actual default position is of our Circle and it's right there so now if I gave it a

546:02

left 50 pixels I would move the circle right by essentially giving it some left

546:09

spacing right here I can also do top 50

546:16

pixels and the same will happen so let's get rid of that for now

546:23

and let's get to doing that in our JavaScript so I would grab the circle

546:28

and once again I'm going to need like a y and an X AIS so I'm going to say let X

546:36

AIS equal let's just do c case s x AIS

546:44

equal zero and if circle is pressed

546:50

left so I'm pressing the left button Buton I need to give it some right

546:57

padding but because we're here maybe let's start off with the circle right so I'd grab the circle use

547:06

style and then to go right so I'm pressing the right button I will need to

547:12

add left spacing to

547:18

it that would be the X AIS plus pixels

547:23

because I need to pass through the x-axis before doing that I want to get the x-axis use the assignment operator

547:30

to add 50 to it so let's check that out let's click

547:36

our right button and there we go we are now

547:41

adding 50 to the x axis each time we press the right button so let's console

547:48

log what that looks like console log xais

547:56

refresh that this going be quite temperamental 50 100 150 200 and so on

548:03

and so on and so on so that is looking good now let's do the

548:09

left Arrow left so once again I would get the axis and this time I'm going to use the minus equals operator to take

548:18

away 50 pixels and once again assign whatever x- axxis is to to the left of our

548:26

Circle okay so

548:34

refresh left click right click right click right

548:40

click left click left so we're just manipulating the x-axis by adding 50 or

548:45

taking 50 away from it and then assigning it to the left of our Circle

548:52

okay that's all we are doing let's do the same for Arrow up and

548:59

arrow down now so for this we need a y AIS let y AIS equal

549:07

zero and then y AIS if we're going up where we need to manipulate the

549:15

top so let's start with arrow

549:21

down y AIS this plus = 50 and I'm going

549:27

to get the circle and use style to add a

549:33

top and xaxis plus pixels I'm adding to the top of mine so if I press down I

549:40

want to add 50 to the top of my circle and here let's just check that

549:47

out to see if that's worked down down down and now here I would - 50 to keep

549:55

taking away from the Y AIS and get the circle and you style top again to assign

550:02

the new y AIS plus the string

550:07

pixel so now we should be able to move anywhere oops y AIS Circle St top y AIS

550:19

Ah that's strange let's just copy that I don't know what's happened there fresh go

550:28

left down go up and there we go okay so we can now move anywhere

550:35

using our arrows and if we press another key well we get key not recognized okay

550:41

brilliant I hope that was useful for you let me try to get that whole function in

550:46

for you and we go if you want to make note of that that is how I would move

550:52

around a element on a screen don't forget to add the event listener and of

550:58

course store the values for X and Y

551:04

okay if you want to make a another of that too once again the position absolute is what is enabling us to give

551:11

a position to the circle each time now that I think we have that down time for

551:16

a little pop challenge I'm going to ask you to so I'm going to keep this here

551:24

hopefully you still have everything that we learned because let's go back into here I'm

551:29

going to change this to be the color yellow and let's change this to the

551:37

blue I don't like that color let's chose it another

551:43

color here we go light SE green so in this challenge I want you to

551:52

make our little friend here so let's give it some eyes I'm going to give it an ie

552:00

container display flex and then an i which is just going

552:08

to be basically a black circle so let's do that now 20

552:13

pixels height 20 pixels P radius

552:26

pixels and then it's go to here so here's a circle I'm going to

552:32

make another div which is going to have the class

552:38

of I [Music]

552:43

container and in it a

552:51

div with one IE

552:57

and another ey background

553:05

color black play Flex Flex Direction

553:29

I contain no okay and then let's

553:34

actually give these some

553:45

margin Marin left

553:53

Marin top okay so we have a little face

554:00

however it doesn't have a mouth using what we learned here so I'm just going

554:06

to get rid of this all of it how would you make our little guy

554:15

here smile if we pressed the arrow up and be sad if we press the arrow down

554:23

so this is a little challenge for you once again if you need to take down

554:29

the style that is it I'm just going to I've just commod outt for now but that is the whole thing

554:36

here pause here to take that down and our index HTML file just contains the

554:43

following content and don't forget to get your folder structure right with the

554:48

source folder containing the index GS and stylesheet

554:54

okay so yes using what we've just leared so everything about switch cases and keys I want you to make our little guy

555:01

here smile if we press the arrow up and be sad if we press the arrow down I'm

555:07

going to give you a while to do this so please have a go yourself feel free to rewind and look at the previous lesson

555:14

or do some research on the internet that is totally up to you have a go yourself don't worry if you don't get it because

555:21

I'm going to go through the answer with you together in a bit see you

555:34

soon okay so the first thing that I would do is actually style the face

555:40

itself so let's go ahead and make a

555:46

mouth this I would get a width of what's our width of our

555:53

Circle 100 pixels so let's go 70

555:59

pixels height 35

556:05

pixels background color I'm actually going to go yellow

556:11

I'll show you why because we're going to have a border so

556:16

border top left radius I'm going to have as

556:24

80 pixels and I'll show you why it all makes sense in a bit border just copy

556:31

this border top right

556:37

radius 80 pixels and the Border itself it's going to be 10 pixels

556:45

solid and black in color and so if I save that now let's

556:53

actually give a mouth here so I I and under the ey container I'm just going to put my mouth so

557:02

div with the class of

557:08

mouth okay so there we go it's it's very big I'm just going to get rid of the Border bottom though border bottom

557:16

equals Zer pixels it is a very large mouth let's

557:22

let's let's make it smaller okay so I think maybe we need 50 height

557:29

25 I make this 60 make that

557:34

60 okay so that's looking a lot better this is of course a sad

557:40

mouth so let's go back here and put sad

557:46

mouth and let's also give it a margin left of 15 pixels

557:54

okay I mean this is looking quite good it's quite a big mouth still maybe we

558:00

can do something about that should we move it up Margin topus 5 pixels okay so that's good

558:08

enough for me sad mouth we made a sad mouth now let's make a happy

558:14

mouth so I'm literally just going to copy this happy mouth keep that the same

558:20

but this time we want the bottom left and the bottom right and Border top

558:29

we want to disappear so that should be the same but reversed let's check that is the case at

558:37

the mouth perfect sad mouth happy mouth so let's SK with sad

558:43

first now let's get to writing a function just

558:48

like we did before that will control what we press so function control and I'm going to pass through an event just

558:54

like we did before I'm I'm also going to use the switch case so I'm going to switch out

559:01

the E key and open up our curly braces and for

559:07

case well this time we're just going to have Arrow

559:12

up and a console log press up to make sure it's working

559:20

and break out of this

559:28

case arrow down just going to have oops not

559:37

C console log

559:43

press down and once again break out of this and have a

559:50

default console log key not

559:58

recognized great so now let's hook it up to our event listener so we're going to grab the whole document use add event

560:04

listener to listen out for a key down on

560:10

and then if we do press a key down on our keyboard we want to invoke the Control Function so there we go should we check

560:18

it out press up let's refresh it press up up let down make sure you actually

560:25

click on here otherwise it mighton not work up down up down everything seems to be working fine so let's get to writing

560:31

some code so we would need to grab the mouth element so

560:39

document let query selector and let's grab I'm actually

560:46

going to give this an ID so ID mouth

560:54

so document well we could use Query selector we just need to tell this to look for an ID of

561:04

mouth const mouth equals okay so now we would grab the

561:11

mouth and I would use class list add so I'm going to add the style of happy

561:19

mouth so once again I did not make this up class list and add I did not make up

561:24

I'm going to add the happy month class I don't need that because you already know we already to the JavaScript it's a

561:30

class we want to add and I want to first off remove any other class L there so

561:36

class list remove sad mouth so I'm going to remove

561:42

the sad mouth going add the happy mouth refresh click on our browser and press

561:48

up and there we go we've done it and let's do the same for sad so once again

561:54

I'm grabbing the mouth I'm using class list to remove anything so remove the

562:00

happy mouth because we don't want the Happy mouth there and once again I'm use class list

562:07

add to add the sad enough let's do it fresh happy sad happy

562:18

sad happy sad brilliant okay so thanks so much for doing this challenge with me

562:25

hopefully you've got something similar this is of course not the only solution there's so many ways to solve it this is

562:30

just one way that I've chosen if you chose to use key code or if you chose to use an if statement or perhaps you chose

562:37

to do it differently than adding and removing a class list that is absolutely fine too please do share it with me on

562:43

Twitter I'd love to see your Solutions and let's carry on

562:53

okay next up I'm going to talk to you about sort the sort method sorts the elements

563:00

of an array in place and returns a sorted array so that's what we're going

563:05

to be using it for sort literally sorts arrays the default s order is going to be ascending so let's check it out it is

563:13

ascending based on the UFT 16 code unit values what I mean by this is that it's

563:20

going to sort it alphabetically so I'm just going to create a const for

563:25

us let's have con I don't know

563:32

planets and then I'm just going to put a few in Mars Jupiter let going capital letters

563:40

because you know they are planets they are important Mars Jupiter

563:48

Uranus Earth so this is going to be super easy I would literally get the planets and

563:55

use sort sort on them like so so now if I

564:03

console log you will see my arrays come back to

564:10

me in alphabetical order so that is pretty

564:18

cool we can also use sort on numbers so it works on strings and it also works on

564:24

numbers let's do it with some ages so let's get some ages up I'm going

564:30

to go constant ages equal and then let's have some random ages so 32 45 21 13 78

564:43

99 and there we have it I have now sorted my array of numbers so that's it

564:49

for sort let's carry on okay now that we have done the sort

564:56

JavaScript method I think it's the perfect time to talk a little bit about algorithms if you're interested to learn

565:02

a little bit more about algorithms and computer science I have the perfect YouTube playlist for you please go ahead

565:09

and click on the card right here to view some of these videos otherwise let's carry

565:15

on in this next section we're going to look at the includes JavaScript method

565:23

the include JavaScript method determines whether an array includes a certain value among its entries returning true

565:29

or false as appropriate so again I'm just going to use an array for this so

565:35

I'm going to make an array of

565:41

books and in it I'm going to have a book called

565:46

Al a book called five of Pi

565:53

and a book called Power of Now so we have three

566:01

books in our array I can use the include JavaScript method to find out if

566:07

something is included in an array so I would simply do it like this

566:14

I would get the array itself and if so this I'm not making this up this is a

566:19

JavaScript method includes is a JavaScript method and if that array includes the book I'm

566:27

looking for so let's put through Alf well this will have a return of a true

566:33

or a false so if I console

566:39

log books includes Al I will get a true if I search for perhaps the

566:47

book sapiens I will get a false so what I

566:52

would really do is store this as a variable I'm going to have the const

566:59

is in books and then save this statement like

567:08

so so now I would simply use this and I can use that variable

567:14

wherever I want in my code so at the moment ISM books is false however if it

567:22

was elf is in books would be true so that is

567:28

how we would use includes I just want to take a little bit of time to talk to you about contain because contains is

567:35

totally different to includes in the way that we can't use in arrays we use contains so even though it looks like

567:43

includes it is used for completely different purposes I'm going to show you how now so contains if I want to find

567:51

out out if a node exists on a specific node I would use contain what I mean is

568:00

if I want to find out if the body has a child that has an element with a class

568:06

of circle I can find that out so as a beginner it could be quite easy

568:13

to get the two confused but I'm going to show you how they are different now so I'm going to actually grab the body so I

568:19

need to grab the body I'm going to go document query

568:27

selector and select the body so I'm literally selecting the element of body

568:33

and storing it as body and called Circle once again I'm going into my document

568:40

and I'm going to find the element with the class so dot for class of

568:48

circle now I can use includes to find out to get the

568:54

body find out if the body contains

568:59

Circle and I would get a true this is because we know that is true okay so

569:06

that is one way that I would use contains the body does indeed contain a

569:12

element with a class of circle if I was to get rid of this class let's replace

569:17

it with I don't know Square

569:24

we would get a false and let's put that

569:29

back and there you go so that is how you would use includes the first

569:35

one and this is how you would use contains I hope that makes sense I just

569:41

thought it was very useful for us to clear this up now just in case you see both and try using them interchangeably

569:47

that will that will not work

569:54

in this next section I'm going to show you how to create elements from our JavaScript directly let's do

570:00

it the create element method when attached to a document creates the HTML

570:06

element specified by tag name what I mean by this is I can actually create

570:11

elements in our JavaScript just like we would if we created a

570:19

div like this by writing it out in our

570:24

HTML so I'm going to do this now I am literally going to recreate

570:30

writing a div okay so to see it in our browser I'm

570:36

actually going to have to give a div some styling so I'm just going to go simple width 100 pixels height 100

570:44

pixels background color

570:50

blue okay so to do this I would actually have to

570:55

grab our document and use the JavaScript method of create elements so I'm not making this up I'm going to create a

571:03

div and put it in a string now we've created a div however

571:09

we can't see it yet I'm going to go ahead and store this as a square so our

571:14

JavaScript now thinks that the div we created is a

571:19

square and I'm going to grab the body so

571:24

con body equals document query selector and I'm going to look for the

571:32

body tag in our HML file if I console log out

571:39

square well you will see exactly that a div that we created so we' created a div

571:45

we stored it as a square we now want to put it into our body so to do this I

571:50

would use body append child so once again this is not something I'm making up aend child is a JavaScript method and

571:58

I would put through the square and there we go you will now see our Square in the

572:06

browser that is pretty cool okay one more thing that I'm going

572:12

to do is actually create an image this time I'm going to do this so we can move on to the next section swiftly so once

572:21

again you will see there there is nothing here I've literally added a div that I've styled to be a blue square

572:28

into our body okay and I've done this all with JavaScript the next thing I want to do

572:34

so I'm actually going to actually let's keep that for now let's create something

572:40

else so this time I want to create an image tag so once again I would get the

572:45

document and use create element to create an image tag

572:53

let's store this as con image a console

572:59

log image well you will indeed get an image tag a closing an opening and a

573:04

closing image

573:10

tag now let's go ahead and put that in our body so once again I would get the

573:15

body which you've already got and use aend

573:22

child to put the image in there now if I console log our body CU

573:29

obviously the image doesn't have any styling yet the body itself will have an image

573:37

tag and a div tag great so that is how

573:43

we use create element I've Ted this up perfectly because the next thing I want to show you is something called set

573:49

attribute and get attribute so I'm just going to keep this here I'm going to keep I'm going to take

573:56

rid of that console log I'm going to keep all these

574:02

together and those two together so we've appended a square and we've appended an image and this is so we can see what's

574:08

going on in our body the next thing I want to show you is something called set

574:14

attribute just make sure we spelling it correctly so the set attribute method I

574:21

sets a value of an attribute to a specified element if that attribute already exists the value is updated okay

574:30

so that is what we're going to do we're going to set a attribute to our image

574:35

I'm going to show you how to do that now so the first thing I want to do is

574:41

actually get an image so I'm going to create a folder called images I'm going to put that into my source folder and

574:49

into my images I'm just going to drag and drop an image I have so I'm going to

574:55

find search for the head shot of myself and I'm just going to drag it into the

575:00

images folder so

575:05

now if I grab the image itself and you set

575:11

attribute I need to pass through two things I need to pass through the key

575:16

and the value so I would do this by writing the source and the path so I'm

575:23

going to go into the images folder and grab the headshot

575:31

gy okay now I would actually have to put the source directory before this this is

575:38

because our Javascript file gets sent to our index HTML file which is in the root

575:43

of our project so we do need to put that Source folder in there too that is how

575:49

we would get the images showing up in browser so that is how I use set

575:55

attribute I can set any sort of attribute I want if I console log actually we can use the body too so if I

576:03

click into the body you will see I have indeed created

576:09

a div up here I've also created an image tag and I've also given it the I've set

576:17

these attributes I've set this source and this Source images head shot through

576:23

JavaScript so that is pretty cool that is how you can use set attribute and essentially how you can make out the

576:30

entirety of your htl elements using

576:37

JavaScript you can also use something called get

576:46

attribute okay so if I want to get const uh image I can can essentially get the

576:54

image and use get attribute and search for the

577:02

source ah we've already declared that so const image

577:09

path and now if I console log image

577:16

path I will literally get the value here

577:21

so get attribute we search for an attribute so it's going to search for this and get that for us okay so if I

577:30

for example did this image set attribute and this time I did data ID and I set an

577:38

ID of four and I used image get attribute so const get

577:45

ID or just image ID not get image ID get the image use get

577:54

attribute and this time I'm going to get the data ID of the

577:59

image and then console log image

578:06

ID I will get the number four okay so hopefully that was useful I

578:13

think that was the perfect time to start with a project let's do it well done

578:21

everyone for making it to this point in the boot camp in this section we are going to build out a full project I will

578:28

be showing you how to build a simple memory game in which you have to win by matching all the cards on the board

578:35

building this game will help us practice everything we have learned so far in regards to event listeners operators if

578:42

statements storing values and variables as well as a few new things too I will

578:47

also be showing you how to use a code editor program such as vs code or atom

578:53

in order to store your projects on your personal device just as you would as a professional

578:59

developer this section will take roughly 1 hour I hope you do enjoy it please do

579:05

share your finished projects with me when you have finished them on Twitter on YouTube on Instagram I would

579:10

absolutely love to see okay so it's come to that part of our course in which

579:16

we're going to take everything that we have learned so far in order to create our very first project that includes

579:22

JavaScript HTML and CSS so what are we waiting for let's get going in this

579:30

section I'm not going to use the ID I've been using so far this is because I want to show you how to use uh code editors

579:36

such as atom or vs code in order to actually store projects as a

579:42

professional software developer would on GitHub so to do this I need to talk to

579:48

you about those code editors first so just like the code editor that we've

579:53

been using that's been hosted on the internet we can have our own code editor downloaded onto our laptop this makes

580:00

our lives a lot easier when dealing with projects and saving them onto our computer I'm going to show you which

580:06

code it is I prefer to use so atom IO is one of them you can choose to use atom

580:12

IO simply by downloading it here or you can use VSS code as I am using a Mac

580:21

I would recommend downloading VSS code for Max so go ahead please choose one

580:27

it's absolutely up to you which one you choose I'm going to choose to download vs code so simply click the download button

580:35

and that download should start in your browser once it has finished I've

580:41

actually already gone ahead and downloaded this for myself but you would simply open up the extension

580:52

and follow the download process until you have it on your computer so I'm going to ahead and double click that and

581:00

the VSS code editor should start up for me just going to get rid of that here

581:05

and get rid of that here so now I have vs code on my

581:12

computer this is not hosted online this is on my personal laptop and it's where

581:17

I'm going to be making my project for this section so the first thing I'm to do is actually

581:23

just make this a little bit bigger for us so we can see what is happening now I'm going to click this

581:30

button right here so I'm going to open a folder and I've already made a folder

581:37

where I saw most of my projects this is personal projects and in here I'm just

581:43

going to create a new folder and I'm going to

581:48

call it memory

581:54

game just like that and click save so now we have a folder called memory game

581:59

where we're going to sort all our files let's click

582:06

open and there we go this is step

582:12

one so we're going to be storing all our files in here just like we did before we need to set up this project so we can

582:19

start building in it so I would start off by just creating an index HTML

582:25

file and then a source directory and in it my Styles

582:33

CSS and my app or index JS we can call it whatever we want the extension should

582:39

be JS for JavaScript CSS for cascading stylesheets and the index HTML so that

582:47

is the folder structure that we have been working with and one that I'm going to use for this

582:53

lesson once again we will need to get the Boiler code for the index HTML setup

582:59

as the first step so to do this I'm just going to get the doc

583:07

type and then I'm just going to use the HTML tag I'm going to set the

583:17

language as English and this is just some boilerplate code

583:24

for our HTML file then include a

583:32

head use a meta tag charet

583:39

UTF 8 so just like we did when we set up in the very first lesson is the same

583:45

boiler plate code the title

583:51

let's put memory

583:57

game and then that's our head done for now and then we need a

584:04

body so that is all we need for the boiler plate code the next thing I want

584:10

to do is actually link my sty sheet so I'm going to

584:15

link making a closing tag and have sty

584:24

sheet HF Styles CSS but it's actually in the

584:30

source folder so let's go ahead and get

584:36

that and then finally I'm going to link my script tag as well so I'm just going

584:42

to do that here script tag

584:51

and the source is going to be I'm go into the source folder and get

584:57

the index JS file so I can put that at the bottom of my body or I'm going to

585:03

use the Dom content loader so I'm actually going to choose it that way I'm going to put it in my header so save all

585:09

these files and then in my index JS file let's actually make this a bit smaller

585:14

too I'm use the event listener to check if all of our HTML has loaded

585:21

so I'm going to go and use document add event

585:27

listener Dom content loaded make sure to spell it

585:33

correctly otherwise you will get all sorts of errors and then just an arrow function

585:40

because this is a function we're passing through okay the event we are listening out for and the function that we want to

585:46

invoke if we hear it so that is how how event listeners work if you

585:55

remember okay so that is looking good just going to make it a little bit

586:01

bigger for us just in case anyone can't really

586:07

see okay so now it's time to start writing our JavaScript but first off I'm

586:15

just going to make a grid here

586:23

so the only thing we really want in here so let's get rid of that cuz we can't have it in two

586:32

places I'm just going to put a div with the

586:38

class of grid and that is where all the Magic's going to happen okay I'm also

586:44

going to have a score so let's put an H3 tag

586:51

that'll say the score and I'm going to use something called a span tag I don't think we've used it before but the span

586:57

tag will essentially allow me to cut into this H3 tag and in it I'm going to

587:04

put these score so ID score or result we just put

587:12

result okay so there we go we have a div with a class of grid

587:21

and a score now if I open this on the browser we would only see the red score in here

587:28

so perhaps let's actually style up the grid so I'm going to grab the class of grid so once again dot for

587:36

class and I'm just going to give the grid a width of 400 pixels and a height

587:43

of 300 pixels let's also give it a border maybe border solid black one pixel so we can

587:51

see it and that is it so now to view this in my

587:59

browser I would simply go to the index HTML file and copy the path not the

588:05

relative path with the whole path and I would simply paste that into my URL and

588:13

there we go just like before and then we can inspect the Page by right clicking

588:21

here so we can see our console log

588:27

brilliant this is looking good let's get to writing some JavaScript so let's go

588:34

back to our visual code editor and go into the index JS

588:43

file now the first thing I want to do is actually create an array of all the

588:50

cards cards in our memory game so I'm just going to get some card

588:56

options what kind of card should we have let's make a card array first so cards

589:01

we'll just call it cards we don't need to call it cards array and open up our

589:08

array now I want to have some objects so here's my first card object and each

589:14

object is going to have a name so this card is going to be friiz

589:22

and it's going to have an image of some fries so for this I've already decided I

589:28

want images in here because all the cards are going to have images all 12

589:34

cards so feel free to take mine if you wish just go to my GitHub repository and

589:41

find the memory game go into the images you can just

589:48

download all of these so I'm just going to so if you click it here you can

589:55

download the first one so this is going to be my blank image save's image blank

590:01

let's save it in downloads

590:08

save let's get the cheeseburger download save image as cheeseburger and

590:16

downloads as a PNG image great that's good

590:22

fries save image as fries PNG and downloads fine need a few more to

590:31

go save image as hot dog so that's four so far we have 5 6

590:39

78 ice [Music]

590:44

cream save

590:51

Shake save image

590:59

Pizza image so I've already gone ahead and made the image the exact sizing that

591:04

we want so we don't need to do any CSS trickery and then just a plain old white image so that is going to be like a

591:10

blank card white image Okay so we've got all the images that we need download for

591:15

our game now back in vs code just like before in my Source folder I'm going to

591:22

make an

591:28

images folder and in here I want to put all the images okay so I'm literally

591:33

going to go to my download file and get all these

591:42

images and just put them in to here like so so that was pretty easy

591:52

let's go ahead and put the first image in so I would go at the moment we are at

591:57

index GS file so it is in the same folder as the images so I would go into

592:04

the images and grab the fries PNG like so so

592:10

we've created our first card let's go ahead and do the same for the others so name let's call this one

592:18

cheese image

592:27

images so the cheeseburger so the object with the name cheeseburger is going to have the cheeseburger

592:36

PNG what's next we're going to do the ice

592:42

cream and that image is of course going to be we're going to go into our images folder and grab the ice cream PNG

592:57

name Pizza make sure that is a string we're just keeping everything

593:04

extremely consistent this is an array of objects that we are

593:09

building so images pizza.

593:16

PNG name milk

593:21

milkshake image into the images folder and just grab the

593:27

milkshake and then just a few more we've got a milkshake we have a hot dog as well so

593:34

name hot dog image into the images

593:41

folder we grab the hot dog okay so we have our six cards now

593:50

because I want to essentially mix and match the cards so we need to have two

593:55

ches beggers two ice creams two pizzas we need to essentially get everything and put it in Array again so before we

594:03

do this I'm just want to explain one thing even though we are in the Javascript file at the moment so the way

594:10

to get the images would be in fact to go to the images and get the

594:15

following uh URLs I would actually need to act as if I in the index HTML file

594:22

okay this is for when we build stuff on the internet just make sure so I'm just going to add that using

594:30

command D I'm going to command D and select all the images I'm just going to put source and images at the beginning

594:37

okay so that is important you always have to act as if you are in the index HTML

594:43

file so there we go now once you have done that I want you to essentially grab

594:49

all six of these objects and put them in again great okay

594:59

so now if we console log

595:07

cards and go to our and go to our browser let's get rid

595:14

of these now you will see 12 cards that all have an image part path and have all

595:21

have a name now we need to mix them up before we start putting them in our grid

595:27

so let's do that we can do this with uh a JavaScript function that we have

595:34

learned already along with math random so how do you think we would sort

595:41

this cards array okay what do you think we would do to

595:48

get this cards array and sort it

595:56

randomly well I would use sort and this is a bit of a cool trick I would open up

596:03

our function and then I use 0.5 minus math

596:13

random how this works is that math random essentially if you remember returns a random number between 0 and

596:21

one or just under one so if that random number happens to give you a number less than 0.5 then you get a negative number

596:28

and if it's over then you get a positive number and we are sorting things absolutely at random we're sorting the

596:34

whole array at random okay if that doesn't make sense please take the moment out to have a think about that

596:40

research it it is a sort of just math problem it's not really a programming problem so I'm not going to focus too

596:46

much on it have a go at researching it if you don't understand but it is phical trick definitely make a note of it if

596:52

you ever need to sort an array randomly this is your guy okay so now if I console log cards

597:01

I'm just going to take this away and put it here go back to our browser and

597:09

refresh let's see you will see that indeed these are now randomly sorted

597:15

because we didn't start with ice cream did we so you will see that FES us first

597:21

and we have randomly sorted our array let's carry on okay the next thing

597:30

I'm going to do is actually put these randomly sorted Cards into our qud so

597:35

let's do it well as you know we would use Query selector for this so I would

597:40

use document query selector to essentially search for a

597:47

class of GD and let's store this as a

597:53

grid so there we

597:58

go now I'm going to use JavaScript to essentially create our board so I'm

598:04

going to use a function for this I'm going to write function create board and in it we are

598:12

wonderfully going to use everything that we learned so far about creating elements appending elements setting

598:18

attributes and so on and so on so just going to put that back to

598:23

where it was I'm also going to use a loop so I'm just going to use four let I equal

598:33

Z now as long as I is smaller than the card array

598:43

length I want to increment I by 1 okay so this is obviously quite far back now

598:49

I feel we learned about for Loops quite a while ago but that is your Syntax for a for Loop now I need to create an image

598:57

so for each time so we've got 12 items in our cards array okay now for each time so 12 times

599:08

I want to create a element so I'm going to grab our document and use create

599:13

element and I'm going to create an image make sure to put that as a string

599:20

and let's save this as const

599:26

card so a singular card that is a singular card now let's get our card and

599:33

use set attribute as we learned in our lessons to set it a

599:39

source and that source is going to be if we think about this each card is going

599:44

to essentially have a blank version of itself so I'm just going to create a blank version of everything so we're

599:51

going to go into the source folder into the images and grab the blank PNG so that

600:00

one there and then I also want to give each

600:06

card a data ID so once again I'm going to use set attribute and along with Source I'm

600:12

going to set it a data ID so again that's something that we leared in our HTML section and the data ID of each

600:19

card is going to be I so the first card is going to have an idea of zero the second is one 2 3 4 because we are

600:26

looping over so we're going to give each card its own individual data ID starting from zero and ending at

600:35

11 the next thing I want to do is actually grab our grid and

600:42

append the Cod so let's talk through this again our

600:49

function now is going to actually create a card give each card the attribute of

600:58

the source and the image path it's also going to give it a data ID and then we're going to put the card into our

601:04

grid so let's go ahead and invoke that so create board click

601:11

save Fresh our board and there we go we now have 12

601:17

blank cards because that is the image that that we use for blank and if I now

601:23

inspect so let's go in here our grid you will see exactly what we have done we

601:30

have created let's make this a bit smaller actually we have created an image tag

601:37

we've given it using set attribute as source and the path to the image itself

601:43

and we've given each one a data ID that is pretty cool in itself I think

601:49

everything that we have learned so far is really coming together so I'm really glad to see it uh looking like this

601:56

let's carry on the next thing I actually want to do is actually add an event listener to each one of these cards too to listen

602:03

out for if we click it so before we add the card to the grid

602:10

I'm just going to grab the card one more time and use add event listener so once

602:16

again we did not make this up the add event listener to pass through a click which we also did did not make up we're going to be listening out for a click on

602:22

that specific card and if that card is clicked we want to write a function or

602:29

let's call the function flip card so let's get to writing that

602:40

function function flip

602:45

card oops let's make sure to keepy that at the bottom and there we

602:52

go again just keep that there okay so what do we want to happen

602:58

when we flip a card well I want to get whatever card we flips data ID so let's

603:07

do this I'm going to use this because we are talking about whatever card that we

603:12

are currently working with that is how we use the this keyword I don't think we've done enough on this keywords but

603:18

just know that what whatever card we have flipped whatever card we

603:24

have here we're talking about that card so this get

603:32

attribute so we're going to get the attribute this time and the attribute we want to get is the data

603:38

ID so we want to get this thing right here of whatever

603:44

card we clicked and let's store this as something so let's store it as

603:50

let card ID cuz that's what it is it's an ID now once we have that ID what do we

603:58

do with it we need to store it somewhere so I'm going to make an array

604:05

here I'm going to call it let cards Chosen and just leave it as an empty

604:12

array for now because there's nothing in it we haven't chosen any cards to be checked against each other so there we

604:19

go let cards chosen I'm then going to get that cards

604:26

chosen array and push so again this is something that we learned we're going to push into that array the card's name so

604:35

we do this by getting the cards array and passing through the card

604:41

ID okay so perhaps it's best to console log

604:46

something for now so at the moment when we click a card we are getting that card's ID and storing as card ID we're

604:54

then going to use that card so say we click the card ID three we then pass

604:59

that three into our cards array okay so I'm going to console

605:09

log cards card ID so at the moment this is

605:15

all I really want to happen let's save

605:22

console let's click on a card so I've clicked the 0 one 2 three card with ID

605:29

or data ID three and I being returned the third

605:35

card in whatever our random array is at the moment so our third card is a

605:40

milkshake if I refresh this and I click again it'll be Fri okay so we're getting

605:48

an object back however we just want to store the name we've decided okay I just want to store the name in my card chosen

605:55

array so I would do that by grabbing the name okay so now in our card chosen

606:03

array I'm actually going to console log cards

606:13

chosen refresh so that's my array I'm going to click on a card click on a card

606:19

again click on a card again uh we need to actually put this console log in our function so after we flip the card let's

606:28

console log the cards chosen array refresh click on a card so we clicked on

606:34

the hot dog we put hot dog in the cards chosen array we clicked here so we clicked on a cheeseburger and we have

606:41

also put cheeseburger in our chosen cards array if I keep doing it I'm just going to keep adding to the chosen cards

606:48

all right however we don't want this we only want

606:53

to get two items in the cards chosen array and compare the two and if those

606:59

two don't match well we want to clear the cards chosen array and start again

607:04

so I can do so like this so we are indeed getting the cards

607:16

Chosen and pushing through the name let's get rid of this console log here

607:21

going to get rid of that for now too I'm actually also going to do the same for the card ID so cards chosen

607:34

IDs and push well I can actually just grab the card ID itself so there we go

607:40

and let's make an array let cards chosen IDs equal so we're stor

607:49

the names in one and we're storing the IDS in one separately

607:58

okay and of course if we click the card we want that card to flip over before we move on so once again I'm going to use

608:05

this set attribute and to whatever card we click I'm going to set the

608:11

attribute from so we're going to overwrite because at the moment it's attribute is set to this we're going to

608:16

overwrite it okay we're going to overwrite it by going into our array and

608:22

grabbing the image so once again I'm going to get my

608:28

cards I'm going to pass through the card

608:34

ID and get the image

608:40

great let's check it out refresh click and there we go click click click click

608:49

click click pretty cool so at the moment

608:54

I actually want them to uh refer back if two haven't been

609:03

selected so I can do this with an if statement

609:09

if cards chosen or you can do it by D but essentially if either of those

609:16

length D equals 2

609:24

I'm going to put a set timeout so we learned about set timeouts a set time out essentially invokes a function after

609:31

certain amount of time has passed so after a certain amount of time pass if there are two cards chosen in our array

609:39

I want to check if those two cards match and if they match take them off the

609:46

board and if they don't match flip them back over but I'm going to do that all in one

609:51

function so I'm going to write a function called check for match and after we do get to I'm

609:58

actually going to wait 500 seconds cuz I don't want to be instant I want it to be like after a while I want them to be

610:05

checked for a match and if they do match take them off the board and if they don't flip them back

610:12

over so I'm actually going to move this create board to the end my

610:17

file and run write a function

610:24

check for

610:32

match okay let's get a checking for some matches in this check for match function A lot's going to be going on okay we

610:40

need to make sure that people can't double click on the same image for one otherwise what will happen

610:47

is well if we con log here CS chosen

610:56

IDs CHS cards chosen IDs so if I click here I get the ID of

611:04

three but there's nothing stopping me from pressing that over and over again which obviously doesn't work because

611:10

then we could check we could essentially double click something and we would get a match so we need to prevent that from

611:15

happening we need to do that in our check for match

611:22

function so if

611:30

chosen or card chosen IDs and the first

611:35

item deeply equals or equals it doesn't really matter cards chosen

611:42

IDs and the second item well let's just get an alert

611:49

that says you have clicked the same

612:00

image and let's flip both of them back to be blank so

612:06

cards actually let's we have to grab all the cards again so I don't know why this

612:11

formatting is happening but I don't like it um const cards equals grab all the cards

612:20

from our display query selector all I'm want to grab all the images and

612:28

saw them as cards we've already declared cards once so to make things less confusing I'm actually going to call

612:33

this a cards card array so now let's find everywhere else

612:40

I use cards okay well this should be card array oops card array

612:49

card array can we card card

612:59

array card array

613:07

card okay great just to make things less confusing

613:14

because I need to regrab all those images now and if the the cards chosen ID and

613:20

the second card chosen ID so the two IDs that are currently in my array are the

613:26

same you have clicked the same image I going to flip the card back so I'm

613:32

actually going to store this something

613:38

to H option one ID

613:49

just so we don't have to keep writing it out I'm just going to make our code a bit neater option 2

613:59

ID cut that and now I can just check if option one

614:07

ID equals option 2 ID well then we go into

614:12

our cards we get option one ID and we set

614:19

attribute to be source and we're going to set it back to blank so I'm going to

614:24

go into our source folder get the images and get the

614:30

blank

614:36

PNG and once again let's do it for the second one so

614:41

option to ID as well okay let's check this

614:47

out fresh click click you have clicked

614:52

the same image okay and it flips back fantastic let's carry on so we've

615:01

accounted for that now let's get to actually checking if we have a match

615:06

so if that else

615:16

if now we need to check if the names match because each of our cards has an

615:22

ID from 1 to 12 however each of the cards has two names and not array each

615:28

so we finished dealing with the IDS we've checked if we've clicked the same image now let's use the names of the

615:35

cards to check for matches okay so we're using IDs to identify if the image is an individual card and now we're checking

615:42

for matches using new names so let's go into our cards chosen this time so I can

615:48

easy easily do the same as we did above cards chosen equal or deeply equal cards

615:59

chosen like that so once again if you would prefer it's totally up to you you

616:05

can store them just like we did up here or you can do that I'm going to do it like that because I don't think we're going to be using this anywhere else so

616:12

if the first card in our chosen cards array is the same as the second card in

616:18

our chosen card array I'm going to

616:24

alert you have found a

616:29

match okay it's pretty cool and what else do we need to happen well let's

616:36

just check if this works first so I can actually cheat and find out I know that the uh let's find out

616:44

where the cards are randomly so we don't need to console

616:49

like this I want the sorted array actually maybe that's right let's

616:55

check it out again yeah okay so that's the randomly sorted array we just need to put our

617:02

piece of code after the sort so I know that for example ice

617:08

cream 2 and three are going to be ice cream so 0 1 2 3 these two should be the same I'm going to click this one click

617:14

that one you have found a match great so you will see here the IDS are being

617:20

stored at two and three that's fine and if we were to console log out the card

617:26

chosen array you would see ice cream and ice cream okay so we have done that what

617:34

else do we need to do well if there is a match we also need to remove the cards

617:41

or essentially I'm just going to replace it with a white PNG square instead so

617:47

just like we did a so using

617:56

IDs I would set the image to be the white

618:03

PNG so let's go and check again refresh let's find out which ones

618:09

match the last two so once again one two you found a match okay and they

618:16

disappear however we can still click them which is not great we need to use a

618:23

JavaScript method that we leared and that is remove event listener so let's

618:28

do that now I'm going to grab the cards option

618:35

one again and use dot remove event listener to essentially listener for

618:43

clicks

618:51

and the function flip card and not let that happen Okay I don't want flip card

618:57

function happening if we click on either

619:06

card and finally I'm going to create another array called cards one I'm going

619:12

to use push to push these two cards in there so anything that's in the cards

619:17

chosen array is going to be pushed into the cards one Chosen and we actually need to remove them out of our card

619:23

chosen array and we also need to remove the cards out of the card CHS and IDs right because then we want to start over

619:30

so I can simply do this in a very very simple way by getting the cards

619:37

Chosen and just leaving it blank and getting the card chosen IDs

619:43

and leaving it blank too so let's check that out

619:49

see which ones match okay well seven and eight but

619:55

let's just go ahead and click so ID 7's been stored ID 6 has been stored there's no match ID 5 has been stored you can

620:02

see it's already started again there was no match so we've started a new array and now we're checking for a new match

620:08

cool once again one two not match one two not much great I love the fact that

620:16

the array is been cleared and we can start again to look for new two matching let's refresh and let's see

620:23

let's actually see what happens if we click two matching ones

620:29

so 7 and 11 so we know that one 0 1 2 3 4 5 6 7 matching you found a match um

620:38

boom cards one is not defined ah we did not push it into the cards one array because we did not declare

620:45

it so let's do that up here let cards one and again an empty

620:55

array cool so now if I I'm going to console

621:00

log it out here actually console log cards

621:07

One console log cards

621:15

Chen fresh check for my matching three and

621:20

four 0 1 2 3 4 You have found a

621:26

match cheeseburger cheeseburger and now a chosen array is

621:34

empty and we have passed cheeseburger and cheeseburger to the

621:40

cards one so it is in fact an array within an

621:45

array cuz cards one has an array array here so you can see one match and I've

621:51

stored it as an array okay so by the end of this we should have six arrays in our

622:00

array let's carry on so we've already done what happens if you click on the same card you've done what happens when

622:08

you find a match the one last thing to do now is what happens if you don't find

622:16

a match so for this is I would simply put both of

622:23

these back to looking blank and I'm just going to have an

622:30

alert saying

622:37

sorry try again and then once again we would clear the cards chosen we would

622:43

clear the cards chosen IDs and start a game

622:49

okay this is looking good now the one thing I need to do is actually

622:55

uh show if we win or

623:02

lose so for this I'm going to do that in my

623:08

results I'm going to grab the con result display

623:15

document and query selector so I'm going to look for can't remember what I called

623:21

it results it's an ID of results so I'm going to look for an ID

623:27

of result and I've saved it as result

623:33

display so here now I want to use text

623:41

content or in a HTML it's up to you to display however many arrays are in my

623:50

cards one array okay because I think you should get one point if you get one set matching so that makes sense cards

623:59

one

624:06

length and if cods

624:13

one length deeply equals the C OD

624:19

array length / two or I could have just wrote a

624:26

six that is up to you but I've chosen to do

624:33

this result display text

624:39

content congratulations

624:45

you have w on Amazing so let's check it

624:55

out not a match okay flip back not a match

625:02

okay it's a match great so we've removed those we have one in our array let's cheat

625:09

because we can it's a match and you will see we get two because we have two items or two one

625:17

card pairs in our array now we know this is a hot dog the

625:23

other hot dog is in six so 0 1 2 3 four five six it's a match we got a score

625:29

three and we now have three winning arrays in our

625:37

array it's a cheeseburger and seven is a cheeseburger a match we've gone to four

625:44

fries and we know that fries are in eight it's a match and

625:51

then it's a match and congratulations you have won and you can see here we

625:56

have all six pairs so six arrays in our cards one array great just fix that okay

626:07

so that is our first project done I hope you've enjoyed it I hope you've really

626:13

seen how we have used everything that we have learned so far to make this game you will now have this game saved on

626:20

your local computer and if you want to put it on GitHub so in other case store

626:26

it somewhere you know uh GitHub is a great example and place for developers storing things and it is very useful if

626:34

you want to showcase your projects to potential employers I'm going to show you how to do that at the very end so

626:41

congratulations make sure you save all your files you now have your project in your own desktop or in your own

626:48

uh working environment so that you can have it saved and work with it whenever you want now let's carry on with a

626:55

little bit more learning before we get to the GitHub

627:05

stage okay well done everyone I hope your learning is going well so far based on where we are in our coding journey I

627:13

thought I would introduce two games for you to choose from Tetris or Candy Crush

627:19

these two games have been chosen specifically for the level of learning we are at at the moment so the choices

627:26

totally up to you you can either choose to complete one project now complete

627:32

both projects or save them for later and carry on with this course the choice is

627:38

totally up to you so if you would like to have a go at building Tetris please

627:43

click on this YouTube card right here so we'll be doing a lot of array work in this video as well as learning how to

627:50

listen out for keystrokes and using a lot of 4 each and some JavaScript methods or you can try Candy Crush by

627:58

clicking this card right here in Candy Crush we will be learning how to drag

628:03

and drop elements as well as practice our array work and eventless N work as well as many many more things that we

628:10

have learned so far okay let's carry

628:16

on in this section I'm going to talk to you about HTTP or hyper text transfer protocol to

628:24

do this let's have a look at a normal standard website you see on the

628:30

internet most internet web pages are generated by web of HTML CSS and

628:36

JavaScript sent to you via the Internet the internet is made up of a bunch of

628:41

resources hosted on different servers the term resource corresponds to any

628:47

entity on the web including HTML files Styles sheets images and so on to access

628:54

the content on the internet your browser must ask these servers for the resources

628:59

that it needs and display these resources to you this protocol of

629:05

requests and responses enables you to view the page as it is let's have a

629:10

closer look at this protocol so to recap what we just said HTTP or hypertext

629:18

transfer protocol is used to structure requests and responses over the Internet

629:25

HTTP requires data to be transferred from one point to another over the

629:31

network this transfer of resources happens by using transmission control

629:37

protocol or in short TCP in viewing a web page TCP manages

629:43

the channels between your browser and the server so once again to recap TCP is

629:49

used to manage many types of internet connections in which one computer or device wants to send something to

629:55

another and HTTP is the command language that the

630:00

devices on both sides of the connection must follow in order to communicate when you type an address

630:07

such as www.google.com into your computer you are commanding it to open a TCP channel

630:15

to that site's uniform resource locator or in short URL a URL is unique to your

630:24

site and it's sort of like an address to it in this situation your computer so

630:32

your computer which is making the request is called the client the URL you

630:39

are requesting is the address that belongs to the server Okay so we've got

630:44

a client and a server you're on the computer and the URL which is where your

630:49

website is is on a server once the TCP connection is established the client

630:55

sends an HTTP get request to the server to

631:01

retrieve the web page issued display so here we have a get request or

631:08

a visualization of a get request the client is requesting the server gives him the

631:14

necessary resources for the website then after the server has sent the

631:20

response so here we see the server sending the response to us we say we've got it thank you after the server has

631:28

sent the response it closes the TCP connection if you open the website in

631:33

your browser again or if your browser automatically requests something from the server a new connection is opened

631:39

which follows the same process we just did get requests are one kind of HTTP

631:45

method a client can call we also have post requests put requests so here we

631:53

have a visualization of how the request with work with post request You're simply sending something to the server

631:59

and with put request the same we also have a delete request we

632:05

will be going into all four of these in more detail in the next

632:10

section now let's go back to our Google example suppose you want to check out something you want to search for

632:16

something on Google so so you type in the URL into your browser after you type

632:22

that URL into your browser what is happening behind the hood is your browser will extract the HTTP part and

632:29

recognize that it is the name of the network protocol to use then it takes

632:34

the domain name from the URL in this case it's google.com and asks the Internet domain

632:42

name server to return an Internet Protocol or IP address so at this point

632:49

the client knows the destination's IP address it then opens a connection to

632:54

the server at the address using the HTTP protocol as specified it will initiate a

633:01

get request to the server which contains the IP address of the host and optionally a data payload the get

633:09

request contains the following text that you see on the

633:15

screen this identifies a type of request Quest the path on

633:22

www.google.com and the protocol the protocol here is

633:28

http/1.1 the protocol is a revision of the first HTTP which is now called

633:37

http/1.0 in http/1.0 every resource request requires a separate connection to the server

633:46

http/1.1 like we have have on the screen uses one connection more than once so

633:52

that additional content like images or Styles sheets is retrieved even after the page has been retrieved as a result

634:00

requests using http/1.1 have less delay than those

634:05

using http/1.0 the second line of the request

634:11

contains the address of the server which is www.google.com there also may be

634:18

additional lines as well depending on what data your browser chooses to send if the server is able to locate the path

634:24

requested so if the server is able to get you to google.com the server might

634:30

respond with the header http/1.1 200 okay followed by the

634:36

content type so let's break this down the first line of the header is the

634:42

confirmation that the server understands a protocol that the client wants to communicate with we then get a HTTP

634:50

status code so the 200 signifying that the resource was found on the server on

634:55

the bottom line so the content type the bottom line shows the type of content

635:00

that it will be sending to the client if the server however is not able to locate

635:06

the path requested so it can't find the path to google.com it will respond with

635:11

the following header 404 not found in this case the

635:17

server identifies that it understands the HTTP protocol but the 404 not found

635:22

status code signifies that the specific piece of content requested was not found

635:27

there is many and many status codes that are available so I'm just going to show you some now here we have a website

635:34

called HTTP status dogs hyper transfer protocol response status codes and dogs

635:41

so here we'll see all the status codes you can get along with funny dog images just to sort of make sure that you

635:48

understand what each of them means so for example here we have the 200 it says okay let's find the

635:56

404 404 not found we have 403 Forbidden we have so many 500s under the popular

636:03

ones if you go to 500 internal server error there is so many and it's quite

636:08

cute website if you want to have a go familiarizing yourself with these stus

636:15

codes so there we go 404

636:20

422 400 all of these status codes are

636:26

essentially ones that you might see in your daily life as a

636:33

developer and that's it so that was a quick uh crash course on

636:38

HTTP and around HTTP status codes so one's like

636:44

404 next up I'm going to take you through some get requests post requests

636:49

put requests and a delete request so let's do it so next up I want us to have

636:56

a go using fetch which provides a JavaScript interface for accessing and manipulating parts of the htb pipeline

637:04

such as requests and responses let's have a look at what I mean

637:10

now so here we have fetch we use fetch to fetch a Json file across theor networ

637:17

and print it out to the console what I mean is this okay so here is an API this restful

637:27

API is essentially going to give us access to adjacent full of objects these

637:33

objects are going to be countries along with a lot more information with each of the objects so like the name the full

637:40

name the code and so on I'm going to choose an API endpoint I'm going to

637:45

select all because I want all the information all the information that is possible so I'm just going to select

637:51

this and I'm just going to put it literally in my browser so with the help

637:57

of Jason view so this is a Chrome extension that makes everything a lot

638:03

more readable if you haven't downloaded it please do download it now it essentially transforms everything to

638:09

look like this so in a lot more of a readable way as opposed to what it looks like like that okay so now it looks like

638:17

this and we can read everything so here we have our first object which is

638:23

Afghanistan the country Afghanistan we get the alpha codes for it we get the

638:28

capital we get the regions sub regions population literally so many time zones borders languages translations and a

638:37

flag so let's click the flag so essentially yes a lot a lot of

638:42

information gets given we also have different types of things as well well but essentially it's

638:48

just a breakdown of what we just saw if you need something specifically I just want everything so now we can actually

638:55

get all that data and use it in our project so let's go ahead and do that

639:00

now to do this I would need fetch so I'm just going to break this down I'm just

639:05

going to post that in here and talk to you about the syntax so already you will see that in my console let's make this

639:11

bigger and our console log I'm getting all 250 objects let's cck on the first one and it's Afghanistan so literally

639:19

the thing we are looking at even the flag is there we've got all that information and we can use it in our

639:28

project great so the simplest use of fetch takes one

639:33

argument so the API Endo the path to the resource you want to fetch and returns a

639:40

promise containing the response or the response

639:46

object this this is just an HTT response not the actual Json to extract the Json

639:52

body content from the response we use this so it's adjacent

639:57

method we then of course get all that data and we console log it so we can see

640:02

it in our browser so that's it it's pretty simple that's essentially what you need to use you can use this on any

640:09

API that you want or restful API as long as you get the path correct then that

640:15

should work perfectly this of course is the simplest form and

640:20

it is simply to get data so to get data

640:27

I'm simply getting it I am taking the file and the adjacent file and I'm getting all that information so I can

640:33

work with it you can even go as far as calling this a get request it's it's the

640:39

same it essentially does the same thing okay so that is an API that we

640:47

have chosen I'm going to actually show you another API too just to show you that you can literally put anything in

640:52

here as long as it's the right format I also like to use Punk API so Punk API is

640:59

essentially an API full of beers so if I take this and put this in here you will

641:06

get literally a list of all the beers by Brew dog there's Lads there's even

641:13

ingredients okay it has hops food pairing in which is quite a fun one you

641:18

make projects based on the food pairings which I have done in the past so it's also a great API let's go ahead and use

641:26

it in our project so I'm just going to get rid of

641:31

this and post beers instead so

641:36

now just try that again be

641:44

post just move some things around just refresh the page do

641:51

that I will get a bunch of beer objects which is pretty awesome one last

641:59

one to show you and that's my own API that I built so if I just go to here you will

642:07

see that I have made my own API which is all about Burgers so this is an open

642:12

source project if you want to go contribute to this I'll show you how to do this later once we've done a bit more

642:18

learning so I would simply copy that link and put it in

642:25

here in order to get my 28 Burgers so there's my first one

642:33

you'll see has an array of ingredients an array of addresses which is an object so that is

642:39

my first object and so on and so on so this is great we have made our first get

642:46

request to three different apis let's carry

642:52

on so next up I want to show you what to actually do with the data once we've got it so once again we have my burger API

643:01

I'm actually going to comment this out I'm still going to keep it there however and let's get rid of this I now

643:10

I'm going to write a function to get data

643:18

I'm then going to use the syntax here so I'm going to fetch the data but only if

643:24

we want it to So currently I'm not getting it I'm just getting the data I'm

643:29

fetching it and then storing it so response and then I'm getting the response

643:36

Json and then the data and I don't just want to console log the data I mean that is something that I want to do so I'm

643:41

going to put it there however I want to do a few more things as well once we get the data and only once we get the data

643:49

because we need to make sure that promise is resolved okay so we need to make sure the data is there and only

643:55

once it's there we want to get a name so I need to get the burger name

644:02

and to get the burger name I'm actually going to go into the data so actually let's get the data now I'm just going to

644:07

call it so we're getting our data so we're going into our data and it's going to

644:14

the first object

644:21

so the first object and get the name property so this hopefully is coming

644:28

together everything that we've learned so far so we should have the name and I'm just going to console log

644:35

out the name so we can see it and indeed we have the tribute burer

644:41

let's check if that's right so the first object name tribute Burger

644:47

amazing so that is how we would get data so we can work with it in projects in

644:53

one simple example I can also Loop over this to get all the names there's so much we can do I have so many great

645:00

projects on this so I'm going to leave you with a project now I hope you enjoy

645:06

it have fun

645:20

project in which we're going to learn how to build a random Burger generator what I mean by this is that we are going

645:26

to be using a burger API in order to randomly generate a burger name if we

645:32

click this button right here okay so as

645:37

a reminder this is the Burger API that we will using it is one I made myself I

645:43

provided you the link and you can go ahead and see all the different Baggers that different people from all over the

645:49

world have added to this open-source project we have an ID we have a name for

645:55

a bagger we have the restaurant where you can find it you have the website a

646:00

description an array of ingredients an array of addresses so

646:06

this one has one address it is an object and so on and so on for each one

646:13

so there's another one there's another one we have a Krabby Patty we have the Good Burger literally so so

646:21

many burgers so I'm going to show you how to do this to create a random Burger

646:28

generator we are going to have to get so we're going to have to have a get request to get all the burgers and we

646:36

can do this with fetch as we learned previously so let's go ahead and do that

646:41

now once again the Syntax for fetch is this

646:49

so I'm just going to copy paste it we are fetching so I'm just going to fetch

646:55

this URL not doing much with it I'm simply getting all the information that we saw

647:01

in our browser so each of the objects so we can work with it so if I make this a

647:07

little bit bigger we have once again the name the

647:13

restaurant of where we can find the bagger the website the description the

647:18

ingredients as an array and addresses which is an array of objects this one

647:25

only has one object Okay so we've got that information now

647:33

but how do we actually use this for our UI well so we get the response and then

647:40

we get the data only once we have the data then we can use what we have so I'm

647:49

just going to Simply get the name so I'm going to get the

647:54

name so I need to go into the data so this is our data I need to go into it and get the first object so zero just

648:03

going to get the first one for now so we can see what we are doing and get the name so if I console

648:10

log name well we will indeed see the tribute buger so to start things off let's just

648:17

work with that I'm just going to store it up here so I'm going to get

648:25

the element up here so let's do that here

648:30

const via display equals and then

648:38

document let's use Query selector to

648:43

find the name so the div with the class of name a class we need a DOT so once we

648:51

have that let's actually get our beer display and with inner HTML assign it the

648:59

name so there we go we have a tribute burger just going to style this up a

649:05

little bit maybe give it some padding let's say 30

649:15

pixels the high okay so that is looking good um let's

649:21

make the width

649:27

37 okay okay well I'm happy for that that's

649:34

that's fine for now actually maybe let's make it 30 and

649:40

then zero pixels on the side and change that back to 400 it's up

649:46

to you I'm just being a bit pedantic okay so we have a burger however it's not random it's not really

649:52

a random Burger well we know how to make things random but for this we need to actually

649:59

do something to our button so let's go ahead and grab the button store it as button and you document query

650:07

selector and I'm actually looking for a div with a class of button not the button itself as you can see here it's a

650:14

class of button

650:20

and then I'm actually a function that says get

650:26

data and put all of this in my function

650:31

okay so that at the moment nothing happens but only if I click the button then we get a

650:37

burger and the button so we need to grab the button and use an event listener so we're really using everything that we

650:43

have learned so far and in it I pass through a click and the function of get

650:50

data because as a reminder the ad event listener works on a Target we pass through an event and the function that

650:56

we want to invoke if the event is triggered so now if I click the button

651:01

well I get a bger however it's still not random so let's do that up

651:08

here well to get a random number so con random number we know that we need to

651:14

use math random and let's multiply it by the data

651:23

length so by however many bugs we have in our data because it is an array so we

651:30

can use the length property on it so now we're getting a random number c random

651:37

we need to make sure this is an integer so we can pass it back through to our array and I will do this

651:45

using math floor and passing through a random

651:52

number Okay so we've got a random integer great and what do we do with it well let's pass it through here so now

652:01

if I click here let's refresh that we are getting a

652:08

random Burger each time this is fantastic I'm really

652:16

pleased with how this has worked I hope you've enjoyed this lesson I'm really

652:23

pleased with how everything came together so we're using everything we've learned about this we've learned about

652:28

fetching we've learned about getting random numbers and we learned about getting in HTML and we've learned about

652:35

event listeners so this was a really good project I'm really happy that we can use it in order to build a random

652:42

Burger generator okay let's carry

652:47

on for those of you who want to make a note of this please feel free here's the stylesheet all I have is a body and name

652:55

and a button with some styling for the button and of course the index HTML file

653:03

which simply has a name and a button and

653:08

they're all in a div as well to make them styled out like this so that is

653:14

it cool also Al don't forget about your folder structure that will be important

653:19

if you want to pick out the JavaScript and stylesheet so if something is not working it might be due to that are we

653:27

ready to move on let's do it next up I'm going to show you how to

653:33

make a post request what I mean by post request is this so just like we were

653:40

able to get data we are able to post

653:45

data to n API so for example here let's have a

653:51

look at my burger API again I can essentially send data to here in order

653:58

to add another bger object okay so

654:03

because this is a very low security one I shouldn't have any errors so let's do

654:09

it in order to make a post request we need the following

654:14

syntax so here we go let's talk through this a little bit first this is just the

654:21

basic Syntax for making a post request to a URL so first off we start with the same

654:29

Fetch and we open up our parentheses and pass through a

654:34

URL so this time we are not just passing through a URL like we did last time we are passing through two things the URL

654:42

and this object right here okay so that is essentially the same

654:49

syntax we're just passing through a chunky object with our URL too so two

654:54

arguments and then once again we are catching the response and then the data

655:00

I've also made a little success message here to know that our data has been successful so we'll get the data along

655:06

with the success message or if there has been an error we can catch the error and we'll be able to see that in our console

655:14

log so I'll show you both of these I also have the method of post so

655:20

I am telling our fetch API that I want to post this data I don't want to get it I want to post it to the URL the URL

655:28

that we're going to specify here and I've just put in some headers as well so this is just the syntax we are

655:34

essentially just passing through the content type as a header and the content type is application Json okay so we're

655:40

just passing through this header along with the method of post then for the body so once again we are not not only

655:46

passing through the URL as an argument we're passing through this object which has a method of post a header and a body

655:53

and the body is whatever we tell it to be so this is just like a template I

655:58

just have a username example so if we post this to a URL we're essentially

656:04

posting this data this object that has user an example

656:11

okay I think the best way to do this is Show You by doing so

656:16

so I'm going to use my burger API again so here we have the burger

656:24

API here you will see the last object which is the Barbie Burger it's got

656:30

id28 I'm essentially going to copy this object as I want to copy the format used

656:36

for this API so I've copied the entire thing now instead of this template data

656:42

object I'm just going to pass that through and paste it now just going to format that a little

656:49

bit so it looks a bit nicer I'll leave that up here so you can

656:55

see how that looks the description is a bit long but don't worry about it that

657:00

is our data object the entire thing now let's create a new burger so I'm just

657:06

going to go data id29 let's call

657:11

it oby's Burger

657:20

restaurant AR's web address rbs.com

657:31

description a delicious burger from

657:39

Heaven ingredients let's have a bun let's have

657:46

have cheese let's have a beef

657:52

py let's have some lettuce

657:57

tomato tomato and Mayo is fine and address well

658:04

let's make this up id0 great 24 RB

658:11

Lane Obby

658:19

town there we go and then RB L okay so

658:24

that is our fake burger that is essentially our data object that we want to post to the URL here so because we

658:35

want to post to the Burger API now we need to make sure that we

658:42

actually get the correct address so copy that

658:49

and I'm simply going to put it here okay so hold on I'm just going to cut this

658:55

out so you've already see we've posted it I actually wanted to post okay fine

659:00

let's just put that in I wanted to do that on the Press of a button but as you can see here we've already posted it so

659:07

there we go you will see we get a success message so that is our success

659:13

message along with the data that we posted so here we go that is what we posted is essentially exactly what we

659:19

wrote in our example data object so if I get the ingredients out

659:25

it's the new ones and the address that we made up and there we go we have posted our bagger but this is not where

659:33

we finished I just want to make sure that everything work correctly so now let's go back to that

659:38

URL if I refresh the page and go to the bottom you will see the arbs Burger

659:47

immediately we have made a post request and it was

659:54

successful okay and that is it we have made a post request it has worked

660:00

perfectly everything is fine we have now covered how to get data but also how to

660:06

post data so we have really made some progress this is looking great I just

660:12

have two more to show you before we carry on

660:19

so next up I want to talk to you about a put request a put request essentially allows

660:25

you to edit a

660:31

object okay that is an explanation in a very basic way we can use it to update

660:37

any resource that we have it is considered to be one of the most common HTTP methods for retrieving and sending

660:45

data to a server so once again let's get the syntax up

660:54

so there we go we don't have any data yet I'm going to make the method as put

661:00

this time once again we have the fetch API and we need to pass through a URL

661:06

and an object that will contain the method the header and the body of what

661:12

we want to alter so let's go ahead and do this so once

661:18

again we need the data as an

661:24

object don't forget this is just the normal syntax I'm actually going to put it in a function this time so

661:33

function edit

661:38

data okay just so we can invoke it whenever we want so method put headers

661:44

body we are getting the data so data up here and we are passing it through to the body and then we get a success

661:51

message or an error message if it has failed okay so the data well the first

661:59

thing that I need to do is decide what object I want to edit so let's do that

662:04

now let's go back into my bagger API or my fake bager API and then let's say I

662:12

want to edit the Third third item so I would need the

662:19

third burger so I would simply put a for

662:25

slash3 and now I could view the Good Burger as a stand alone object so this

662:31

is the URL I need if I wanted to edit the good bger let's go back to our

662:39

project I'm going to put it in here make sure it's a string otherwise this will

662:45

not work and with the put method I essentially need to

662:52

take so I'm going to take the burger as it is exactly copy

662:59

it and then paste this format it and now I can edit it so

663:06

let's just change I don't know let's say that this number is incorrect and put 1 2

663:13

3 so now we've changed that data we want to override the data that we have and we

663:19

can do this by essentially making a put request to the specific root to that

663:26

bger so if we're ready I'm going to just call the function click save and success you will

663:36

see that now in the addresses I have changed the number from

663:41

0 0 0 to 1 2 3 let's just have a look here for good

663:49

measure refresh and indeed the number has changed to 1 2 3 amazing let's carry

664:03

on okay I'm going to delete this for now so we've done put requests we've

664:10

done get request we've done post request I have one more to show you and that is the delete request and you guessed it it

664:19

can delete a whole object so let's do that

664:26

now let's say I want to delete the very last bger from our fake

664:33

API so I would go in here let's have a look at it again scroll all the way down

664:40

well it's the Arby's burger it's the burger with id29

664:45

so to do this I would simply use Fetch and then the URL so the

664:55

URL that we had last time as a string and I would need to

665:02

pass through the ID so the ID 29 as that was the burger the RB's

665:09

burger and then I would simply just pass through the method of

665:23

delete now this is in its very simplified form let's see if that has

665:28

worked so now refresh go scroll

665:33

down and that has indeed worked we have deleted the 29th Burger now we don't

665:43

really see anything because I didn't it to console log anything if I wanted to

665:48

see uh what was returned I would once again have to have a response uh and so

665:54

on and so on but I didn't I didn't do this for now I just wanted to show you the delete method in its basic form if I

666:02

wanted to however I could have attached this as

666:09

before in which we would get a success message so let's try delete another bger 28

666:18

okay so that shows us a success we don't get a result back because there's

666:23

nothing to give back we've just deleted something so it's an empty object but if we have a

666:29

look here and refresh Burger 28 is now gone so that is

666:37

great we essentially don't need all of this we could just have conso log success or console log error we probably

666:44

do need the error message so so there we go okay so just going to get rid of that

666:52

now and keep it in its most basic form that is it we have covered the top four

666:57

most popular HTTP requests I hope you've enjoyed this

667:02

I really enjoyed uh showing you these they're really fun and once you get to GPS with them the world is your oyster

667:08

in terms of working with ap ice so I'm glad I can show you I do have a few

667:13

projects for you on my channel so I'm going to hook you up with a few if you choose to look at them now if not then

667:20

please do carry on I have a lot more to teach you for those of you who are interested

667:26

in how I made my restful API imitation in a super simple way I have just the video for you in this video I show you

667:34

how to make your own API in just a few simple steps it is a bit more on the advanced side but if you would like to

667:40

have a look or are just curious please do look at this YouTube card right here

667:46

so up there otherwise please save it for another time and let's carry

667:52

on okay in this section I'm going to show you how to put your project so the

667:58

game of memory game that we built on our local code editor onto GitHub so it can

668:04

be viewed by others online let's do it GitHub is a subsidiary of Microsoft

668:12

which provides hosting for software developers and Version Control using Git it offers the distribute ver Version

668:19

Control and source code management functionality of git plus its own features don't worry if that doesn't

668:25

mean anything for now I'm going to show you some functionality of GitHub as we go on so first off you need to know this

668:33

is a free service and is essentially is just a way for you to Showcase your

668:39

projects so go ahead and sign up once you have signed up you should see a

668:44

dashboard that looks like this so this is my own personal GitHub

668:51

page you will see all my repositories as well as all my contributions in the last

668:57

year a contribution is simply me making a g commit once again don't worry if

669:03

that doesn't mean anything to you it's just a word that you should get used to hearing and that you will learn along

669:08

the way so now let's say I want to add my memory game to my repositor right here

669:16

so I would simply click repositories

669:24

new and then right here I'm going to create a new repository so I'm going to

669:30

call this memory game I already have one memory game in

669:37

here so let's call it 2021 description simple game made in

669:47

JavaScript HTML and CSS now I'm going to choose to make this

669:52

repository public so that anyone can see it but if you'd rather keep it private

669:57

please click the private button right there and next I'm going to initialize

670:03

this repository with a read me file this is essentially where you can write a

670:08

description of your project so that others can see it I'm going to show you what I

670:14

mean okay okay so by creating this we are creating a main branch this is the

670:21

default name of the branch and going to click create

670:29

repository Okay so we've created our repository at the moment our repository only has one file and that is the read

670:36

me file that we clicked to initialize along with this template text that we

670:41

gave it so to edit this read me I can simply click here and typee

670:48

away if you want to know some formatting tricks I suggest looking at markup for

670:53

readms so for example this is a H1 tag if you will if I want to make a smaller

671:00

one I am a smaller title and so

671:05

on and I'm just going to commit this to the main branch so

671:11

commit so I've now committed that and you will see my five F has now changed I

671:17

have that I am a smaller title that I wrote okay so this is great but how do

671:23

we actually get to adding our memory game in here well I'm going to show you a super simple way of doing it that

671:29

doesn't involve the terminal and that would simply involve me clicking on the repo itself or

671:36

repository and adding files so I'm going to choose to upload files and now I'm just going to drag my

671:43

files in here so let's go to where we saved our memory game on our personal

671:50

computers for me it would be in my personal projects and I saved it right

671:55

here so I would click into the folder and copy all of

672:02

this so the index HTML file as well as the source file that has my index GS and

672:08

style CSS file I'm going to copy all of that and simply just drop it like

672:16

so you will now see all my files being added so the index HTML file the sty

672:22

sheet all the images that are in the images folder and the index JS file for

672:29

the JavaScript once again I'm going to commit these changes I can choose to

672:34

change the name of this commit or I could just leave it as it is once again

672:40

this will be committing directly to the main branch of our project

672:47

commit and there we go we have now saved our project onto the internet for others

672:54

to view our code this is great is now

672:59

publicly shared anyone can find it anyone can simply click in here to view our JavaScript and this is essentially

673:07

how you would submit code to potential employers or just share with your

673:13

friends once again this is a public repository if you'd like to keep it

673:19

private so if you just like to share your code with one person or two people you could easily do that too before

673:27

sharing your code I would suggest to really build out this read me I think read me are super important otherwise

673:33

someone's just going to get your folder and not really know how to open it for example you might want to say like download the file so code download it

673:42

and then open it by opening the index HTML file all this information is super

673:48

important no one can you know no one's a mind reader you need to really lay down The rules as to how you want your

673:55

project to be opened so for example if I show you some of

674:00

mine let's go to my repository I'm going to show

674:09

you a more complicated project that I did which involves a lot

674:17

of information as to how to start the app okay so there we go that is how I

674:23

would suggest writing a readme let's go back to our repository

674:30

now so once again memory game

674:37

2021 now if I just wanted to share this with one or two people I would have to

674:42

change these settings on this so I'd go to settings I would scroll all the way

674:52

down I would change visibility to make

674:57

private so I would just have to type this out

675:03

again and put in my password

675:12

and this repository has now been change to be private I will then share this

675:18

project with people so I can manage access and I can invite a collaborator

675:25

to do this I can use the GitHub username or email so that is another option too

675:32

if you just want to share your code with one other person or two other people for example if it is for an interview this

675:38

is the way that I would do it okay so that's really it for this

675:44

section uh that was just a basic understanding of GitHub so you can get your games online there is a lot more learning to

675:51

do and I'm going to leave you on some tips as to where you should go from

675:57

here okay so we are coming to the end of our course in this course we have built

676:03

an understanding of HTML CSS and JavaScript thanks to the lessons

676:09

exercises and projects along the way however you might be wondering what

676:14

what's next well I have a few suggestions for you so where's go from here the first

676:21

thing I would suggest is getting more familiar with GitHub even though I did

676:26

show you how to store your own project on GitHub GitHub has a lot of other functionalities that you should be aware

676:33

of so that would be your best bet as to where to go next some features of GitHub

676:39

include creating a profile building out your network and just storing more projects

676:45

I have a few tutorials on GitHub that is how to make branches how to make PLL

676:51

requests don't worry if all these words don't mean a lot at the moment this is what your research into GitHub will help

676:59

you with leading on to that I'm going to talk about terminal learning the terminal is the

677:05

next piece of advice that I would give you as a Next Step the terminal in

677:10

layman terms will allow you to control projects and and files and folders on

677:16

your computer from a command line interface as well as allow you to pull in packages talk to GitHub and a lot

677:25

more next up I would suggest looking into libraries and Frameworks one of

677:30

these is react react is something that I like to work with every day as a developer in my professional setting

677:38

learning react was a personal choice for me if you'd rather look into Mobile development please do have a look at

677:45

react native or you can check out completely other libraries and Frameworks such as view or angular there

677:51

are so many on the internet react just happens to be my personal

677:56

choice and next I would suggest looking at nodejs once again in a nutshell and in

678:03

layman terms node.js will essentially allow you to build out backends allow you to download packages and a lot of

678:10

other really cool things in order to really build out your projects I have a couple of no s videos on my channel so

678:18

please do check them out lastly going back to our contactform section I'm

678:24

going to have a video coming out especially on this so please do like and follow my channel if you want to learn

678:30

how to do this it will involve a library and scripting so a little bit more

678:35

advanced stuff than what we have learned today but I hope you're excited to learn and that is it we have now

678:42

finished our YouTube coding boot camp congratulations if you have finished I

678:48

hopefully you now feel you have a good grasp on the fundamental of JavaScript HTML and CSS you should also have a few

678:56

good projects to put in your portfolio as well as a clear direction of where you should go next keep practicing and

679:02

gaining more software developer skills as mentioned if there is an area that

679:08

you're not to make a lot of sense by all means please go back and do that section again that is exactly what the time St

679:14

are there in the description of my video once again thank you so much for coding

679:20

along with me please do like and subscribe to my channel it really would mean a lot I love creating more content

679:27

and I'd love to create more content for you guys so that would really help me out okay thanks so much again and I'll

679:34

see you hopefully on my channel

679:43

soon

680:13

e

680:43

e

681:13


 

No comments:

Post a Comment