commit 24df9f13b8de8e0cdc86e56ab0b21655440cad21 Author: Asabeneh Date: Wed Jan 1 21:41:36 2020 +0200 day 1 diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..c206125d --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +draft.md +playground +/playground +.DS_Store \ No newline at end of file diff --git a/01-Day/helloworld.js b/01-Day/helloworld.js new file mode 100644 index 00000000..8c9e2c0a --- /dev/null +++ b/01-Day/helloworld.js @@ -0,0 +1 @@ +console.log('Hello, World!') \ No newline at end of file diff --git a/01-Day/index.html b/01-Day/index.html new file mode 100644 index 00000000..ac4827dc --- /dev/null +++ b/01-Day/index.html @@ -0,0 +1,17 @@ + + + + + 30DaysOfJavaScript + + + + + + + + + + + + \ No newline at end of file diff --git a/01-Day/introduction.js b/01-Day/introduction.js new file mode 100644 index 00000000..316199cd --- /dev/null +++ b/01-Day/introduction.js @@ -0,0 +1 @@ +console.log('Welcome to 30DaysOfJavaScript') \ No newline at end of file diff --git a/01-Day/main.js b/01-Day/main.js new file mode 100644 index 00000000..4704eb27 --- /dev/null +++ b/01-Day/main.js @@ -0,0 +1,3 @@ +console.log(firstName, lastName, country, city, age, isMarried) +console.log(gravity, boilingPoint, PI) // 9.81, 100, 3.14 +console.log(name, job, live) \ No newline at end of file diff --git a/01-Day/varaible.js b/01-Day/varaible.js new file mode 100644 index 00000000..f5872afd --- /dev/null +++ b/01-Day/varaible.js @@ -0,0 +1,17 @@ +// Declaring different variables of different data types +let firstName = 'Asabeneh' // first name of a person +let lastName = 'Yetayeh' // last name of a person +let country = 'Finland' // country +let city = 'Helsinki' // capital city +let age = 100 // age in years +let isMarried = true + +// Declaring variables with number values +const gravity = 9.81 // earth gravity in m/s2 +const boilingPoint = 100 // water boiling point, temperature in oC +const PI = 3.14 // geometrical constant + +// Variables can also be declaring in one line separated by comma +let name = 'Asabeneh', //name of a person + job = 'teacher', + live = 'Finland' diff --git a/images/30DaysOfJavaScript.png b/images/30DaysOfJavaScript.png new file mode 100644 index 00000000..41422866 Binary files /dev/null and b/images/30DaysOfJavaScript.png differ diff --git a/images/adding_project_to_vscode.png b/images/adding_project_to_vscode.png new file mode 100644 index 00000000..19358607 Binary files /dev/null and b/images/adding_project_to_vscode.png differ diff --git a/images/arithmetic.png b/images/arithmetic.png new file mode 100644 index 00000000..9830916b Binary files /dev/null and b/images/arithmetic.png differ diff --git a/images/console_log_multipl_arguments.png b/images/console_log_multipl_arguments.png new file mode 100644 index 00000000..f324a907 Binary files /dev/null and b/images/console_log_multipl_arguments.png differ diff --git a/images/day-1.png b/images/day-1.png new file mode 100644 index 00000000..98a4d29f Binary files /dev/null and b/images/day-1.png differ diff --git a/images/download_node.png b/images/download_node.png new file mode 100644 index 00000000..f290b201 Binary files /dev/null and b/images/download_node.png differ diff --git a/images/google-chrome.png b/images/google-chrome.png new file mode 100644 index 00000000..5d66d13d Binary files /dev/null and b/images/google-chrome.png differ diff --git a/images/install_node.png b/images/install_node.png new file mode 100644 index 00000000..e5aecf12 Binary files /dev/null and b/images/install_node.png differ diff --git a/images/js_code_on_chrome_console.png b/images/js_code_on_chrome_console.png new file mode 100644 index 00000000..24a67d8d Binary files /dev/null and b/images/js_code_on_chrome_console.png differ diff --git a/images/js_code_vscode.png b/images/js_code_vscode.png new file mode 100644 index 00000000..6e1a6614 Binary files /dev/null and b/images/js_code_vscode.png differ diff --git a/images/launched_on_new_tab.png b/images/launched_on_new_tab.png new file mode 100644 index 00000000..ed377dcf Binary files /dev/null and b/images/launched_on_new_tab.png differ diff --git a/images/multiple_script.png b/images/multiple_script.png new file mode 100644 index 00000000..caa067f3 Binary files /dev/null and b/images/multiple_script.png differ diff --git a/images/opening_chrome_console_shortcut.png b/images/opening_chrome_console_shortcut.png new file mode 100644 index 00000000..bae212f3 Binary files /dev/null and b/images/opening_chrome_console_shortcut.png differ diff --git a/images/opening_developer_tool.png b/images/opening_developer_tool.png new file mode 100644 index 00000000..4d32e7ab Binary files /dev/null and b/images/opening_developer_tool.png differ diff --git a/images/opening_project_on_vscode.png b/images/opening_project_on_vscode.png new file mode 100644 index 00000000..908c8fd7 Binary files /dev/null and b/images/opening_project_on_vscode.png differ diff --git a/images/raising_syntax_error.png b/images/raising_syntax_error.png new file mode 100644 index 00000000..81f6245e Binary files /dev/null and b/images/raising_syntax_error.png differ diff --git a/images/running_script.png b/images/running_script.png new file mode 100644 index 00000000..deac13de Binary files /dev/null and b/images/running_script.png differ diff --git a/images/scripts_on_vscode.png b/images/scripts_on_vscode.png new file mode 100644 index 00000000..f6257be5 Binary files /dev/null and b/images/scripts_on_vscode.png differ diff --git a/images/vscode.png b/images/vscode.png new file mode 100644 index 00000000..724fc109 Binary files /dev/null and b/images/vscode.png differ diff --git a/images/vscode_ui.png b/images/vscode_ui.png new file mode 100644 index 00000000..7210a088 Binary files /dev/null and b/images/vscode_ui.png differ diff --git a/readMe.md b/readMe.md new file mode 100644 index 00000000..1d5fcdb3 --- /dev/null +++ b/readMe.md @@ -0,0 +1,480 @@ +## Table of Contents +![Thirty Days Of JavaScript](./images/30DaysOfJavaScript.png) + +- [📔 Day 1](#%f0%9f%93%94-day-1) +- [Introduction](#introduction) +- [Requirements](#requirements) +- [Setup](#setup) + - [Install Node.js](#install-nodejs) + - [Browser](#browser) + - [Installing Google Chrome](#installing-google-chrome) + - [Opening Google Chrome Console](#opening-google-chrome-console) + - [Writing Code on browser Console](#writing-code-on-browser-console) + - [Console.log](#consolelog) + - [Console.log with multiple arguments](#consolelog-with-multiple-arguments) + - [Comment](#comment) + - [Syntax](#syntax) + - [Arithmetics](#arithmetics) + - [Code Editor](#code-editor) + - [Installing Visual Studio Code](#installing-visual-studio-code) + - [How to use visual studio code](#how-to-use-visual-studio-code) +- [Adding JavaScript to a web page](#adding-javascript-to-a-web-page) + - [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) + - [Booleans](#booleans) + - [Undefined](#undefined) + - [Null](#null) + - [Checking Data types](#checking-data-types) +- [Comments](#comments) +- [Variables](#variables) +- [💻 Day 1: Exercises](#%f0%9f%92%bb-day-1-exercises) + + + +# 📔 Day 1 +# Introduction +**Congratulations** for deciding to participate in a 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 concepts of programming. In the end of the challenge you will get a 30DaysOfPython programming challenge certificate. Join the [telegram group](https://t.me/ThirtyDaysOfJavaScript). + +**A 30DaysOfJavaScript** is a guide for both beginners and advanced JavaScript developers. Welcome to JavaScript. JavaScript is the language of the browser. + +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 four 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 +3. Internet +4. Browser +5. Code Editor + +# Setup +I believe you have the motivation, computer and internet. + +## Install Node.js +You may not need it right now but you may need it for later. Install [node.js](https://nodejs.org/en/). + +![Node download](images/download_node.png) + +After downloading double click and install + + ![Install node](images/install_node.png) + +We can check if node is installed in our machine by opening our device terminal or command prompt. + +```sh +asabeneh $ node -v +v12.14.0 +``` +I am using node version 12.14.0 which is the recommended version of node. + +## Browser +There are many browsers out there but I strongly recommend Google Chrome. +### Installing Google Chrome +Install [google chrome](https://www.google.com/chrome/) if you do not have one yet. We can write small JavaScript code on the browser console but we can not use the browser console to develop applications. +### Opening Google Chrome Console +You can open the google chrome either by clicking three dots at the top right corner of chrome or using short cut. I prefer short cuts. +![Opening chrome](images/opening_developer_tool.png) + + +To open chrome console using short cut. +```sh +Mac +Command+Option+I + +Windows: +Ctl+Shift+I +``` +![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 change your JavaScript code to machine code. +Let us write a JavaScript code on google chrome console: + +![write code on console](./images/js_code_on_chrome_console.png) + +### Writing Code on browser Console +We can write any JavaScript code on google console or any browser console but for this challenge we only focus on google chrome console. Open the console using: +```sh +Mac +Command+Option+I + +Windows: +Ctl+Shift+I +``` +#### Console.log +To write our first JavaScript code we used a builtin function **console.log()**. We passed an argument as an input data and the function display the output. We passed 'Hello, World' as input data or argument in the condole.log() function. +```js +console.log('Hello, World!') +``` +#### Console.log with multiple arguments +The console.log(param1, param2, param3), can take multiple arguments. +![console log multiple arguments](./images/console_log_multipl_arguments.png) + +```js +console.log('Hello', 'World', '!') +console.log('HAPPY', 'NEW', 'YEAR', 2020) +console.log('Welcome', 'to', 30, 'Days', 'Of', 'JavaScript') +``` +As you can see from the above snippet code, *console.log()* can take multiple arguments. + +Congratulations! You wrote your first JavaScript code using *console.log()*. +#### Comment +We add comment to our code. Comment is very important to make code more readable and to leave remark in our code. JavaScript does not execute comment part of our code. Any text starts with // in JavaScript is a comment or any thing enclose like this /* */ is a comment. + +Example: Single Line Comment + + // This is the first comment + // This is the second comment + // I am a single line comment +Example: Multiline Comment + + /* + This is a multiline comment + multiline comment take multiple lines. + JavaScript is the language the langauge of the web. + */ + +#### Syntax +JavaScript is a programming language and it has its own syntax like other languages. If we do not write a syntax which JavaScript understands it will raise different kind of errors. We will see different kind of JavaScript errors later but for now let us see syntax error. + +![Error](images/raising_syntax_error.png) + +I made a deliberate mistake the console raise a syntax error. Actually, the syntax is very informative. It tell what kind of mistake we made and we can fix the by reading error feedback. 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 so how to display text using a *console.log()*. If we are printing text or string using *console.log()*, the text has to be under single, double or back tick. +**Example:** +```js +console.log("Hello, World!") +console.log('Hello, World!') +console.log(`Hello, World!`) +``` +#### Arithmetics + +Now, let us practice more writing JavaScript code using *console.log()* on google chrome console for number data types. +In addition to text, we can also do mathematical calculations using JavaScript. Let us do the following simple calculations + +![Arithmetic](images/arithmetic.png) +```js +console.log(2 + 3) // Addition +console.log(3 - 2) // Subtraction +console.log(2 * 3) // Multiplication +console.log(3 / 2) // Division +console.log(3 % 2) // Modulus - finding remainder +console.log(3 ** 2) // Exponential + +``` + +## Code Editor +We can write code on the browser console but it won't be for a big project. In real work environment, developers use different code editors to write codes. In this 30 days python programming challenge we will use visual studio code. +### Installing Visual Studio Code +Visual studio code is a very popular open source text editor and I would recommend to [download](https://code.visualstudio.com/) visual studio code, but if you are in favor of other editors, feel free to follow with what you have. + +![Vscode](images/vscode.png) + +If you installed visual studio code, let us start using it. +### How to use visual studio code +Open the visual studio code by double clicking the visual studio icon. When you open it you will get this kind of interface. Try to interact with the labelled icons. + +![Vscode ui](./images/vscode_ui.png) +![Vscode add project](./images/adding_project_to_vscode.png) +![Vscode open project](./images/opening_project_on_vscode.png) +![script file](images/scripts_on_vscode.png) +![running script](./images/running_script.png) +![coding running](./images/launched_on_new_tab.png) + +# Adding JavaScript to a web page +JavaScript can be added to a web page in three ways: +- **_Inline script_** +- **_Internal script_** +- **_External script_** +- **_Multiple External scripts_** + +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 project folder. Then paste the following code and open it in a browser, either in [Chrome](https://www.google.com/chrome/). + +```html + + + + 30DaysOfScript:Inline Script + + + + + +``` +Now, you wrote your first inline script. We can create a pop up alert message using the build in *alert()* function. + +## Internal script +Internal script can be written in the _head_ or the _body_ but it is preferred to put it on the body of the html document. +First let us write on the head part of the page. + +```html + + + + 30DaysOfScript:Internal Script + + + + + + +``` +This is how we write inline script most of the time. Writing the JavaScript code in the body section is the most preferred place. Open the browser console to see the out put from the console.log() + +```html + + + + 30DaysOfScript:Internal Script + + + + + + +``` +Open the browser console to see the out put from the console.log() +![js code from vscode](./imas/js_code_ve) + +## External script +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. Any JavaScript file ends with .js. Create a file introduction.js inside your project directory and write the following code and link this fat the body +```js +console.log('Welcome to 30DaysOfJavaScript') +``` + +External script in the head + +```html + + + + 30DaysOfJavaScript:External script + + + + + + + + 30DaysOfJavaScript:External script + + + //it could be in the header or in the body + // Here is the recommended place to put the external script + + + + + + Multiple External Scripts + + + + + +