Update readMe.md

pull/93/head
Daniel Oluborode 5 years ago committed by GitHub
parent f231757a79
commit c6e6fa1363
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -30,7 +30,7 @@
</div>
[Day 2 >>](https://github.com/Asabeneh/30DaysOfJavaScript/blob/master/02_Day/02_day_data_types.md)
[Go to Day 2 >>](https://github.com/Asabeneh/30DaysOfJavaScript/blob/master/02_Day/02_day_data_types.md)
![Thirty Days Of JavaScript](./images/day_1_1.png)
@ -55,7 +55,6 @@
- [Inline Script](#inline-script)
- [Internal Script](#internal-script)
- [External Script](#external-script)
- [Multiple External Scripts](#multiple-external-scripts)
- [Introduction to Data types](#introduction-to-data-types)
- [Number](#number)
- [String](#string)
@ -70,30 +69,26 @@
# 📔Day 1
## Introduction
**Congratulations** on deciding to participate in 30 days of JavaScript programming challenge. In this challenge, you will learn everything you need to be a JavaScript programmer, and in general, the whole concept of programming. At the end of the challenge, you will get a 30DaysOfJavaScript programming challenge completion certificate. In case you need help or would like to help others, you may join the [telegram group](https://t.me/ThirtyDaysOfJavaScript).
**Congratulations** for deciding to participate in 30 days of JavaScript programming challenge. In this challenge you will learn everything you need to be a JavaScript programmer, and in general, the whole concept of programming. In the end of the challenge you will get a 30DaysOfJavaScript programming challenge completion certificate. In case you need help or if you would like to help others you may join the [telegram group](https://t.me/ThirtyDaysOfJavaScript).
**A 30DaysOfJavaScript** challenge is a guide for both beginners and advanced JavaScript developers. Welcome to JavaScript. I enjoy using and teaching JavaScript and I hope you will do so too. JavaScript is the language of the web.
**A 30DaysOfJavaScript** challenge is a guide for both beginners and advanced JavaScript developers. Welcome to JavaScript. JavaScript is the language of the web. I enjoy using and teaching JavaScript, and I hope you will do so too.
In this step by step tutorial, you will learn JavaScript, the most popular programming language in the history of mankind.
You use JavaScript **_to add interactivity to websites, to develop mobile apps, desktop applications, games_** and nowadays JavaScript can be used for **_machine learning_** and **_AI_**.
**_JavaScript (JS)_** has increased in popularity in recent years and has been the leading
programming language for six consecutive years and is the most used programming language on
Github.
In this step-by-step tutorial, you will learn JavaScript, the most popular programming language in the history of mankind.
JavaScript is used to **_add interactivity to websites, to develop mobile apps, desktop applications, games_** and nowadays, JavaScript can be used for **_machine learning_** and **_AI_**. JavaScript (JS) has increased in popularity in recent years and has been the leading programming language for six consecutive years and is the most used programming language on Github.
## Requirements
No prior knowledge of programming is required to follow this challenge. You need only:
1. Motivation
2. Computer
2. A Computer
3. Internet
4. Browser
5. Code Editor
4. A Browser
5. A Code Editor
## Setup
I believe you have the motivation and a strong desire to be a developer, computer and Internet. If you have those, then you have everything to get started.
I believe you have the motivation and a strong desire to be a developer, a computer and Internet. If you have those, then you have everything to get started.
### Install Node.js
@ -142,8 +137,7 @@ Ctl+Shift+J
![Opening console](images/opening_chrome_console_shortcut.png)
After you open the Google Chrome console, try to explore the marked buttons. We will spend most of the time on the Console part. The Console is the place where your JavaScript code goes. The Google Console V8 engine changes your JavaScript code to machine code.
Let us write a JavaScript code on the Google Chrome console:
After you open the Google Chrome console, try to explore the marked buttons. We will spend most of the time on the Console. The Console is the place where your JavaScript code goes. The Google Console V8 engine changes your JavaScript code to machine code. Let us write a JavaScript code on the Google Chrome console:
![write code on console](./images/js_code_on_chrome_console.png)
@ -169,7 +163,7 @@ console.log('Hello, World!')
##### Console.log with Multiple Arguments
The console.log(param1, param2, param3), can take multiple arguments.
The **console.log()** function can take multiple arguments in the form: **console.log(param1, param2, param3)**.
![console log multiple arguments](./images/console_log_multipl_arguments.png)
@ -181,11 +175,11 @@ console.log('Welcome', 'to', 30, 'Days', 'Of', 'JavaScript')
As you can see from the snippet code above, *console.log()* can take multiple arguments.
Congratulations! You wrote your first JavaScript code using *console.log()*.
Congratulations! You just wrote your first JavaScript code using *console.log()*.
##### Comment
##### Comments
We add comments to our code. Comments are very important to make code more readable and to leave remarks in our code. JavaScript does not execute the comment part of our code. Any text line starting with // in JavaScript is a comment or anything enclosed like this /* */ is a comment.
We add comments to our code. Comments are very important to make code more readable and to leave remarks in our code. JavaScript does not execute the comment part of our code. In JavaScript, any text line starting with **//** is a comment, and anything enclosed in between **/*** and ***/** is a comment.
**Example: Single Line Comment**
@ -203,18 +197,18 @@ We add comments to our code. Comments are very important to make code more reada
##### Syntax
Programming languages are similar to human languages. English language or any 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 and many other languages use words, phrases, sentences and more to convey meaningful messages. 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 return different types of errors. We will explore different kinds of JavaScript errors later. For now, let us look at syntax errors.
![Error](images/raising_syntax_error.png)
I made a deliberate mistake. As a result, the console raises a syntax error. Actually, the syntax is very informative. It informs what type of mistake we made. By reading the error feedback guideline, we can correct the syntax and fix the problem. The process of identifying and removing errors from a program is called debugging. Let us fix the errors:
I made deliberate mistakes. As a result, the console raises syntax errors. Actually, the syntax is very informative. It informs what type of mistake was made. By reading the error feedback guideline, we can correct the syntax and fix the problem. The process of identifying and removing errors from a program is called debugging. Let us fix the errors:
```js
console.log("Hello, World!")
console.log('Hello, World!')
```
So far, we saw how to display text using a *console.log()*. If we are printing text or string using *console.log()*, the text has to be under the single quote, double quote, or a backtick quote.
So far, we saw how to display text using the console.log() function. If we are printing text or string using console.log(), the text has to be inside the single quotes, double quotes, or backtick quotes.
**Example:**
```js
@ -225,8 +219,8 @@ console.log(`Hello, World!`)
#### Arithmetics
Now, let us practice more writing JavaScript codes using *console.log()* on google chrome console for number data types.
In addition to the text, we can also do mathematical calculations using JavaScript. Let us do the following simple calculations.
Now, let us practice more writing JavaScript codes using *console.log()* on google chrome console for number data types. In addition to the text, we can also do mathematical calculations using JavaScript. Let us do the following simple calculations.
P. S. The console can directly take arguments without the **_console.log()_** function. However, it is included in this introduction because most of this challenge would be taking place in a text editor where the usage of the function would be mandatory. You can play around directly with instructions on the console.
![Arithmetic](images/arithmetic.png)
@ -241,7 +235,7 @@ console.log(3 ** 2) // Exponentiation 3 ** 2 == 3 * 3
### Code Editor
We can write our codes on the browser console, but it won't do for bigger projects. In a real working environment, developers use different code editors to write their codes. In this 30 days JavaScript challenge, we will use Visual Studio Code.
We can write our codes on the browser console, but it won't do for actual projects. In a real working environment, developers use different code editors to write their codes. In this 30 days JavaScript challenge, we will be using Visual Studio Code.
#### Installing Visual Studio Code
@ -274,14 +268,13 @@ Open the Visual Studio Code by double-clicking its icon. When you open it, you w
JavaScript can be added to a web page in three different ways:
- **_Inline script_**
- **_Internal script_**
- **_External script_**
- **_Multiple External scripts_**
- **_External script(s)_**
The following sections show different ways of adding JavaScript code to your web page.
### Inline Script
Create a folder on your desktop and call it 30DaysOfJS or in any location and create an **_index.html_** file in the project folder. Then paste the following code and open it in a browser, for example [Chrome](https://www.google.com/chrome/).
Create a project folder on your desktop or any other location, name it 30DaysOfJS and create an **_index.html_** file in the project folder. Then paste the following code and open it in a browser, for example, [Chrome](https://www.google.com/chrome/).
```html
<!DOCTYPE html>
@ -295,7 +288,7 @@ Create a folder on your desktop and call it 30DaysOfJS or in any location and c
</html>
```
Now, you wrote your first inline script. We can create a pop up alert message using the built-in *alert()* function.
Now, you just wrote your first inline script. We can create a pop up alert message using the **_alert()_** function.
### Internal Script
@ -316,7 +309,7 @@ First, let us write on the head part of the page.
</html>
```
This is how we write an internal script most of the time. Writing the JavaScript code in the body section is the most preferred option. Open the browser console to see the output from the console.log()
This is how we write an internal script most of the time. Writing the JavaScript code in the body section is the most preferred option.
```html
<!DOCTYPE html>
@ -333,14 +326,13 @@ This is how we write an internal script most of the time. Writing the JavaScript
</html>
```
Open the browser console to see the output from the console.log()
Open the browser console to see the output of the console.log() argument.
![js code from vscode](./images/js_code_vscode.png)
### External Script
### External Script(s)
Similar to the internal script, the external script link can be on the header or body, but it is preferred to put it in the body.
First, we should create an external JavaScript file with .js extension. All files ending with .js extension are JavaScript files. Create a file introduction.js inside your project directory and write the following code and link this .js file at the bottom of the body.
Similar to the internal script, the external script link can be on the header or body, but it is better to put it in the body. First, we should create an external JavaScript file with .js extension. All files ending with .js extension are JavaScript files. Create a file named introduction.js inside your project directory and write the following code. Link this .js file at the bottom of the body.
```js
console.log('Welcome to 30DaysOfJavaScript')
@ -376,11 +368,10 @@ External scripts in the _body_:
</html>
```
Open the browser console to see the output from the console.log()
Open the browser console to see the output of the console.log() argument.
### Multiple External Scripts
We can link multiple external JavaScript files to a web page.
We can also link **multiple external JavaScript files** to a web page.
Create a helloworld.js file inside the 30DaysOfJS folder and write the following code.
```js
@ -401,26 +392,26 @@ console.log('Hello, World!')
</html>
```
*Your main.js file should be below all other scripts*. It is very important to remember this.
**_Your main JavaScript file should be below all other scripts_**. It is very important to remember this.
![Multiple Script](./images/multiple_script.png)
## Introduction to Data types
In JavaScript and also other programming languages, there are different kinds of data types. The following are JavaScript primitive data types:_String, Number, Boolean, undefined, Null_, and _Symbol_.
In JavaScript and also other programming languages, there are different kinds of data types. The following are JavaScript primitive data types: _String, Number, Boolean, undefined, Null_, and _Symbol_.
### Number
### Numbers
- Integer: Integer (negative, zero and positive) numbers
- Integers: Integer (negative, zero and positive) numbers
Example:
... -3, -2, -1, 0, 1, 2, 3 ...
- Float: Decimal number
- Floating-point numbers: Decimal number
Example
... -3.5, -2.25, -1.0, 0.0, 1.1, 2.2, 3.5 ...
### String
### Strings
A collection of one or more characters under a single quote, double quote, or backtick quote.
A collection of one or more characters between two single quotes, double quotes, or backtick quotes.
**Example:**
```js
@ -430,7 +421,7 @@ A collection of one or more characters under a single quote, double quote, or ba
"I love teaching"
'I hope you are enjoying the first day'
`We can also create a string using a backtick`
'A string could be just as small as one character as big as many pages'
'A string could be just as small as one character or as big as many pages'
```
### Booleans
@ -442,8 +433,10 @@ A boolean data type is either a true or false value.
**Example:**
```js
true // if the light on ,the value is true
false // if the light off, the value is false
2+2= 4;
true // the console would return the true value because the equation above is correct
2 ** 2= 8;
false // the console would return the true value because the equation above is incorrect
```
### Undefined
@ -452,7 +445,7 @@ In JavaScript, if we don't assign a value to a variable, the value is undefined.
```js
let firstName;
console.log(firstName); //not defined, because it is not assigned to a value yet
console.log(firstName); //returns undefined because it is not assigned a value yet
```
### Null
@ -475,9 +468,9 @@ console.log(typeof null) // object type
console.log(typeof undefined) // undefined
```
## Comments Again
## Comments, Again!
Reminding, that commenting in JavaScript is similar to other programming languages. Comments are important in making your make code more readable.
Remember that commenting in JavaScript is similar to other programming languages. Comments are important in making your make code more readable.
There are two ways of commenting:
- _Single line commenting_
@ -502,19 +495,18 @@ Multiline commenting:
## Variables
Variables are _containers_ of data. Variables used to _store_ data in a memory location. When a variable is declared, a memory location is reserved. When a variable is assigned to a value (data), the memory space will be filled with that data. To declare a variable, we use _var_, _let_, or _const_ keywords. We will talk more about var, let, and const in detail in other sections (scope). For now, the above explanation is enough.
Variables are _containers_ of data. Variables are used to _store_ data in a memory location. When a variable is declared, a memory location is reserved. When a value (data) is assigned to a variable, the memory space will be filled with that data. To declare a variable, we use _var_, _let_, or _const_ keywords.
For a variable that changes at a different time, we use _let_. If the data does not change at all, we use _const_. For example, PI, country name, gravity do not change, so we use *const*. We will not be using _var_ in this challenge and I don't recommend you to use it. It is an error-prone way of declaring variable and it has lots of leaks.
We will talk more about var, let, and const in detail in other sections (scope). For now, the above explanation is all you need to proceed.
For a variable that changes at a different time, we use _let_. If the data does not change at all, we use _const_. For example, PI, country name, gravity do no change, and we can use *const*. We will not use var in this challenge and I don't recommend you to use it. It is error prone way of declaring variable it has lots of leak.
A valid JavaScript
A valid JavaScript variable name must follow the follow rules.
- A JavaScript variable name should not begin with a number.
- A JavaScript variable name does not allow special characters except dollar sign and underscore.
- A JavaScript variable name follows a camelCase convention.
- A JavaScript variable name should not have space between words.
The following are valid examples of JavaScript variables.
Valid variables in JavaScript:
The following are examples of valid JavaScript variables.
```js
firstName
@ -538,8 +530,9 @@ Valid variables in JavaScript:
year_2020
```
camelCase or the first way of declaring is conventional in JavaScript. In this material, we will use camelCase variables.
Invalid variables:
The first and second variables on the list follows the camelCase convention of declaring in JavaScript. In this material, we will be using camelCase variables.
Examples of invalid variables:
```sh
first-name
@ -547,14 +540,14 @@ Invalid variables:
num_#_1
```
Let us declare variables with different data types. To declare a variable, we need to use let or const keyword before the variable name. Following the variable name, we write an equal sign (assignment operator), and a value.
Let us declare variables with different data types. To declare a variable, we need to use *let* or *const* keyword before the variable name. Following the variable name, we write an equal sign (assignment operator), and a value (assigned data).
```js
// Syntax
let nameOfVariable = value
```
**Examples: Variables**
**Examples of declared variables**
```js
// Declaring different variables of different data types
@ -598,23 +591,23 @@ console.log(name, job, live);
Asabeneh teacher Finland
```
When you run the files on 01-Day folder you should get this:
When you run the *index.html* file in the 01-Day folder, you should get this:
![Day one](./images/day_1.png)
🌕 You are amazing! You have just completed day 1 challenge and you are on your way to greatness. Now do some exercises for your brain and for your muscle.
🌕 You are amazing! You have just completed day 1 challenge and you are on your way to greatness. Now do some exercises for your brain and muscle.
# 💻 Day 1: Exercises
1. Write a single line comment which says, _comments can make code readable_
2. Write another single comment which says, *Welcome to 30DaysOfJavaScript*
3. Write a multiline comment which says, _comments can make code readable, easy to reuse_
3. Write a multiline comment which says, _comments can make code readable and easy to reuse_
_and informative_
4. Create a variable.js file and declare variables and assign string, boolean, undefined and null data types
5. Create datatypes.js file and use the JavaScript ***typeof*** operator to check different data types. Check the data type of each variable
6. Declare four variables without assigning values
7. Declare four variables with assigning values
7. Declare four variables with assigned values
8. Declare variables to store your first name, last name, marital status, country and age in multiple lines
9. Declare variables to store your first name, last name, marital status, country and age in a single line
10. Declare two variables _myAge_ and _yourAge_ and assign them initial values and log to the browser console.

Loading…
Cancel
Save