Merge pull request #1 from Asabeneh/master

Day 7
pull/47/head
suryazi 5 years ago committed by GitHub
commit 0f3f42b859
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

6
.gitignore vendored

@ -1,4 +1,8 @@
draft.md draft.md
react-for-everyone.md react-for-everyone.md
component.md component.md
06_Day_Map_List_Keys 08_Day_States
09_Day_Conditional_Rendering
10_Day_Events
11_Day_Forms

@ -13,8 +13,8 @@
<a href="https://www.linkedin.com/in/asabeneh/" target="_blank">Asabeneh Yetayeh</a><br> <a href="https://www.linkedin.com/in/asabeneh/" target="_blank">Asabeneh Yetayeh</a><br>
<small> October, 2020</small> <small> October, 2020</small>
</sub> </sub>
</div>
</div>
[<< Day 0](../readMe.md) | [Day 2 >>](../02_Day_Introduction_to_React/02_introduction_to_react.md) [<< Day 0](../readMe.md) | [Day 2 >>](../02_Day_Introduction_to_React/02_introduction_to_react.md)
@ -2763,13 +2763,12 @@ Let us see were we use call back functions.For instance the _forEach_ method use
```js ```js
const numbers = [1, 2, 3, 4] const numbers = [1, 2, 3, 4]
const sumArray = arr => { const sumArray = arr => {
let sum = 0 let sum = 0
const callback = function(element) { const callback = function(element) {
sum += element sum += element
} }
numbers.forEach(callback) arr.forEach(callback)
return sum return sum
} }
@ -2777,7 +2776,7 @@ console.log(sumArray(numbers))
``` ```
```sh ```sh
15 10
``` ```
The above example can be simplified as follows: The above example can be simplified as follows:
@ -2787,7 +2786,7 @@ const numbers = [1, 2, 3, 4]
const sumArray = arr => { const sumArray = arr => {
let sum = 0 let sum = 0
numbers.forEach(function(element) { arr.forEach(function(element) {
sum += element sum += element
}) })
return sum return sum
@ -2797,7 +2796,7 @@ console.log(sumArray(numbers))
``` ```
```sh ```sh
15 10
``` ```
#### setting time #### setting time
@ -4083,7 +4082,7 @@ class Person {
const fullName = this.firstName + ' ' + this.lastName const fullName = this.firstName + ' ' + this.lastName
return fullName return fullName
} }
get getscore() { get getScore() {
return this.score return this.score
} }
get getSkills() { get getSkills() {

@ -25,14 +25,14 @@
- [React vs Vue popularity in February 2020](#react-vs-vue-popularity-in-february-2020) - [React vs Vue popularity in February 2020](#react-vs-vue-popularity-in-february-2020)
- [3. JSX](#3-jsx) - [3. JSX](#3-jsx)
- [JSX Element](#jsx-element) - [JSX Element](#jsx-element)
- [Commenting JSX element](#commenting-jsx-element) - [Commenting a JSX element](#commenting-a-jsx-element)
- [Rendering JSX Element](#rendering-jsx-element) - [Rendering a JSX Element](#rendering-a-jsx-element)
- [Style and className in JSX](#style-and-classname-in-jsx) - [Style and className in JSX](#style-and-classname-in-jsx)
- [Injecting data to JSX Element](#injecting-data-to-jsx-element) - [Injecting data to a JSX Element](#injecting-data-to-a-jsx-element)
- [Injecting a string to JSX Element](#injecting-a-string-to-jsx-element) - [Injecting a string to a JSX Element](#injecting-a-string-to-a-jsx-element)
- [Injecting a number to JSX Element](#injecting-a-number-to-jsx-element) - [Injecting a number to a JSX Element](#injecting-a-number-to-a-jsx-element)
- [Injecting an array to JSX Element](#injecting-an-array-to-jsx-element) - [Injecting an array to a JSX Element](#injecting-an-array-to-a-jsx-element)
- [Injecting an object to JSX Element](#injecting-an-object-to-jsx-element) - [Injecting an object to a JSX Element](#injecting-an-object-to-a-jsx-element)
- [Exercises](#exercises) - [Exercises](#exercises)
- [Exercises: What is React?](#exercises-what-is-react) - [Exercises: What is React?](#exercises-what-is-react)
- [Exercises: Why React?](#exercises-why-react) - [Exercises: Why React?](#exercises-why-react)
@ -44,33 +44,33 @@
## Getting Started React ## Getting Started React
Prerequisite to get started with React. You should have a good understanding of the following technologies: This section covers prerequisites to get started with React. You should have a good understanding of the following technologies:
- HTML - HTML
- CSS - CSS
- JavaScript - JavaScript
If you have the above skills you will enjoy doing React. The 30 Days Of React challenge contains anything you need to know about react. In every section, it has some exercises and mini-projects and it is recommended to work on them. This 30 Days Of React challenge will help you learn the latest version of React and the old version step by step. The topics are broken down into 30 days, where each day contains several topics with easy-to-understand explanations, real-world examples and many hands on exercises. If you have the skills mentioned above, you will enjoy doing React. The 30 Days Of React challenge contains everything you need to know about react. In every section, it has some exercises and mini-projects, and it is recommended to work on them. This 30 Days Of React challenge will help you learn the latest version of React and the old version, step by step. The topics are broken down into 30 days, where each day contains several topics with easy-to-understand explanations, real-world examples and many hands-on exercises.
This challenge is designed for beginners and professionals who want to build a web application using React and JavaScript. This challenge is designed for beginners and professionals who want to build a web application using React and JavaScript.
### 1. What is React? ### 1. What is React?
React is a JavaScript library for building a reusable user interface(UI). It was initially released on May 29, 2013. The current version is 16.13.1 and somehow it is stable. React was created by Facebook. React makes creating UI components very easy.The official React documentation can be found [here](https://reactjs.org/docs/getting-started.html). When we work with React we do not interact directly with the DOM. React has its own way to handle the DOM(Document Object Model) manipulation. React uses its virtual DOM to make a new change and it updates only the element that needs change. Do not directly interact with DOM when you build a React Application and leave the DOM manipulation job for the React virtual DOM. In this challenge, we will develop 10-15 web applications using React. A web application or a website is made up of buttons, links, forms with different input fields, header, footer, sections, articles, texts, images, audios, videos and boxes with different shapes. We use react to make a reusable UI component of a website. React is a JavaScript library for building a reusable user interface(UI). It was initially released on May 29, 2013. The current version is 16.13.1 and somehow it is stable. React was created by Facebook. React makes creating UI components very easy. The official React documentation can be found [here](https://reactjs.org/docs/getting-started.html). When we work with React we do not interact directly with the DOM. React has its own way to handle the DOM(Document Object Model) manipulation. React uses its virtual DOM to make new changes and it updates only the element, that needs changing. Do not directly interact with DOM when you build a React Application and leave the DOM manipulation job for the React virtual DOM. In this challenge, we will develop 10-15 web applications using React. A web application, or a website, is made of buttons, links, forms with different input fields, header, footer, sections, articles, texts, images, audios, videos and boxes with different shapes. We use react to make a reusable UI components of a website.
To summarize: To summarize:
- React was released in May 2013 - React was released in May 2013
- React was created by Facebook - React was created by Facebook
- React is a JavaScript library for building user interfaces - React is a JavaScript library for building user interfaces
- React is used to build single page applications- An application which has only one HTML page. - React is used to build single page applications - An application which has only one HTML page.
- React allows us to create reusable UI components - React allows us to create reusable UI components
- React latest release is 16.13.1 - React latest release is 16.13.1
- [React versions](https://reactjs.org/versions/) - [React versions](https://reactjs.org/versions/)
- React official documentation can be found [her](https://reactjs.org/docs/getting-started.html) - React official documentation can be found [here](https://reactjs.org/docs/getting-started.html)
### 2. Why React? ### 2. Why React?
React is one of the most popular JavaScript library. Many developers and companies have been using it for the last couple of years. Its popularity has been growing fast and it has a huge community. How do we measure popularity? One measure of popularity could be GitHub repository stars, watchers and forks. Let us compare the popularity of [React](https://github.com/facebook/react) and [Vue](https://github.com/vuejs/vue). As of today, the popularity between the two most popular JavaScript looks like as shown on the diagram. From the diagram, you can speculate the most popular JavaScript library. You may look at the number of watchers, stars and forks for both React and Vue. These alone will not be a very good measure of popularity but still it tells a little bit about the popularity of the two technologies. If I have to recommend another JavaScript library next to React would Vue.js. React is one of the most popular JavaScript libraries. Many developers and companies have been using it for the last couple of years. Its popularity has been growing fast and it has a huge community. How do we measure popularity? One measure of popularity could be GitHub repository stars, watchers and forks. Let us compare the popularity of [React](https://github.com/facebook/react) and [Vue](https://github.com/vuejs/vue). As of today, the popularity between the two most popular JavaScript looks like as shown on the diagram. From the diagram, you can speculate the most popular JavaScript library. You may look at the number of watchers, stars and forks for both React and Vue. These alone will not be a very good measure of popularity, but still it tells a little bit about the popularity of the two technologies. If I have to recommend another JavaScript library next to React, it would be Vue.js.
#### React vs Vue popularity in October 2020 #### React vs Vue popularity in October 2020
@ -92,7 +92,7 @@ Vue Official GitHub Repository
![Vue Popularity February 2020](../images/vue_popularity.png) ![Vue Popularity February 2020](../images/vue_popularity.png)
Why we choose to use react ? We use react because of the following reasons: Why we choose to use React ? We use it because of the following reasons:
- fast - fast
- modular - modular
@ -104,7 +104,7 @@ Why we choose to use react ? We use react because of the following reasons:
### 3. JSX ### 3. JSX
JSX stands for JavaScript XML. JSX allows us to write HTML elements with JavaScript code. An HTML element has an opening and closing tag, content, and attribute in the opening tag. However, some HTML tag may not have a content and a closing tag, they are self closing elements. To create HTML elements in React we do not use the _createElement()_ instead we just use JSX elements. Therefore, JSX makes it easier to write and add HTML elements in React. JSX will be converted to JavaScript on browser using transpiler which [babel.js](https://babeljs.io/). Babel is a library which transpile JSX to pure JavaScript and latest JavaScript to older version. See the JSX code below. JSX stands for JavaScript XML. JSX allows us to write HTML elements with JavaScript code. An HTML element has an opening and closing tags, content, and attribute in the opening tag. However, some HTML elements may not have content and a closing tag - they are self closing elements. To create HTML elements in React we do not use the _createElement()_ instead we just use JSX elements. Therefore, JSX makes it easier to write and add HTML elements in React. JSX will be converted to JavaScript on browser using a transpiler - [babel.js](https://babeljs.io/). Babel is a library which transpiles JSX to pure JavaScript and latest JavaScript to older version. See the JSX code below.
```js ```js
// JSX syntax // JSX syntax
@ -115,25 +115,25 @@ const welcome = <h1>Welcome to 30 Days of React Challenge</h1>
const data = <small>Oct 2, 2020</small> const data = <small>Oct 2, 2020</small>
``` ```
The above strange looking code seems a JavaScript but it is not JavaScript and it seems an HTML but not completely an HTML element. It is a mix of JavaScript and an HTML element. JSX can allow us to use HTML in JavaScript. The HTML element in the above JSX is _h1_ and _small_. The above strange looking code seems like JavaScript and it seems like , but it is not JavaScript and it seems like HTML but not completely an HTML element. It is a mix of JavaScript and an HTML elements. JSX can allow us to use HTML in JavaScript. The HTML element in the JSX above is _h1_ and _small_.
#### JSX Element #### JSX Element
As you have seen in the above example, JSX has a JavaScript and HTML like syntax. JSX element could be a single HTML element or many HTML elements wrapped in a parent HTML element. As you have seen in the example above, JSX has a JavaScript and HTML like syntax. JSX element could be a single HTML element or many HTML elements wrapped in a parent HTML element.
This JSX element has only on HTML element which is _h1_. This JSX element has only one HTML element which is _h1_.
```js ```js
const jsxElement = <h1>I am a JSX element</h1> // JS with HTML const jsxElement = <h1>I am a JSX element</h1> // JS with HTML
``` ```
Let's make more JSX elements by declaring a new variable name title and content inside h1. Let's make more JSX elements by declaring a new variable named title and content inside _h2_.
```js ```js
const title = <h2>Getting Started React</h2> const title = <h2>Getting Started React</h2>
``` ```
Let us add a subtitle and other contents to the above JSX element by adding additional HTML elements. Every HTML element should be wrapped by an outer HTML element to create a valid JSX element. The name title variable also should be changed to header because our JSX element is containing almost all the header of the application. Let us add a subtitles and other contents to this JSX element by adding additional HTML elements. Every HTML element should be wrapped by an outer HTML element to create a valid JSX element. The name title variable also should be changed to header because our JSX element is containing almost all of the header of the application.
```js ```js
const header = ( const header = (
@ -145,7 +145,7 @@ const header = (
) )
``` ```
Let us keep adding more elements. Additional HTML element to display the author name and year. Let us keep adding more elements. Additional HTML elements to display the author name and year.
```js ```js
const header = ( const header = (
@ -161,9 +161,9 @@ const header = (
As you can see the _header_ element is a parent element for all the inner HTML elements and JSX must be wrapped by an outer parent element. Without the _header_ HTML element or other parent HTML element the above JSX is invalid. As you can see the _header_ element is a parent element for all the inner HTML elements and JSX must be wrapped by an outer parent element. Without the _header_ HTML element or other parent HTML element the above JSX is invalid.
#### Commenting JSX element #### Commenting a JSX element
We comment codes for different reasons and it is also go to know how to comment out JSX element in React. We comment codes for different reasons and it is also good to know how to comment out JSX elements in React.
```js ```js
{ {
@ -180,9 +180,9 @@ We comment codes for different reasons and it is also go to know how to comment
} }
``` ```
#### Rendering JSX Element #### Rendering a JSX Element
To render a JSX element to HTML document, we should first create an index HTML. The index.html is the only HTML file you will have in any React Application. That is why we call that every React Application is a single page application. Let us create an index.html file. We can get started React in two ways either using CDN or create-react-app. The create-react-app create a React project boilerplate outbox and because of that many people do have a hard time understand how react works. In order to make things clear for absolute beginners I would like to start with a CDN. We use CDN only in this section and we will use the create-reap-app in the rest of the challenge and I also recommend you to use only create-react-app all the time. To render a JSX element to HTML document, we should first create an index HTML. The index.html is the only HTML file you will have in any React Application. That is why we say that every React Application is a single page application. Let us create an index.html file. We can get started with React in two ways - either by using CDN or create-react-app. The create-react-app creates a React project boilerplate outbox and because of that, many people do have a hard time to understand how React works. In order to make things clear for absolute beginners I would like to start with a CDN. We use CDN only in this section and we will use the create-reap-app in the rest of the challenge and I also recommend you to use only create-react-app all the time.
```html ```html
<!DOCTYPE html> <!DOCTYPE html>
@ -201,7 +201,7 @@ To render a JSX element to HTML document, we should first create an index HTML.
</html> </html>
``` ```
As you can see from the above index.html, we have one div with a class root and script. The root _div_ is the get way to connect all react component to the index.html. In the script tag, we will write our JavaScript but the script _type_ will be _babel_. Babel will _transpile_ the react JSX to pure JavaScript on the browser. Let us add babel to the script. Inside the babel, we can write any pure JavaScript, JSX and in general any react code. As you can see from the above index.html, we have one div with a class root and script. The root _div_ is the gateway to connect all react components to the index.html. In the script tag we will write our JavaScript, but the script _type_ will be _babel_. Babel will _transpile_ the react JSX to pure JavaScript on the browser. Let us add babel to the script. Inside the babel, we can write any pure JavaScript, JSX and in general any React code.
```html ```html
<!DOCTYPE html> <!DOCTYPE html>
@ -222,7 +222,7 @@ As you can see from the above index.html, we have one div with a class root and
</html> </html>
``` ```
The babel library is linked to our document and now we can make use of it. The next step is importing _React_ and _ReactDOM_ using CDN or link. In order to link React and ReactDOM we attach both packages CDN to the body of index.html. To test if React is linked to the index.html try to check by doing console.log(React). Open the browser console and you should get an object. If you see an object containing React methods then you managed to link your project with React CND and you are ready to use React. The babel library is linked to our document and now we can make use of it. The next step is importing _React_ and _ReactDOM_ using CDN or link. In order to link React and ReactDOM, we attach both packages from CDN to the body of index.html. To test if React is linked to the index.html, try to check it by doing console.log(React). Open the browser console and you should get an object. If you see an object containing React methods then you managed to link your project with React CDN and you are ready to use React.
```html ```html
<!DOCTYPE html> <!DOCTYPE html>
@ -285,7 +285,7 @@ Now, you knew JSX and JSX element. Let us render the JSX element on the browser,
const jsxElement = <h1>I am a JSX element</h1> const jsxElement = <h1>I am a JSX element</h1>
// we render the JSX element using the ReactDOM package // we render the JSX element using the ReactDOM package
// ReactDOM has the render method and the render method takes two argument // ReactDOM has the render method and the render method takes two arguments
ReactDOM.render(jsxElement, rootElement) ReactDOM.render(jsxElement, rootElement)
</script> </script>
</body> </body>
@ -294,7 +294,7 @@ Now, you knew JSX and JSX element. Let us render the JSX element on the browser,
![Rendering JSX](../images/rendering_jsx.png) ![Rendering JSX](../images/rendering_jsx.png)
Let us render more content. To render more content, the JSX element should have more HTML elements. For instance, we can create a header of a website and header may have a title, subtitle, author or date etc. Remember, we can render only one on JSX element at a time. Let us render more content. To render more content, the JSX element should have more HTML elements. For instance, we can create a header of a website and header may have a title, subtitle, author or date etc. Remember, we can render only one JSX element at a time.
[Live on code pen](https://codepen.io/Asabeneh/full/QWbGWeY). [Live on code pen](https://codepen.io/Asabeneh/full/QWbGWeY).
```html ```html
@ -334,7 +334,7 @@ Let us render more content. To render more content, the JSX element should have
) )
// we render the JSX element using the ReactDOM package // we render the JSX element using the ReactDOM package
// ReactDOM has the render method and the render method takes two argument // ReactDOM has the render method and the render method takes two arguments
ReactDOM.render(header, rootElement) ReactDOM.render(header, rootElement)
</script> </script>
</body> </body>
@ -372,7 +372,7 @@ const footer = (
) )
``` ```
Now, we have three JSX elements:the header, main and footer. The best way to render all the three JSX elements is by wrapping them all in a parent JSX element or putting them in an array. To include JSX element inside another JSX element we use the curly bracket, {} and call the name of the JSX inside the curly bracket. Now, we have three JSX elements: the header, main and footer. The best way to render all of the three JSX elements is by wrapping them all in a parent JSX element or putting them in an array. To include JSX element inside another JSX element we use the curly bracket, {} and call the name of the JSX inside the curly bracket.
```js ```js
// JSX element for the header part of the website // JSX element for the header part of the website
@ -503,7 +503,7 @@ Now, lets us apply style the header part only [Live on code pen](https://codepen
So far, we did not apply any style in the JSX elements. Now, let us add style to our JSX elements. Inline style became very popular after the emergence of react. Let us add border to the header JSX element. So far, we did not apply any style in the JSX elements. Now, let us add style to our JSX elements. Inline style became very popular after the emergence of react. Let us add border to the header JSX element.
To add style to a JSX element we use inline style or className. We inject the style object using {}. Every CSS properties become a key and every CSS properties value become value for the the object. For instance, in the example below, border is a key and '2px solid orange' is a value, color is a key and 'black' is a value, fontSize is a key and '18px' is a value. All two word CSS properties will change to camelCase when we use them as key in the CSS object in react or JavaScript.[Live on code pen](https://codepen.io/Asabeneh/full/ZEGBYbY). To add style to a JSX element we use inline style or className. We inject the style object using {}. Every CSS property becomes a key and every CSS property value becomes a value for the the object. For instance, in the example below, border is a key and '2px solid orange' is a value, color is a key and 'black' is a value, fontSize is a key and '18px' is a value. All two word CSS properties will change to camelCase when we use them as key in the CSS object in React or JavaScript.[Live on code pen](https://codepen.io/Asabeneh/full/ZEGBYbY).
```js ```js
const header = ( const header = (
@ -518,7 +518,7 @@ const header = (
</header> </header>
) )
// or we can write it // or we can write it this way
const style = { border: '2px solid orange', color: 'black', fontSize: '18px' } const style = { border: '2px solid orange', color: 'black', fontSize: '18px' }
@ -533,9 +533,9 @@ const header = (
) )
``` ```
It is good practice to open the browser console while you are developing your application to know if everything goes well. It is good practice to open the browser console while you are developing your application to know, if everything goes well.
Let us keep styling all the JSX elements we have created: the header, main and footer. We can also use regular internal styling to style our application. Using regular style, to target an HTML element we use tag name, id, class, an attribute and other methods. It is very common in the react developer community people use quite a lot classes instead of id. In this material, I will use only class instead of id. Let us keep styling all the JSX elements we have created: the header, main and the footer. We can also use regular internal styling to style our application. Using regular style, to target an HTML element we use tag name, id, class, an attribute and other methods. It is very common in the React developer community - people use classes quite a lot instead of id. In this material, I will use only class instead of id.
In JSX element we write className instead of class because class is a reserved word in JavaScript. Similar to className, htmlFor instead of for in label tag. See the example below. In JSX element we write className instead of class because class is a reserved word in JavaScript. Similar to className, htmlFor instead of for in label tag. See the example below.
@ -549,13 +549,13 @@ const inputField = (
) )
``` ```
The id used in the input element is not for styling purpose instead to refer the label to the input field. The id used in the input element is not for styling purpose, instead to refer the label to the input field.
If class is used instead of className or for instead of htmlFor you will see such kind of warning. If class is used instead of className or for instead of htmlFor you will see such kind of warning.
![Class Name warning](../images/className_warning.png) ![Class Name warning](../images/className_warning.png)
Now, you know how to use the inline style and how to use className and let us style all the JSX elements. Now, you know how to use the inline style and how to use className. Let us style all the JSX elements.
```html ```html
<!DOCTYPE html> <!DOCTYPE html>
@ -644,9 +644,9 @@ Now, you know how to use the inline style and how to use className and let us st
</html> </html>
``` ```
![Styling all jsx elements](../images/styling_all_jsx_elements.png) ![Styling all JSX elements](../images/styling_all_jsx_elements.png)
Instead of style object using regular styling method is more easier than the above. Now, let us use internal style to style all the JSX. It is also possible to use external style method.[Live on code pen](https://codepen.io/Asabeneh/full/QWbGwge) Instead of style object using regular styling method is more easy than the one above. Now, let us use internal style to style all the JSX. It is also possible to use external styling method. [Live on code pen](https://codepen.io/Asabeneh/full/QWbGwge)
```html ```html
<!DOCTYPE html> <!DOCTYPE html>
@ -817,9 +817,9 @@ Instead of style object using regular styling method is more easier than the abo
![Internal Style](../images/internal_style.png) ![Internal Style](../images/internal_style.png)
#### Injecting data to JSX Element #### Injecting data to a JSX Element
So far, we used static data on the JSX elements but we can also pass different data types as a dynamic data. The dynamic data could be string, number, boolean, array or object. Let us see each of the data types step by step. To inject data to a JSX we use the {} bracket. So far, we used static data on the JSX elements, but we can also pass different data types as a dynamic data. The dynamic data could be string, number, boolean, array or object. Let us see each of the data types step by step. To inject data to a JSX we use the {} bracket.
```js ```js
const welcome = 'Welcome to 30 Days Of React' const welcome = 'Welcome to 30 Days Of React'
@ -845,11 +845,11 @@ const header = (
) )
``` ```
Similar to the header JSX element we can implement to main and footer JSX element. Similar to the header JSX element, we can implement data injection to main and footer JSX elements.
##### Injecting a string to JSX Element ##### Injecting a string to a JSX Element
In this section we only inject only strings In this section we inject only strings
```js ```js
const welcome = 'Welcome to 30 Days Of React' const welcome = 'Welcome to 30 Days Of React'
@ -877,7 +877,7 @@ const header = (
) )
``` ```
##### Injecting a number to JSX Element ##### Injecting a number to a JSX Element
```js ```js
const numOne = 3 const numOne = 3
@ -895,11 +895,11 @@ const age = currentYear - yearBorn
const personAge = <p> {age}</p> const personAge = <p> {age}</p>
``` ```
As you can see in the above example, it is possible to do some arithmetic calculation and ternary operations. As you can see in the example above, it is possible to do some arithmetic calculations and ternary operations.
##### Injecting an array to JSX Element ##### Injecting an array to a JSX Element
To give example for an array, let us change the HTML, CSS, JavaScript an array and inject it to the main JSX element below. We will cover in much detail in rendering lists section. To give an example for an array, let us change the HTML, CSS, JavaScript to an array and inject it to the main JSX element below. We will cover more in much detail later, in rendering lists section.
```js ```js
const techs = ['HTML', 'CSS', 'JavaScript'] const techs = ['HTML', 'CSS', 'JavaScript']
@ -921,11 +921,11 @@ const main = (
) )
``` ```
##### Injecting an object to JSX Element ##### Injecting an object to a JSX Element
We can inject string, number, boolean, array data to JSX but we can not directly inject object. We should extract object values first or destructure the content of the object before we inject to the JSX element. For instance, let us write firstName and lastName inside an object and extract them out to use them inside JSX. We can inject string, number, boolean, array data to JSX but we cannot directly inject an object. We should extract object values first or destructure the content of the object before we inject the data to the JSX element. For instance, let us write firstName and lastName inside an object and extract them to use them inside JSX.
Now, let us put everything together. Here in the example below, the data is injected dynamically to the JSX. [Live on code pen](https://codepen.io/Asabeneh/full/YzXWgpZ) Now, let us put everything together. Here, in the example below, the data is injected dynamically to the JSX. [Live on code pen](https://codepen.io/Asabeneh/full/YzXWgpZ)
```html ```html
<!DOCTYPE html> <!DOCTYPE html>
@ -1128,14 +1128,14 @@ Now, let us put everything together. Here in the example below, the data is inje
![Dynamic Data](../images/dynamic_data.png) ![Dynamic Data](../images/dynamic_data.png)
As you can see the lists are all in one line. Therefore, we should format the list the way we want before we inject to JSX. In order to format the list we should modify the array before we will inject to JSX. We can modify the array using _map_. As a react developer you should have a very good understanding of functional programming(map, filter, reduce, find, some, every). If you don't have good understanding of functional programming check out day 1. As you can see the lists are all in one line. Therefore, we should format the list the way we want, before we inject it to JSX. In order to format the list, we should modify the array before we will inject it to JSX. We can modify the array using _map_. As a react developer you should have a very good understanding of functional programming(map, filter, reduce, find, some, every). If you don't have good understanding of functional programming, check out day 1.
```js ```js
const techs = ['HTML', 'CSS', 'JavaScript'] const techs = ['HTML', 'CSS', 'JavaScript']
const techsFormatted = techs.map((tech) => <li>{tech}</li>) const techsFormatted = techs.map((tech) => <li>{tech}</li>)
``` ```
In the following code example, the list is now containing list elements and formatted properly. In the following code example, the list is now containing list elements and it is formatted properly.
```html ```html
<!DOCTYPE html> <!DOCTYPE html>
@ -1337,10 +1337,10 @@ In the following code example, the list is now containing list elements and form
</html> </html>
``` ```
Rendering list Rendering lists
![List Id](../images/map_list_id.png) ![List Id](../images/map_list_id.png)
As you can see above, now the lists are formatted properly but there is warning on the console which says each list child should have a unique key. In the array, we do not have id but it is common to pass id as a unique value when you have id in your data. Now, let us just pass each items as a unique key and remove the warning. As you can see above, now the lists are formatted properly, but there is a warning on the console, which says each list child should have a unique key. In the array, we do not have id, but it is common to pass id as a unique value, when you have id in your data. Now, let us just pass each item with a unique key to remove the warning.
```html ```html
<!DOCTYPE html> <!DOCTYPE html>
@ -1543,9 +1543,9 @@ As you can see above, now the lists are formatted properly but there is warning
</html> </html>
``` ```
![Removing warning ](../images/removing_unique_id_warning.png) ![Removing the warning ](../images/removing_unique_id_warning.png)
Now, you have a very good understanding of how to create JSX element and also how to inject data to JSX. In the next section, we will talk about how to use create-react-app and component. Components are more powerful and useful than JSX. Now, you have a very good understanding of how to create JSX elements and also how to inject data to JSX. In the next section, we will talk about how to use create-react-app and components. Components are more powerful and useful than JSX.
🌕 You are awesome. You have just completed day 2 challenges and you are two steps ahead on your way to greatness. Now do some exercises for your brain and for your muscle. 🌕 You are awesome. You have just completed day 2 challenges and you are two steps ahead on your way to greatness. Now do some exercises for your brain and for your muscle.
@ -1554,34 +1554,34 @@ Now, you have a very good understanding of how to create JSX element and also ho
#### Exercises: What is React? #### Exercises: What is React?
1. What is React? 1. What is React?
2. What is a library ? 2. What is a library?
3. What is single page application ? 3. What is a single page application?
4. What is component ? 4. What is a component ?
5. What is the latest version of react ? 5. What is the latest version of React?
6. What is DOM ? 6. What is DOM?
7. What is React Virtual DOM 7. What is React Virtual DOM?
8. What does a web application or a website(composed of) may have? 8. What does a web application or a website(composed of) have?
#### Exercises: Why React? #### Exercises: Why React?
1. Why you chose to use react? 1. Why did you chose to use react?
2. What measures do you use to know popularity ? 2. What measures do you use to know popularity ?
3. What is more popular, react or Vue ? 3. What is more popular, React or Vue ?
#### Exercises: JSX #### Exercises: JSX
1. What is an HTML element ? 1. What is an HTML element?
2. Write is a self closing HTML element ? 2. How to write a self closing HTML element?
3. What is HTML attribute, write some HTML attributes ? 3. What is an HTML attribute? Write some of them
4. What is JSX ? 4. What is JSX?
5. What is babel ? 5. What is babel?
6. What is a transpiler? 6. What is a transpiler?
#### Exercises: JSX Elements #### Exercises: JSX Elements
1. What is JSX element 1. What is a JSX element?
2. Write your name in JSX element and store it in a name variable 2. Write your name in a JSX element and store it in a name variable
3. Write a JSX element which displays your full name, country, title, gender, email, phone number. Use h1 for the name and p for the rest of the information and store it in a user variable. 3. Write a JSX element which displays your full name, country, title, gender, email, phone number. Use h1 for the name and p for the rest of the information and store it in a user variable
4. Write a footer JSX element 4. Write a footer JSX element
#### Exercises: Inline Style #### Exercises: Inline Style

@ -34,6 +34,8 @@
- [Injecting data to JSX elements](#injecting-data-to-jsx-elements) - [Injecting data to JSX elements](#injecting-data-to-jsx-elements)
- [Importing Media Objects in React](#importing-media-objects-in-react) - [Importing Media Objects in React](#importing-media-objects-in-react)
- [Exercises](#exercises) - [Exercises](#exercises)
- [Exercises: Level 1](#exercises-level-1)
- [Exercises: Level 2](#exercises-level-2)
# Setting Up # Setting Up
@ -734,16 +736,32 @@ The boilerplate code can be found [here](../03/../03_Day_Setting_Up/30-days-of-r
# Exercises # Exercises
## Exercises: Level 1
1. What is module
2. What is package ?
3. What is the difference between a module and a package
4. What is NPM ?
5. What is Webpack ?
6. How do you create a new React project ?
7. What are these files and folders in a project(package.json, package-lock.json or yarn.lock, .gitignore,node_modules and public )
8. What is your favorite code editor (I believe that it is Visual Studio Code) ?
9. Add different Visual Studio Code extensions to imporve your productivity(eg. prettier, ESLint etc)
10. 6. Try to make different module in a different file and import it to index.js.
## Exercises: Level 2
1. Import and render the following images 1. Import and render the following images
![Front end](../images/frontend_technologies.png) ![Front end](../images/frontend_technologies.png)
1.Design the following user card. 2.Design the following user card.
![User Card](../images/user_card_design_jsx.png) ![User Card](../images/user_card_design_jsx.png)
1. Use h1, p, input and button HTML element to create the following design using JSX 3. Use h1, p, input and button HTML element to create the following design using JSX
![News Letter](../images/news_letter_design.png) ![News Letter](../images/news_letter_design.png)
🎉 CONGRATULATIONS ! 🎉 🎉 CONGRATULATIONS ! 🎉
[<< Day 2](../02_Day_Introduction_to_React/02_introduction_to_react.md) | [Day 4 >>](../04_Day_Components/04_components.md) [<< Day 2](../02_Day_Introduction_to_React/02_introduction_to_react.md) | [Day 4 >>](../04_Day_Components/04_components.md)

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

@ -28,6 +28,8 @@
- [Injecting data to JSX in React Component](#injecting-data-to-jsx-in-react-component) - [Injecting data to JSX in React Component](#injecting-data-to-jsx-in-react-component)
- [Further on Functional components](#further-on-functional-components) - [Further on Functional components](#further-on-functional-components)
- [Exercises: Components](#exercises-components) - [Exercises: Components](#exercises-components)
- [Exercises: Level 1](#exercises-level-1)
- [Exercises: Level 2](#exercises-level-2)
# Components # Components
@ -482,8 +484,21 @@ ReactDOM.render(<HexaColor />, rootElement)
# Exercises: Components # Exercises: Components
1.Create functional components and display the following images ## Exercises: Level 1
![Front end](../images/frontend_technologies.png)
1. What is a React Component ?
2. How do you make a React functional component ?
3. What is the difference between a pure JavaScript function and a functional component ?
4. How small is a React component ?
5. Can we make a button or input field component ?
6. Make a reusable Button component
7. Make a reusable InputField component ?
8. Make a reusable alert box component with one div parent element and one p child element of the div(warning alert box, success alert box)
## Exercises: Level 2
1. Create functional components and display the following images
![Front end](../images/frontend_technologies.png)
2.Use functional component to design the following user card. 2.Use functional component to design the following user card.

@ -15,7 +15,7 @@
</div> </div>
</div> </div>
[<< Day 4](../04_Day_Component/04_components.md) | [Day 6 >>]() [<< Day 4](../04_Day_Component/04_components.md) | [Day 6 >>](../06_Day_Map_List_Keys/06_map_list_keys.md)
![30 Days of React banner](../images/30_days_of_react_banner_day_5.jpg) ![30 Days of React banner](../images/30_days_of_react_banner_day_5.jpg)
@ -34,6 +34,8 @@
- [propTypes](#proptypes) - [propTypes](#proptypes)
- [defaultProps](#defaultprops) - [defaultProps](#defaultprops)
- [Exercises: Components and Props](#exercises-components-and-props) - [Exercises: Components and Props](#exercises-components-and-props)
- [Exercises: Level 1](#exercises-level-1)
- [Exercises: Level 2](#exercises-level-2)
# Props # Props
@ -1065,8 +1067,18 @@ We will cover propTypes in detail in other section.
# Exercises: Components and Props # Exercises: Components and Props
1.Create functional components and display the following images ## Exercises: Level 1
![Front end](../images/frontend_technologies.png)
1. What is props in a React component ?
2. How do you access props in React component ?
3. What data types can we pass as a props to components ?
4. What is a propTypes
5. What is a default propTypes
## Exercises: Level 2
1. Create functional components and display the following images
![Front end](../images/frontend_technologies.png)
2.Use functional component to design the following user card. 2.Use functional component to design the following user card.
@ -1082,4 +1094,4 @@ We will cover propTypes in detail in other section.
🎉 CONGRATULATIONS ! 🎉 🎉 CONGRATULATIONS ! 🎉
[<< Day 4](../04_Day_Component/04_components.md) | [Day 6 >>]() [<< Day 4](../04_Day_Component/04_components.md) | [Day 6 >>](../06_Day_Map_List_Keys/06_map_list_keys.md)

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

@ -14,7 +14,7 @@
</div> </div>
[<< Day 5](./../05_Day_Props/05_props.md) | [Day 7 >>]() [<< Day 5](./../05_Day_Props/05_props.md) | [Day 7 >>](../07_Day_Class_Components/07_class_components.md)
![30 Days of React banner](../images/30_days_of_react_banner_day_6.jpg) ![30 Days of React banner](../images/30_days_of_react_banner_day_6.jpg)
@ -25,6 +25,9 @@
- [Mapping array of objects](#mapping-array-of-objects) - [Mapping array of objects](#mapping-array-of-objects)
- [Key in mapping arrays](#key-in-mapping-arrays) - [Key in mapping arrays](#key-in-mapping-arrays)
- [Exercises](#exercises) - [Exercises](#exercises)
- [Exercises: Level 1](#exercises-level-1)
- [Exercises: Level 2](#exercises-level-2)
- [Exercises: Level 3](#exercises-level-3)
# Mapping arrays # Mapping arrays
@ -97,30 +100,29 @@ Let's see how to map array of arrays
import React from 'react' import React from 'react'
import ReactDOM from 'react-dom' import ReactDOM from 'react-dom'
const App = () => { const skills = [
const skills = [ ['HTML', 10],
['HTML', 10], ['CSS', 7],
['CSS', 7], ['JavaScript', 9],
['JavaScript', 9], ['React', 8],
['React', 8], ]
]
// Skill Component
// Skill Component const Skill = ({ skill: [tech, level] }) => (
const Skill = ({ skill: [tech, level] }) => ( <li>
<li> {tech} {level}
{tech} {level} </li>
</li> )
)
// Skills Component // Skills Component
const Skills = ({ skills }) => { const Skills = ({ skills }) => {
const skillsList = skills.map((skill) => <Skill skill={skill} />) const skillsList = skills.map((skill) => <Skill skill={skill} />)
console.log(skillsList) console.log(skillsList)
return <ul>{skillsList}</ul> return <ul>{skillsList}</ul>
} }
const App = () => { const App = () => {
return ( return (
<div className='container'> <div className='container'>
<div> <div>
<h1>Skills Level</h1> <h1>Skills Level</h1>
@ -128,7 +130,7 @@ const App = () => {
</div> </div>
</div> </div>
) )
} }
const rootElement = document.getElementById('root') const rootElement = document.getElementById('root')
ReactDOM.render(<App />, rootElement) ReactDOM.render(<App />, rootElement)
@ -258,6 +260,29 @@ ReactDOM.render(<App />, rootElement)
# Exercises # Exercises
coming soon ... ## Exercises: Level 1
1. Why you need to map an array ?
2. Why we need keys during mapping an array ?
3. What is the importance of destructuring your code ?
4. Does destructuring make your code clean and easy to read ?
## Exercises: Level 2
1. In the following design, evens are green, odds are yellow and prime numbers are red. Build the following colors using React component
![Number Generator](../images/day_6_number_generater_exercise.png)
2. Create the following hexadecimal colors using React component
![Number Generator](../images/day_6_hexadecimal_colors_exercise.png)
## Exercises: Level 3
1.Make the following bar group using given [data](../06_Day_Map_List_Keys/06_map_list_keys_boilerplate/src/data/ten_most_highest_populations.js)
![Ten most highest populations](../images/day_6_ten_highest_populations_exercise.png)
🎉 CONGRATULATIONS ! 🎉
[<< Day 5](./../05_Day_Props/05_props.md) | [Day 7 >>]() [<< Day 5](./../05_Day_Props/05_props.md) | [Day 7 >>](../07_Day_Class_Components/07_class_components.md)

@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# production
/build
# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*

@ -0,0 +1,5 @@
# 30 Days of React App: Day 3
In the project directory, you can run to start the project
### `npm start`

@ -0,0 +1,34 @@
{
"name": "30-days-of-react",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-scripts": "3.4.3"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}

@ -0,0 +1,111 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link
href="https://fonts.googleapis.com/css?family=Montserrat:300,400,500|Roboto:300,400,500&display=swap"
rel="stylesheet"
/>
<meta
name="description"
content="Web site created using create-react-app"
/>
<title>30 Days Of React App</title>
<style>
/* == General style === */
* {
box-sizing: border-box;
padding: 0;
margin: 0;
}
html,
body {
height: 100%;
line-height: 1.5;
font-family: 'Montserrat';
font-weight: 300;
color: black;
}
.root {
min-height: 100%;
position: relative;
}
.header-wrapper,
.main-wrapper,
.footer-wrapper {
width: 85%;
margin: auto;
}
.header-wrapper,
.main-wrapper {
padding: 10px;
margin: 2px auto;
}
h1 {
font-size: 70px;
font-weight: 300;
}
h2,
h3 {
font-weight: 300;
}
header {
background-color: #61dbfb;
padding: 25;
padding: 10px;
}
main {
padding: 10px;
padding-bottom: 60px;
/* Height of the footer */
}
ul {
margin-left: 15px;
}
ul li {
list-style: none;
}
footer {
position: absolute;
bottom: 0;
width: 100%;
height: 60px;
/* Height of the footer */
background: #6cf;
}
.footer-wrapper {
font-weight: 400;
text-align: center;
line-height: 60px;
}
.user-card {
margin-top: 10px;
}
.user-card > img {
border-radius: 50%;
width: 14%;
}
</style>
</head>
<body>
<div id="root"></div>
</body>
</html>

@ -0,0 +1,13 @@
export const tenHighestPopulation = [
{ country: 'World', population: 7693165599 },
{ country: 'China', population: 1377422166 },
{ country: 'India', population: 1295210000 },
{ country: 'United States of America', population: 323947000 },
{ country: 'Indonesia', population: 258705000 },
{ country: 'Brazil', population: 206135893 },
{ country: 'Pakistan', population: 194125062 },
{ country: 'Nigeria', population: 186988000 },
{ country: 'Bangladesh', population: 161006790 },
{ country: 'Russian Federation', population: 146599183 },
{ country: 'Japan', population: 126960000 },
]

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

@ -0,0 +1,49 @@
import React from 'react'
import ReactDOM from 'react-dom'
// importing data
import { countriesData } from './data/countries'
import { tenMostHighestPopulations } from './data/ten_most_highest_populations'
const countries = [
{ name: 'Finland', city: 'Helsinki' },
{ name: 'Sweden', city: 'Stockholm' },
{ name: 'Denmark', city: 'Copenhagen' },
{ name: 'Norway', city: 'Oslo' },
{ name: 'Iceland', city: 'Reykjavík' },
]
// Country component
const Country = ({ country: { name, city } }) => {
return (
<div>
<h1>{name}</h1>
<small>{city}</small>
</div>
)
}
// countries component
const Countries = ({ countries }) => {
const countryList = countries.map((country) => (
<Country key={country.name} country={country} />
))
return <div>{countryList}</div>
}
// The App, or the parent or the container component
// Functional Component
const App = () => {
return (
<div className='app'>
<div>
<h1>Countries List</h1>
<Countries countries={countries} />
</div>
</div>
)
}
const rootElement = document.getElementById('root')
ReactDOM.render(<App />, rootElement)

File diff suppressed because it is too large Load Diff

@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
# dependencies
/node_modules
/.pnp
.pnp.js
# testing
/coverage
# production
/build
# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local
npm-debug.log*
yarn-debug.log*
yarn-error.log*

@ -0,0 +1,5 @@
# 30 Days of React App: Day 3
In the project directory, you can run to start the project
### `npm start`

@ -0,0 +1,34 @@
{
"name": "30-days-of-react",
"version": "0.1.0",
"private": true,
"dependencies": {
"@testing-library/jest-dom": "^4.2.4",
"@testing-library/react": "^9.3.2",
"@testing-library/user-event": "^7.1.2",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-scripts": "3.4.3"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test",
"eject": "react-scripts eject"
},
"eslintConfig": {
"extends": "react-app"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}

@ -0,0 +1,111 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link
href="https://fonts.googleapis.com/css?family=Montserrat:300,400,500|Roboto:300,400,500&display=swap"
rel="stylesheet"
/>
<meta
name="description"
content="Web site created using create-react-app"
/>
<title>30 Days Of React App</title>
<style>
/* == General style === */
* {
box-sizing: border-box;
padding: 0;
margin: 0;
}
html,
body {
height: 100%;
line-height: 1.5;
font-family: 'Montserrat';
font-weight: 300;
color: black;
}
.root {
min-height: 100%;
position: relative;
}
.header-wrapper,
.main-wrapper,
.footer-wrapper {
width: 85%;
margin: auto;
}
.header-wrapper,
.main-wrapper {
padding: 10px;
margin: 2px auto;
}
h1 {
font-size: 70px;
font-weight: 300;
}
h2,
h3 {
font-weight: 300;
}
header {
background-color: #61dbfb;
padding: 25;
padding: 10px;
}
main {
padding: 10px;
padding-bottom: 60px;
/* Height of the footer */
}
ul {
margin-left: 15px;
}
ul li {
list-style: none;
}
footer {
position: absolute;
bottom: 0;
width: 100%;
height: 60px;
/* Height of the footer */
background: #6cf;
}
.footer-wrapper {
font-weight: 400;
text-align: center;
line-height: 60px;
}
.user-card {
margin-top: 10px;
}
.user-card > img {
border-radius: 50%;
width: 14%;
}
</style>
</head>
<body>
<div id="root"></div>
</body>
</html>

@ -0,0 +1,13 @@
export const tenHighestPopulation = [
{ country: 'World', population: 7693165599 },
{ country: 'China', population: 1377422166 },
{ country: 'India', population: 1295210000 },
{ country: 'United States of America', population: 323947000 },
{ country: 'Indonesia', population: 258705000 },
{ country: 'Brazil', population: 206135893 },
{ country: 'Pakistan', population: 194125062 },
{ country: 'Nigeria', population: 186988000 },
{ country: 'Bangladesh', population: 161006790 },
{ country: 'Russian Federation', population: 146599183 },
{ country: 'Japan', population: 126960000 },
]

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 82 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 18 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

@ -0,0 +1,194 @@
// index.js
import React from 'react'
import ReactDOM from 'react-dom'
import asabenehImage from './images/asabeneh.jpg'
// Fuction to show month date year
// User Card Component
const UserCard = ({ user: { firstName, lastName, image } }) => (
<div className='user-card'>
<img src={image} alt={firstName} />
<h2>
{firstName}
{lastName}
</h2>
</div>
)
// A button component
const Button = ({ text, onClick, style }) => (
<button style={style} onClick={onClick}>
{text}
</button>
)
// CSS styles in JavaScript Object
const buttonStyles = {
backgroundColor: '#61dbfb',
padding: 10,
border: 'none',
borderRadius: 5,
margin: 3,
cursor: 'pointer',
fontSize: 18,
color: 'white',
}
// class based component
class Header extends React.Component {
constructor(props) {
super(props)
// the code inside the constructor run before any other code
}
render() {
console.log(this.props.data)
const {
welcome,
title,
subtitle,
author: { firstName, lastName },
date,
} = this.props.data
return (
<header>
<div className='header-wrapper'>
<h1>{welcome}</h1>
<h2>{title}</h2>
<h3>{subtitle}</h3>
<p>
{firstName} {lastName}
</p>
<small>{date}</small>
</div>
</header>
)
}
}
// TechList Component
// class base component
class TechList extends React.Component {
constructor(props) {
super(props)
}
render() {
const { techs } = this.props
const techsFormatted = techs.map((tech) => <li key={tech}>{tech}</li>)
return techsFormatted
}
}
// Main Component
// Class Component
class Main extends React.Component {
constructor(props) {
super(props)
}
render() {
return (
<main>
<div className='main-wrapper'>
<p>Prerequisite to get started react.js:</p>
<ul>
<TechList techs={this.props.techs} />
</ul>
<UserCard user={this.props.user} />
<Button
text='Greet People'
onClick={this.props.greetPeople}
style={buttonStyles}
/>
<Button
text='Show Time'
onClick={this.props.handleTime}
style={buttonStyles}
/>
</div>
</main>
)
}
}
// Footer Component
// Class component
class Footer extends React.Component {
constructor(props) {
super(props)
}
render() {
return (
<footer>
<div className='footer-wrapper'>
<p>Copyright {this.props.date.getFullYear()}</p>
</div>
</footer>
)
}
}
class App extends React.Component {
showDate = (time) => {
const months = [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December',
]
const month = months[time.getMonth()].slice(0, 3)
const year = time.getFullYear()
const date = time.getDate()
return ` ${month} ${date}, ${year}`
}
handleTime = () => {
alert(this.showDate(new Date()))
}
greetPeople = () => {
alert('Welcome to 30 Days Of React Challenge, 2020')
}
render() {
const data = {
welcome: 'Welcome to 30 Days Of React',
title: 'Getting Started React',
subtitle: 'JavaScript Library',
author: {
firstName: 'Asabeneh',
lastName: 'Yetayeh',
},
date: 'Oct 7, 2020',
}
const techs = ['HTML', 'CSS', 'JavaScript']
// copying the author from data object to user variable using spread operator
const user = { ...data.author, image: asabenehImage }
return (
<div className='app'>
<Header data={data} />
<Main
user={user}
techs={techs}
handleTime={this.handleTime}
greetPeople={this.greetPeople}
/>
<Footer date={new Date()} />
</div>
)
}
}
const rootElement = document.getElementById('root')
ReactDOM.render(<App />, rootElement)

@ -0,0 +1,838 @@
<div align="center">
<h1> 30 Days Of React: Class Components </h1>
<a class="header-badge" target="_blank" href="https://www.linkedin.com/in/asabeneh/">
<img src="https://img.shields.io/badge/style--5eba00.svg?label=LinkedIn&logo=linkedin&style=social">
</a>
<a class="header-badge" target="_blank" href="https://twitter.com/Asabeneh">
<img alt="Twitter Follow" src="https://img.shields.io/twitter/follow/asabeneh?style=social">
</a>
<sub>Author:
<a href="https://www.linkedin.com/in/asabeneh/" target="_blank">Asabeneh Yetayeh</a><br>
<small> October, 2020</small>
</sub>
</div>
[<< Day 6](../06_Day_Map_List_Keys/06_map_list_keys.md) | [Day 8 >>](../07_Day_Class_Components/07_class_components.md)
![30 Days of React banner](../images/30_days_of_react_banner_day_7.jpg)
- [Class Components](#class-components)
- [Accessing props in Class components](#accessing-props-in-class-components)
- [Methods in Class based component](#methods-in-class-based-component)
- [Exercises](#exercises)
- [Exercises: Level 1](#exercises-level-1)
- [Exercises: Level 2](#exercises-level-2)
# Class Components
In the previous sections, we have covered JSX, functional component and props. In this section, we will cover class components or statefull component. Only class based components used to have state and life cycle methods. However, after React version 16.8.0 functional components can have state and life cycle using React Hooks. In 30 Days Of React challenge, we will cover React before 16.8.0 and after, that mean both old and newest version. There are lots of codes written in older version and at some point it may need migration. In addition, to understand React very well someone has to understand class based component too.
All the previous components are functional components. Let us make also class based component. Class based component is made using JavaScript class and it inherits from react Component. Let us learn how to make a class based component by converting all the functional components we made previously. It is not important to convert all but we are converting them for the sake of learning how to change functional components to class components.
```js
// Pure JavaScript class and child
// Imagine this what we import from React package
class Component {
constructor(props) {}
}
// This how we make class based components by inheriting from the parent
class Child extends Component {
constructor(props) {
super(props)
}
}
```
Functional React component
```js
// index.js
import React from 'react'
import ReactDOM from 'react-dom'
// Header Component
// Functional component
const Header = () => (
<header>
<div className='header-wrapper'>
<h1>Welcome to 30 Days Of React</h1>
<h2>Getting Started React</h2>
<h3>JavaScript Library</h3>
<p>Asabeneh Yetayeh</p>
<small>Oct 6, 2020</small>
</div>
</header>
)
const rootElement = document.getElementById('root')
ReactDOM.render(<Header />, rootElement)
```
Class based React component is a child of React.Component and it has a built-in render method and it may have a constructor.
```js
//index.js
import React from 'react'
import ReactDOM from 'react-dom'
// class based component
class Header extends React.Component {
render() {
return (
<header>
<div className='header-wrapper'>
<h1>Welcome to 30 Days Of React</h1>
<h2>Getting Started React</h2>
<h3>JavaScript Library</h3>
<p>Asabeneh Yetayeh</p>
<small>Oct 7, 2020</small>
</div>
</header>
)
}
}
const rootElement = document.getElementById('root')
ReactDOM.render(<Header />, rootElement)
```
Let's see the above component with a constructor
```js
//index.js
import React from 'react'
import ReactDOM from 'react-dom'
// class base component
class Header extends React.Component {
constructor(props) {
super(props)
// the code inside the constructor run before any other code
}
render() {
return (
<header>
<div className='header-wrapper'>
<h1>Welcome to 30 Days Of React</h1>
<h2>Getting Started React</h2>
<h3>JavaScript Library</h3>
<p>Asabeneh Yetayeh</p>
<small>Oct 7, 2020</small>
</div>
</header>
)
}
}
const rootElement = document.getElementById('root')
ReactDOM.render(<Header />, rootElement)
```
Let's change all the functional component to class based components
```js
// TechList Component
// functional component
const TechList = () => {
const techs = ['HTML', 'CSS', 'JavaScript']
const techsFormatted = techs.map((tech) => <li key={tech}>{tech}</li>)
return techsFormatted
}
// TechList Component
// class base component
class TechList extends React.Component {
constructor(props) {
super(props)
}
render() {
const techs = ['HTML', 'CSS', 'JavaScript']
const techsFormatted = techs.map((tech) => <li key={tech}>{tech}</li>)
return techsFormatted
}
}
// Main Component
// Functional Component
const Main = () => (
<main>
<div className='main-wrapper'>
<p>Prerequisite to get started react.js:</p>
<ul>
<TechList />
</ul>
</div>
</main>
)
// Main Component
// Class Component
class Main extends React.Component {
constructor(props) {
super(props)
}
render() {
return (
<main>
<div className='main-wrapper'>
<p>Prerequisite to get started react.js:</p>
<ul>
<TechList />
</ul>
</div>
</main>
)
}
}
// Footer Component
// Functional component
const Footer = () => (
<footer>
<div className='footer-wrapper'>
<p>Copyright 2020</p>
</div>
</footer>
)
// Footer Component
// Class component
class Footer extends React.Component {
constructor(props) {
super(props)
}
render() {
return (
<footer>
<div className='footer-wrapper'>
<p>Copyright 2020</p>
</div>
</footer>
)
}
}
// The App, or the parent or the container component
// Functional Component
const App = () => (
<div className='app'>
<Header />
<Main />
<Footer />
</div>
)
// The App, or the parent or the container component
// Class Component
class App extends React.Component {
constructor(props) {
super(props)
}
render() {
return (
<div className='app'>
<Header />
<Main />
<Footer />
</div>
)
}
}
```
Let's put all the class based components together in one file.
```js
//index.js
import React from 'react'
import ReactDOM from 'react-dom'
// class base component
class Header extends React.Component {
constructor(props) {
super(props)
// the code inside the constructor run before any other code
}
render() {
return (
<header>
<div className='header-wrapper'>
<h1>Welcome to 30 Days Of React</h1>
<h2>Getting Started React</h2>
<h3>JavaScript Library</h3>
<p>Asabeneh Yetayeh</p>
<small>Oct 7, 2020</small>
</div>
</header>
)
}
}
// TechList Component
// class base component
class TechList extends React.Component {
constructor(props) {
super(props)
}
render() {
const techs = ['HTML', 'CSS', 'JavaScript']
const techsFormatted = techs.map((tech) => <li key={tech}>{tech}</li>)
return techsFormatted
}
}
// Main Component
// Class Component
class Main extends React.Component {
constructor(props) {
super(props)
}
render() {
return (
<main>
<div className='main-wrapper'>
<p>Prerequisite to get started react.js:</p>
<ul>
<TechList />
</ul>
</div>
</main>
)
}
}
// Footer Component
// Class component
class Footer extends React.Component {
constructor(props) {
super(props)
}
render() {
return (
<footer>
<div className='footer-wrapper'>
<p>Copyright 2020</p>
</div>
</footer>
)
}
}
// The App, or the parent or the container component
// Class Component
class App extends React.Component {
constructor(props) {
super(props)
}
render() {
return (
<div className='app'>
<Header />
<Main />
<Footer />
</div>
)
}
}
const rootElement = document.getElementById('root')
ReactDOM.render(<App />, rootElement)
```
## Accessing props in Class components
We stated that props is a means to send data from on component to another or we can call it that props is a data carrier. Therefore, we should handle props in class based component too. We can access props of a class based component using the keyword _this_. See the example below.
```js
// index.js
import React from 'react'
import ReactDOM from 'react-dom'
// class based component
class Header extends React.Component {
constructor(props) {
super(props)
// the code inside the constructor run before any other code
}
render() {
return (
<header>
<div className='header-wrapper'>
<h1>{this.props.data.welcome}</h1>
<h2>{this.props.data.title}</h2>
<h3>
{this.props.data.author.firstName} {this.props.data.author.lastName}
</h3>
<small>{this.props.data.date}</small>
</div>
</header>
)
}
}
const App = () => {
const data = {
welcome: 'Welcome to 30 Days Of React',
title: 'Getting Started React',
subtitle: 'JavaScript Library',
author: {
firstName: 'Asabeneh',
lastName: 'Yetayeh',
},
date: 'Oct 7, 2020',
}
return (
<div className='app'>
<Header data={data} />
</div>
)
}
const rootElement = document.getElementById('root')
ReactDOM.render(<App />, rootElement)
```
As you can see in the above example, to get the data out from props we have write _props.data_ every time. We can avoid this repetition using destructuring.
```js
// index.js
import React from 'react'
import ReactDOM from 'react-dom'
// class based component
class Header extends React.Component {
constructor(props) {
super(props)
// the code inside the constructor run before any other code
}
render() {
console.log(this.props.data)
const {
welcome,
title,
subtitle,
author: { firstName, lastName },
date,
} = this.props.data
return (
<header>
<div className='header-wrapper'>
<h1>{welcome}</h1>
<h2>{title}</h2>
<h3>{subtitle}</h3>
<p>
{firstName} {lastName}
</p>
<small>{date}</small>
</div>
</header>
)
}
}
const App = () => {
const data = {
welcome: 'Welcome to 30 Days Of React',
title: 'Getting Started React',
subtitle: 'JavaScript Library',
author: {
firstName: 'Asabeneh',
lastName: 'Yetayeh',
},
date: 'Oct 6, 2020',
}
return (
<div className='app'>
<Header data={data} />
</div>
)
}
const rootElement = document.getElementById('root')
ReactDOM.render(<App />, rootElement)
```
As you can see, the above code cleaner than the previous. Now, let's clean all the components we have and put all together.
```js
// index.js
import React from 'react'
import ReactDOM from 'react-dom'
// class based component
class Header extends React.Component {
constructor(props) {
super(props)
// the code inside the constructor run before any other code
}
render() {
console.log(this.props.data)
const {
welcome,
title,
subtitle,
author: { firstName, lastName },
date,
} = this.props.data
return (
<header>
<div className='header-wrapper'>
<h1>{welcome}</h1>
<h2>{title}</h2>
<h3>{subtitle}</h3>
<p>
{firstName} {lastName}
</p>
<small>{date}</small>
</div>
</header>
)
}
}
// TechList Component
// class base component
class TechList extends React.Component {
constructor(props) {
super(props)
}
render() {
const { techs } = this.props
const techsFormatted = techs.map((tech) => <li key={tech}>{tech}</li>)
return techsFormatted
}
}
// Main Component
// Class Component
class Main extends React.Component {
constructor(props) {
super(props)
}
render() {
return (
<main>
<div className='main-wrapper'>
<p>Prerequisite to get started react.js:</p>
<ul>
<TechList techs={this.props.techs} />
</ul>
</div>
</main>
)
}
}
// Footer Component
// Class component
class Footer extends React.Component {
constructor(props) {
super(props)
}
render() {
return (
<footer>
<div className='footer-wrapper'>
<p>Copyright {this.props.date.getFullYear()}</p>
</div>
</footer>
)
}
}
class App extends React.Component {
render() {
const data = {
welcome: 'Welcome to 30 Days Of React',
title: 'Getting Started React',
subtitle: 'JavaScript Library',
author: {
firstName: 'Asabeneh',
lastName: 'Yetayeh',
},
date: 'Oct 7, 2020',
}
const techs = ['HTML', 'CSS', 'JavaScript']
return (
<div className='app'>
<Header data={data} />
<Main techs={techs} />
<Footer date={new Date()} />
</div>
)
}
}
const rootElement = document.getElementById('root')
ReactDOM.render(<App />, rootElement)
```
## Methods in Class based component
We access methods in class based component. Most of the time, we write different methods on the parent component and we pass them to child components. Let's see the implementation.
Let's add a method on this component.
```js
//index.js
import React from 'react'
import ReactDOM from 'react-dom'
// class based component
class Header extends React.Component {
greetPeople = () => {
alert('Welcome to 30 Days Of React Challenge, 2020')
}
render() {
return (
<header>
<div className='header-wrapper'>
<h1>Welcome to 30 Days Of React</h1>
<h2>Getting Started React</h2>
<h3>JavaScript Library</h3>
<p>Asabeneh Yetayeh</p>
<small>Oct 7, 2020</small>
<button onClick={this.greetPeople}> Greet </button>
</div>
</header>
)
}
}
const rootElement = document.getElementById('root')
ReactDOM.render(<Header />, rootElement)
```
The invoking or calling of the method triggers when the event occurs. Therefore, whenever you pass a method to an event listener do not invoke the method.
Now, let's the code we had add all the necessary methods.
```js
// index.js
import React from 'react'
import ReactDOM from 'react-dom'
import asabenehImage from './images/asabeneh.jpg'
// Fuction to show month date year
// User Card Component
const UserCard = ({ user: { firstName, lastName, image } }) => (
<div className='user-card'>
<img src={image} alt={firstName} />
<h2>
{firstName}
{lastName}
</h2>
</div>
)
// A button component
const Button = ({ text, onClick, style }) => (
<button style={style} onClick={onClick}>
{text}
</button>
)
// CSS styles in JavaScript Object
const buttonStyles = {
backgroundColor: '#61dbfb',
padding: 10,
border: 'none',
borderRadius: 5,
margin: 3,
cursor: 'pointer',
fontSize: 18,
color: 'white',
}
// class based component
class Header extends React.Component {
constructor(props) {
super(props)
// the code inside the constructor run before any other code
}
render() {
console.log(this.props.data)
const {
welcome,
title,
subtitle,
author: { firstName, lastName },
date,
} = this.props.data
return (
<header>
<div className='header-wrapper'>
<h1>{welcome}</h1>
<h2>{title}</h2>
<h3>{subtitle}</h3>
<p>
{firstName} {lastName}
</p>
<small>{date}</small>
</div>
</header>
)
}
}
// TechList Component
// class base component
class TechList extends React.Component {
constructor(props) {
super(props)
}
render() {
const { techs } = this.props
const techsFormatted = techs.map((tech) => <li key={tech}>{tech}</li>)
return techsFormatted
}
}
// Main Component
// Class Component
class Main extends React.Component {
constructor(props) {
super(props)
}
render() {
return (
<main>
<div className='main-wrapper'>
<p>Prerequisite to get started react.js:</p>
<ul>
<TechList techs={this.props.techs} />
</ul>
<UserCard user={this.props.user} />
<Button
text='Greet People'
onClick={this.props.greetPeople}
style={buttonStyles}
/>
<Button
text='Show Time'
onClick={this.props.handleTime}
style={buttonStyles}
/>
</div>
</main>
)
}
}
// Footer Component
// Class component
class Footer extends React.Component {
constructor(props) {
super(props)
}
render() {
return (
<footer>
<div className='footer-wrapper'>
<p>Copyright {this.props.date.getFullYear()}</p>
</div>
</footer>
)
}
}
class App extends React.Component {
showDate = (time) => {
const months = [
'January',
'February',
'March',
'April',
'May',
'June',
'July',
'August',
'September',
'October',
'November',
'December',
]
const month = months[time.getMonth()].slice(0, 3)
const year = time.getFullYear()
const date = time.getDate()
return ` ${month} ${date}, ${year}`
}
handleTime = () => {
alert(this.showDate(new Date()))
}
greetPeople = () => {
alert('Welcome to 30 Days Of React Challenge, 2020')
}
render() {
const data = {
welcome: 'Welcome to 30 Days Of React',
title: 'Getting Started React',
subtitle: 'JavaScript Library',
author: {
firstName: 'Asabeneh',
lastName: 'Yetayeh',
},
date: 'Oct 7, 2020',
}
const techs = ['HTML', 'CSS', 'JavaScript']
// copying the author from data object to user variable using spread operator
const user = { ...data.author, image: asabenehImage }
return (
<div className='app'>
<Header data={data} />
<Main
user={user}
techs={techs}
handleTime={this.handleTime}
greetPeople={this.greetPeople}
/>
<Footer date={new Date()} />
</div>
)
}
}
const rootElement = document.getElementById('root')
ReactDOM.render(<App />, rootElement)
```
Most of the time the container or the parent component can be written as class component and others as functional or presentational components. Data usually flows from parent components to child component and it is unidirectional. However, the latest version of react can allow us to write every component in our application only with functional components. This was impossible in previous versions.
In next section, we will cover state which is the heart of React. State allows React component to rerender when whenever there is a change in state.
# Exercises
## Exercises: Level 1
1. How do you write a pure JavaScript function
2. What is inheritance and how do you make a child from a parent class?
3. What is class based React component ?
4. What is the difference between functional React component and class based React component ?
5. What is the use cases of class based component ?
6. What is React life cycle ? (not covered yet) ?
7. What is state in React ?
## Exercises: Level 2
Learn more about class based component by changing previous days exercises to class based components
🎉 CONGRATULATIONS ! 🎉
[<< Day 6](../06_Day_Map_List_Keys/06_map_list_keys.md) | [Day 8 >>](../07_Day_Class_Components/07_class_components.md)

Binary file not shown.

After

Width:  |  Height:  |  Size: 122 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 92 KiB

@ -22,13 +22,20 @@
| # Day | Topics | | # Day | Topics |
| ----- | :-------------------------------------------------------------------------------------------------------------------------: | | ----- | :-------------------------------------------------------------------------------------------------------------------------: |
| 00 | [Introduction](#introduction)<br> [How to Use Repo](#how-to-use-repo)<br> [Requirements](#requirements)<br> [Setup](#setup) | |00|[Introduction](#introduction)<br> [How to Use Repo](#how-to-use-repo)<br> [Requirements](#requirements)<br> [Setup](#setup)|
| 01 | [JavaScript Refresher](./01_Day_JavaScript_Refresher/01_javascript_refresher.md) | |01|[JavaScript Refresher](./01_Day_JavaScript_Refresher/01_javascript_refresher.md)|
| 02 | [Getting Started React](./02_Day_Introduction_to_React/02_introduction_to_react.md) | |02|[Getting Started React](./02_Day_Introduction_to_React/02_introduction_to_react.md)|
| 03 | [Setting Up](./03_Day_Setting_Up/03_day_setting_up.md) | |03|[Setting Up](./03_Day_Setting_Up/03_day_setting_up.md)|
| 04 | [Components](./04_Day_Component/04_components.md) | |04|[Components](./04_Day_Component/04_components.md)|
| 05 | [Props](./05_Day_Props/05_props.md) | |05|[Props](./05_Day_Props/05_props.md)|
| 06 | [List, Map and Keys](./06_Day_Map_List_Keys/05_map_list_keys.md) | |06|[List, Map and Keys](../06_Day_Map_List_Keys/06_map_list_keys.md)|
|07|[Class Components](./07_Day_Class_Components/07_class_components.md)|
|08|[States 😞](./08_Day_States/08_states.md)|
|09|[Conditional Rendering 😞]()|
|10|[Events 😞]()|
|11|[Forms 😞]()|
|13|[Controlled and Uncondrolled Component 😞]()|
🧡🧡🧡 HAPPY CODING 🧡🧡🧡<div> 🧡🧡🧡 HAPPY CODING 🧡🧡🧡<div>
<small>Support [**Asabeneh**](https://www.patreon.com/asabeneh?fan_landing=true) to create more educational materials</small> <small>Support [**Asabeneh**](https://www.patreon.com/asabeneh?fan_landing=true) to create more educational materials</small>
@ -45,7 +52,7 @@
- [Clone your Fork](#clone-your-fork) - [Clone your Fork](#clone-your-fork)
- [Create a New Branch](#create-a-new-branch) - [Create a New Branch](#create-a-new-branch)
- [Structure Exercise Solutions](#structure-exercise-solutions) - [Structure Exercise Solutions](#structure-exercise-solutions)
- [Commit Excercise Solutions](#commit-excercise-solutions) - [Commit Exercise Solutions](#commit-exercise-solutions)
- [Update your Fork Daily](#update-your-fork-daily) - [Update your Fork Daily](#update-your-fork-daily)
- [Setup](#setup) - [Setup](#setup)
- [Install Node.js](#install-nodejs) - [Install Node.js](#install-nodejs)
@ -73,8 +80,8 @@ In this step by step 30 Days React challenge, you will learn React which is one
React can do everything that JavaScript can do. React can be used **_to add interactivity to websites, to develop mobile apps, desktop applications, games_**. React can do everything that JavaScript can do. React can be used **_to add interactivity to websites, to develop mobile apps, desktop applications, games_**.
I believe you will learn quite a lot in the next 30 days and your programming and problem solving skills will also be improved significantly. I believe you will learn quite a lot in the next 30 days and your programming and problem solving skills will also be improved significantly.
I will use conversational English and less jargons to write this challenge. The content will be continuously updated. If you find a typo or grammar mistakes don't surprised because I don't do any proof read before I publish it. I would recommend you to focus on the main message of the challenge instead of the English and some minor mistakes. I really appreciate if you send me pull requests for improvement and remember to pull first from master before you send pull requests. Most of the images I have used in this challenge came from 30DaysOfJavaScript challenge therefore you may need to rename file names and folders 30DaysOfReact. I will use conversational English and less jargons to write this challenge. The content will be continuously updated. If you find a typo or grammar mistakes don't be surprised because I don't do any proof read before I publish it. I would recommend you to focus on the main message of the challenge instead of the English and some minor mistakes. I really appreciate if you send me pull requests for improvement and remember to pull first from master before you send pull requests. Most of the images I have used in this challenge came from 30DaysOfJavaScript challenge therefore you may need to rename file names and folders 30DaysOfReact.
If you are good at arrays, loops, functions, objects, functional programming, destructuring and spreading and class then you will be able to follow the challenge properly. Otherwise, I strongly recommend you to check [30DaysOfJavaScript](https://github.com/Asabeneh/30-Days-Of-React). If you are good at arrays, loops, functions, objects, functional programming, destructuring and spreading and class then you will be able to follow the challenge properly. Otherwise, I strongly recommend you to check [30DaysOfJavaScript](https://github.com/Asabeneh/30-Days-Of-JavaScript).
## Requirements ## Requirements
@ -120,7 +127,7 @@ mkdir -p solutions/day-01 # `-p` helps create nested directories
touch solutions/day-01/level1.js # touch creates a file touch solutions/day-01/level1.js # touch creates a file
``` ```
### Commit Excercise Solutions ### Commit Exercise Solutions
Commit your solutions to your Fork Commit your solutions to your Fork
@ -268,7 +275,7 @@ This is a multiline comment
##### Syntax ##### Syntax
Programming languages are similar to human languages. English or many other language uses words, phrases, sentences,compound sentences and other more to convey a meaningful message. The English meaning of syntax is _the arrangement of words and phrases to create well-formed sentences in a language_. The technical definition of syntax is _the structure of statements in a computer language._ Programing languages have syntax. JavaScript is a programming language and like other programming languages it has its own syntax. If we do not write a syntax that JavaScript understands, it will raise different types of errors. We will explore different kinds of JavaScript errors later. For now, let us see syntax errors. Programming languages are similar to human languages. English or many other language uses words, phrases, sentences, compound sentences and other more to convey a meaningful message. The English meaning of syntax is _the arrangement of words and phrases to create well-formed sentences in a language_. The technical definition of syntax is _the structure of statements in a computer language._ Programing languages have syntax. JavaScript is a programming language and like other programming languages it has its own syntax. If we do not write a syntax that JavaScript understands, it will raise different types of errors. We will explore different kinds of JavaScript errors later. For now, let us see syntax errors.
![Error](images/raising_syntax_error.png) ![Error](images/raising_syntax_error.png)

Loading…
Cancel
Save