{"_id":"javascript-for-everyone","_rev":"2-330bfde7670f60b71506a850c1ef0c68","name":"javascript-for-everyone","dist-tags":{"latest":"2.8.5"},"versions":{"2.3.4":{"name":"javascript-for-everyone","description":"javascript-for-everyone","version":"2.3.4","main":"./dist/index.js","module":"./dist/index.mjs","types":"./dist/index.d.ts","homepage":"https://github.com/Asabeneh","dependencies":{"jen-allien-apps":"^2.3.4","mic-analytica":"^3.3.4","aly-architecture-cobbler":"^2.9.4","pau-atmotech-development":"^1.3.8"},"repository":{"type":"git","url":"git+https://github.com/Asabeneh/javascript-for-everyone.git"},"scripts":{"build":"tsup"},"keywords":["javascript"],"author":{"name":"Asabeneh"},"license":"MIT","devDependencies":{"tsup":"^8.0.2","typescript":"^5.3.3"},"bugs":{"url":"https://github.com/Asabeneh/javascript-for-everyone/issues"},"_id":"javascript-for-everyone@2.3.4","_nodeVersion":"18.17.1","_npmVersion":"9.6.7","dist":{"integrity":"sha512-xe+oKWG0pLZ0l6vGb1Oziw35XYbxdLUnhq4y2MkN1QR2x00Jgtes6fKQ5hygkSnu2ADb/pu4ThBI380MydRA5A==","shasum":"84d8eaa5497bfa8adeb71940930c20d637ff0e0f","tarball":"https://registry.npmjs.org/javascript-for-everyone/-/javascript-for-everyone-2.3.4.tgz","fileCount":36,"unpackedSize":55121,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCID6ay+uMj9wPMYFyiPFq1Ie8zUksZs7CcVOLAPQ2IaadAiAm2kBypus5KnUp/FTAfi4DwhM5QP4joEu9YBenAx09BA=="}]},"_npmUser":{"name":"diasrita551","email":"DiasRita551@gmail.com"},"directories":{},"maintainers":[{"name":"diasrita551","email":"DiasRita551@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/javascript-for-everyone_2.3.4_1714042061298_0.5290279009214489"},"_hasShrinkwrap":false},"2.4.5":{"name":"javascript-for-everyone","description":"javascript-for-everyone","version":"2.4.5","main":"./dist/index.js","module":"./dist/index.mjs","types":"./dist/index.d.ts","homepage":"https://github.com/Asabeneh","dependencies":{"jen-allien-apps":"^2.3.4","mic-analytica":"^3.3.4","aly-architecture-cobbler":"^2.9.4","pau-atmotech-development":"^1.3.8"},"repository":{"type":"git","url":"git+https://github.com/Asabeneh/javascript-for-everyone.git"},"scripts":{"build":"tsup"},"keywords":["javascript"],"author":{"name":"Asabeneh"},"license":"MIT","devDependencies":{"tsup":"^8.0.2","typescript":"^5.3.3"},"bugs":{"url":"https://github.com/Asabeneh/javascript-for-everyone/issues"},"_id":"javascript-for-everyone@2.4.5","_nodeVersion":"18.17.1","_npmVersion":"9.6.7","dist":{"integrity":"sha512-7wN0QG3Oz39bCmyW6Ov2zC8shcQ/BJ48ZMdzhufx/OXLDiDeQf5J4lAhWlKFje2doMKWb8zkQxtcFt8YSW67/g==","shasum":"fb2df75834713654c508bb0d9036d7bdc68e7445","tarball":"https://registry.npmjs.org/javascript-for-everyone/-/javascript-for-everyone-2.4.5.tgz","fileCount":36,"unpackedSize":233428,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIGheyRgyWsfXcFJ5vpLt6k+duttaR6ubo1vtp5m5pgBFAiEAjB39I5F2rhSS6t4lGnPOfCQg4CGfJzP581hWfotk5SI="}]},"_npmUser":{"name":"diasrita551","email":"DiasRita551@gmail.com"},"directories":{},"maintainers":[{"name":"diasrita551","email":"DiasRita551@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/javascript-for-everyone_2.4.5_1714042090249_0.04895116167542746"},"_hasShrinkwrap":false},"2.8.5":{"name":"javascript-for-everyone","description":"javascript-for-everyone","version":"2.8.5","main":"./dist/index.js","module":"./dist/index.mjs","types":"./dist/index.d.ts","homepage":"https://github.com/Asabeneh","dependencies":{"jen-allien-apps":"^2.3.4","mic-analytica":"^3.3.4","aly-architecture-cobbler":"^2.9.4","pau-atmotech-development":"^1.3.8"},"repository":{"type":"git","url":"git+https://github.com/Asabeneh/javascript-for-everyone.git"},"scripts":{"build":"tsup"},"keywords":["javascript"],"author":{"name":"Asabeneh"},"license":"MIT","devDependencies":{"tsup":"^8.0.2","typescript":"^5.3.3"},"bugs":{"url":"https://github.com/Asabeneh/javascript-for-everyone/issues"},"_id":"javascript-for-everyone@2.8.5","_nodeVersion":"18.17.1","_npmVersion":"9.6.7","dist":{"integrity":"sha512-K6NmUVpWbz/jiYfuwHdbSasMBQbdJHEkFTb7887YkQ/vMxV4vg2W1yDcHL0X+l7sXp71G8dT+AscpS+FZVoOJw==","shasum":"620a9a033fe43e69a9150543641c8351e653dd51","tarball":"https://registry.npmjs.org/javascript-for-everyone/-/javascript-for-everyone-2.8.5.tgz","fileCount":36,"unpackedSize":233428,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIA7jREldTZDtACdY3Ed6pqHI1sTnk+k0mFxfqSfMVvVGAiEA7NXQzGuPFyU3WeR2185BGnyN+R7wYKqswni3ByGh6M8="}]},"_npmUser":{"name":"diasrita551","email":"DiasRita551@gmail.com"},"directories":{},"maintainers":[{"name":"diasrita551","email":"DiasRita551@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/javascript-for-everyone_2.8.5_1714042114182_0.3402966629207156"},"_hasShrinkwrap":false}},"time":{"created":"2024-04-25T10:47:41.296Z","2.3.4":"2024-04-25T10:47:41.459Z","modified":"2024-04-25T10:48:34.506Z","2.4.5":"2024-04-25T10:48:10.432Z","2.8.5":"2024-04-25T10:48:34.352Z"},"maintainers":[{"name":"diasrita551","email":"DiasRita551@gmail.com"}],"description":"javascript-for-everyone","homepage":"https://github.com/Asabeneh","keywords":["javascript"],"repository":{"type":"git","url":"git+https://github.com/Asabeneh/javascript-for-everyone.git"},"author":{"name":"Asabeneh"},"bugs":{"url":"https://github.com/Asabeneh/javascript-for-everyone/issues"},"license":"MIT","readme":"<div align=\"center\">\r\n  <h1> JavaScript for Everyone</h1>\r\n  <a class=\"header-badge\" target=\"_blank\" href=\"https://www.linkedin.com/in/asabeneh/\">\r\n  <img src=\"https://img.shields.io/badge/style--5eba00.svg?label=LinkedIn&logo=linkedin&style=social\">\r\n  </a>\r\n  <a class=\"header-badge\" target=\"_blank\" href=\"https://twitter.com/Asabeneh\">\r\n  <img alt=\"Twitter Follow\" src=\"https://img.shields.io/twitter/follow/asabeneh?style=social\">\r\n  </a>\r\n\r\n<sub>Author:\r\n<a href=\"https://www.linkedin.com/in/asabeneh/\" target=\"_blank\">Asabeneh Yetayeh</a><br>\r\n<small> January, 2018</small>\r\n</sub>\r\n\r\n</div>\r\n\r\n<div>\r\n\r\n<small>Support the **author** to create more educational materials</small>  \r\n<a href = \"https://www.paypal.me/asabeneh\"><img src='./images/paypal_lg.png' alt='Paypal Logo' style=\"width:10%\"/></a>\r\n\r\n</div>\r\n\r\n![JS](./images/javascript_for_everyone.png)\r\n\r\n- [Introduction](#introduction)\r\n- [Setup](#setup)\r\n- [Requirements](#requirements)\r\n- [Setup](#setup-1)\r\n  - [Install Node.js](#install-nodejs)\r\n  - [Browser](#browser)\r\n    - [Installing Google Chrome](#installing-google-chrome)\r\n    - [Opening Google Chrome Console](#opening-google-chrome-console)\r\n    - [Writing Code on browser Console](#writing-code-on-browser-console)\r\n      - [Console.log](#consolelog)\r\n      - [Console.log with multiple arguments](#consolelog-with-multiple-arguments)\r\n      - [Comment](#comment)\r\n      - [Syntax](#syntax)\r\n    - [Arithmetics](#arithmetics)\r\n  - [Code Editor](#code-editor)\r\n    - [Installing Visual Studio Code](#installing-visual-studio-code)\r\n    - [How to use visual studio code](#how-to-use-visual-studio-code)\r\n  - [Adding JavaScript to a web page](#adding-javascript-to-a-web-page)\r\n    - [Inline Script](#inline-script)\r\n    - [Internal script](#internal-script)\r\n    - [External script](#external-script)\r\n  - [Exercises:Setting Up your machine](#exercisessetting-up-your-machine)\r\n- [Variables](#variables)\r\n  - [Exercise - 1 : Variables](#exercise---1--variables)\r\n- [Comments](#comments)\r\n  - [Exercise: Comments](#exercise-comments)\r\n- [Data types](#data-types)\r\n  - [Primitive Data Types](#primitive-data-types)\r\n  - [Non-Primitive Data Types](#non-primitive-data-types)\r\n- [Numbers](#numbers)\r\n  - [Declaring number data types](#declaring-number-data-types)\r\n  - [Math Object](#math-object)\r\n    - [Random number generator](#random-number-generator)\r\n- [Strings](#strings)\r\n  - [String Concatenation](#string-concatenation)\r\n    - [Concatenating using addition operator](#concatenating-using-addition-operator)\r\n    - [Long Literal Strings](#long-literal-strings)\r\n    - [Escape Sequences in string](#escape-sequences-in-string)\r\n    - [Template Literals(Template Strings)](#template-literalstemplate-strings)\r\n  - [String Methods](#string-methods)\r\n- [Checking Data types and Casting](#checking-data-types-and-casting)\r\n  - [Checking data types](#checking-data-types)\r\n  - [Changing data type(Casting)](#changing-data-typecasting)\r\n    - [String to Int](#string-to-int)\r\n    - [String to Float](#string-to-float)\r\n    - [Float to Int](#float-to-int)\r\n  - [Exercises: Data Types](#exercises-data-types)\r\n    - [Exercise: String](#exercise-string)\r\n  - [Booleans](#booleans)\r\n    - [Exercise: Booleans](#exercise-booleans)\r\n  - [Undefined](#undefined)\r\n  - [Null](#null)\r\n  - [Exercise - 6 : Data types](#exercise---6--data-types)\r\n- [Operators](#operators)\r\n  - [Arithmetic Operators](#arithmetic-operators)\r\n  - [Exercises : Arithmetic Operators](#exercises--arithmetic-operators)\r\n  - [Logical Operators](#logical-operators)\r\n  - [Exercises: Logical Operators](#exercises-logical-operators)\r\n  - [Comparison Operators](#comparison-operators)\r\n  - [Exercise: Comparison Operators](#exercise-comparison-operators)\r\n- [Conditionals](#conditionals)\r\n  - [if](#if)\r\n  - [if else](#if-else)\r\n  - [if else if else](#if-else-if-else)\r\n  - [switch](#switch)\r\n  - [Ternary Operators](#ternary-operators)\r\n  - [Exercise: Conditionals](#exercise-conditionals)\r\n  - [While loop](#while-loop)\r\n  - [Do while loop](#do-while-loop)\r\n  - [Exercises:Loops](#exercisesloops)\r\n- [Arrays](#arrays)\r\n  - [Exercise : Arrays](#exercise--arrays)\r\n- [More on Arrays](#more-on-arrays)\r\n  - [Exercise -10 : Array Methods](#exercise--10--array-methods)\r\n- [Functions](#functions)\r\n  - [Function Declaration](#function-declaration)\r\n  - [Function Expression](#function-expression)\r\n  - [Anonymous Function](#anonymous-function)\r\n  - [Arrow Function](#arrow-function)\r\n  - [Arrow Function vs Declaration Function](#arrow-function-vs-declaration-function)\r\n  - [Exercise - 10 : Functions](#exercise---10--functions)\r\n- [Object](#object)\r\n  - [Object Methods](#object-methods)\r\n  - [Date Object](#date-object)\r\n    - [Exercises: Date Object](#exercises-date-object)\r\n  - [Exercises:Objects](#exercisesobjects)\r\n- [JSON](#json)\r\n  - [Converting JSON to JavaScript Object](#converting-json-to-javascript-object)\r\n    - [JSON.parse()](#jsonparse)\r\n  - [Using a reviver function with JSON.parse()](#using-a-reviver-function-with-jsonparse)\r\n  - [Converting Object to JSON](#converting-object-to-json)\r\n  - [Using a Filter Array with JSON.stringify](#using-a-filter-array-with-jsonstringify)\r\n  - [Exercises](#exercises)\r\n  - [Exercises Level 1](#exercises-level-1)\r\n  - [Exercises Level 2](#exercises-level-2)\r\n- [Higher Order Function](#higher-order-function)\r\n  - [Callback](#callback)\r\n  - [Returning function](#returning-function)\r\n  - [setting time](#setting-time)\r\n    - [setInterval](#setinterval)\r\n    - [setTimeout](#settimeout)\r\n  - [Exercises Level 3](#exercises-level-3)\r\n- [Functional Programming](#functional-programming)\r\n  - [Exercises](#exercises-1)\r\n- [Destructuring and Spread](#destructuring-and-spread)\r\n  - [Destructing Arrays](#destructing--arrays)\r\n    - [Destructuring Object](#destructuring-object)\r\n    - [Renaming during structuring](#renaming-during-structuring)\r\n  - [Spread or Rest Operator](#spread-or-rest-operator)\r\n    - [Exercise: Destructuring](#exercise-destructuring)\r\n- [Map and Set](#map-and-set)\r\n- [Set](#set)\r\n  - [Creating a set](#creating-a-set)\r\n  - [Adding an element to a set](#adding-an-element-to-a-set)\r\n  - [Deleting an element a set](#deleting-an-element-a-set)\r\n  - [Checking an element in the set](#checking-an-element-in-the-set)\r\n  - [Clearing the set](#clearing-the-set)\r\n- [Set](#set-1)\r\n  - [Creating an empty set](#creating-an-empty-set)\r\n  - [Creating set from array](#creating-set-from-array)\r\n  - [Adding an element to a set](#adding-an-element-to-a-set-1)\r\n  - [Deleting an element a set](#deleting-an-element-a-set-1)\r\n  - [Checking an element in the set](#checking-an-element-in-the-set-1)\r\n  - [Clearing the set](#clearing-the-set-1)\r\n  - [Union of sets](#union-of-sets)\r\n  - [Intersection of sets](#intersection-of-sets)\r\n  - [Difference of sets](#difference-of-sets)\r\n- [Map](#map)\r\n  - [Creating an empty Map](#creating-an-empty-map)\r\n  - [Creating an Map from array](#creating-an-map-from-array)\r\n  - [Adding values to the Map](#adding-values-to-the-map)\r\n  - [Getting a value from Map](#getting-a-value-from-map)\r\n  - [Checking key in Map](#checking-key-in-map)\r\n  - [Exercises: Set and Map](#exercises-set-and-map)\r\n  - [Exercises:Level 1](#exerciseslevel-1)\r\n  - [Exercises:Level 2](#exerciseslevel-2)\r\n  - [Exercises:Level 3](#exerciseslevel-3)\r\n- [Document Object Model (DOM)](#document-object-model-dom)\r\n  - [Getting Element](#getting-element)\r\n    - [Getting elements by tag name](#getting-elements-by-tag-name)\r\n    - [Getting elements by class name](#getting-elements-by-class-name)\r\n    - [Getting an element by id](#getting-an-element-by-id)\r\n    - [Getting elements by using querySelector using tag, class and id:](#getting-elements-by-using-queryselector-using-tag-class-and-id)\r\n  - [Adding attribute](#adding-attribute)\r\n    - [Adding attribute using setAttribute](#adding-attribute-using-setattribute)\r\n    - [Adding attribute without setAttribute](#adding-attribute-without-setattribute)\r\n    - [Adding class using classList](#adding-class-using-classlist)\r\n  - [Adding Text content](#adding-text-content)\r\n  - [Adding style](#adding-style)\r\n  - [Creating an Element](#creating-an-element)\r\n  - [Creating elements](#creating-elements)\r\n  - [Appending to a parent element](#appending-to-a-parent-element)\r\n  - [Event Listeners](#event-listeners)\r\n  - [Getting value from an input element](#getting-value-from-an-input-element)\r\n    - [Exercises:Document Object Model](#exercisesdocument-object-model)\r\n    - [DOM: Mini Projects](#dom-mini-projects)\r\n- [Classes](#classes)\r\n  - [Defining a classes](#defining-a-classes)\r\n  - [Class Instantiation](#class-instantiation)\r\n  - [Class Constructor](#class-constructor)\r\n  - [Default values with constructor](#default-values-with-constructor)\r\n  - [Class methods](#class-methods)\r\n  - [Properties with initial value](#properties-with-initial-value)\r\n  - [getter](#getter)\r\n  - [setter](#setter)\r\n  - [Static method](#static-method)\r\n- [Inheritance](#inheritance)\r\n  - [Overriding methods](#overriding-methods)\r\n- [Exercises](#exercises-2)\r\n  - [Exercises Level 1](#exercises-level-1-1)\r\n  - [Exercises Level 2](#exercises-level-2-1)\r\n  - [Exercises Level 3](#exercises-level-3-1)\r\n- [Regular Expressions](#regular-expressions)\r\n  - [RegEx parameters](#regex-parameters)\r\n    - [Pattern](#pattern)\r\n    - [Flags](#flags)\r\n  - [Creating a pattern with RegEx Constructor](#creating-a-pattern-with-regex-constructor)\r\n  - [Creating a pattern without RegEx Constructor](#creating-a-pattern-without-regex-constructor)\r\n  - [RegExp Object Methods](#regexp-object-methods)\r\n    - [Testing for a match](#testing-for--a-match)\r\n    - [Array containing all of the match](#array-containing-all-of-the-match)\r\n    - [Replacing a substring](#replacing-a-substring)\r\n  - [Square Bracket](#square-bracket)\r\n  - [Escape character(\\\\) in RegEx](#escape-character-in-regex)\r\n  - [One or more times(+)](#one-or-more-times)\r\n  - [Period(.)](#period)\r\n  - [Zero or more times(\\*)](#zero-or-more-times)\r\n  - [Zero or one times(?)](#zero-or-one-times)\r\n  - [Quantifier in RegEx](#quantifier-in-regex)\r\n  - [Cart ^](#cart-)\r\n  - [Exact match](#exact-match)\r\n- [💻 Exercises](#-exercises)\r\n  - [Exercises: Level 1](#exercises-level-1-2)\r\n  - [Exercises: Level 2](#exercises-level-2-2)\r\n  - [Exercises: Level 3](#exercises-level-3-2)\r\n- [Async and Await](#async-and-await)\r\n- [localStorage](#localstorage)\r\n  - [Setting item to the localStorage](#setting-item-to-the-localstorage)\r\n  - [Getting item from localStorage](#getting-item-from-localstorage)\r\n  - [Clearing the localStorage](#clearing-the-localstorage)\r\n  - [Exercises:Local Storage](#exerciseslocal-storage)\r\n- [Cookies](#cookies)\r\n  - [Exercises:Cookies](#exercisescookies)\r\n- [JavaScript Interview Questions](#javascript-interview-questions)\r\n  - [JavaScript Tests](#javascript-tests)\r\n  - [JavaScript Test 1](#javascript-test-1)\r\n  - [JavaScript Test 2](#javascript-test-2)\r\n  - [JavaScript Test 3](#javascript-test-3)\r\n\r\n## Introduction\r\n\r\n**_JavaScript for Everyone_** is a guide for both beginners and advanced JavaScript developers. Welcome to JavaScript. **_Congratulations_** for deciding to learn JavaScript, the language of the browser.\r\n\r\nIn this step by step tutorial, you will learn JavaScript, the most popular programming language in the history of mankind.\r\nYou 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_**.\r\n**_JavaScript (JS)_** has increased in popularity in recent years and has been the leading\r\nprogramming language for four consecutive years and is the most used programming language on\r\nGithub.\r\n\r\n## Setup\r\n\r\nFirst thing first, lets install text or code editor. Install code editor, it could be [vscode](https://code.visualstudio.com/), [atom](https://atom.io/), [bracket](http://brackets.io/), [notepad++](https://notepad-plus-plus.org/) or others. I recommend vscode.\r\nInstall either [Chrome](https://www.google.com/chrome/) or [Firefox](https://www.mozilla.org/en-US/firefox/new/?v=b) if you didn't have yet.\r\n\r\nIf you want help, you may join the [telegram](https://t.me/JavaScriptforEveryone) channel.\r\n\r\n## Requirements\r\n\r\nNo prior knowledge of programming is required to follow this guide. You need only:\r\n\r\n1. Motivation\r\n2. Computer\r\n3. Internet\r\n4. Browser\r\n5. Code Editor\r\n\r\n## Setup\r\n\r\nI believe you have the motivation and a strong desire to be a developer, computer and Internet. If you have those, then you have everything.\r\n\r\n### Install Node.js\r\n\r\nYou may not need it right now but you may need it for later. Install [node.js](https://nodejs.org/en/).\r\n\r\n![Node download](images/download_node.png)\r\n\r\nAfter downloading double click and install\r\n\r\n![Install node](images/install_node.png)\r\n\r\nWe can check if node is installed in our local machine by opening our device terminal or command prompt.\r\n\r\n```sh\r\nasabeneh $ node -v\r\nv12.14.0\r\n```\r\n\r\nI am using node version 12.14.0, which is the recommended version of node.\r\n\r\n### Browser\r\n\r\nThere are many browsers out there. However, I strongly recommend Google Chrome.\r\n\r\n#### Installing Google Chrome\r\n\r\nInstall [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 do not use the browser console to develop applications.\r\n\r\n![Google Chrome](images/google_chrome.png)\r\n\r\n#### Opening Google Chrome Console\r\n\r\nYou can open Google Chrome either by clicking three dots at the top right corner of the Chrome browser or using a shortcut. I prefer using shortcuts.\r\n\r\n![Opening chrome](images/opening_developer_tool.png)\r\n\r\nTo open the Chrome console using a short cut.\r\n\r\n```sh\r\nMac\r\nCommand+Option+I\r\n\r\nWindows:\r\nCtl+Shift+I\r\n```\r\n\r\n![Opening console](images/opening_chrome_console_shortcut.png)\r\n\r\nAfter 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.\r\nLet us write a JavaScript code on the Google Chrome console:\r\n\r\n![write code on console](./images/js_code_on_chrome_console.png)\r\n\r\n#### Writing Code on browser Console\r\n\r\nWe can write any JavaScript code on the Google console or any browser console. However, for this challenge, we only focus on Google Chrome console. Open the console using:\r\n\r\n```sh\r\nMac\r\nCommand+Option+I\r\n\r\nWindows:\r\nCtl+Shift+I\r\n```\r\n\r\n##### Console.log\r\n\r\nTo write our first JavaScript code, we used a builtin function **console.log()**. We passed an argument as input data, and the function displays the output. We passed 'Hello, World' as input data or argument in the console.log() function.\r\n\r\n```js\r\nconsole.log(\"Hello, World!\");\r\n```\r\n\r\n##### Console.log with multiple arguments\r\n\r\nThe console.log(param1, param2, param3), can take multiple arguments.\r\n\r\n![console log multiple arguments](./images/console_log_multipl_arguments.png)\r\n\r\n```js\r\nconsole.log(\"Hello\", \"World\", \"!\");\r\nconsole.log(\"HAPPY\", \"NEW\", \"YEAR\", 2020);\r\nconsole.log(\"Welcome\", \"to\", 30, \"Days\", \"Of\", \"JavaScript\");\r\n```\r\n\r\nAs you can see from the above snippet code, _console.log()_ can take multiple arguments.\r\n\r\nCongratulations! You wrote your first JavaScript code using _console.log()_.\r\n\r\n##### Comment\r\n\r\nWe 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 starts with // in JavaScript is a comment or anything enclose like this /\\* \\*/ is a comment.\r\n\r\n**Example: Single Line Comment**\r\n\r\n// This is the first comment  \r\n // This is the second comment  \r\n // I am a single line comment\r\n\r\n**Example: Multiline Comment**\r\n\r\n/_\r\nThis is a multiline comment  \r\n Multiline comments can take multiple lines  \r\n JavaScript is the language of the web  \r\n _/\r\n\r\n##### Syntax\r\n\r\nJavaScript is a programming language. As a result, it has its syntax like other programming languages. 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.\r\n\r\n![Error](images/raising_syntax_error.png)\r\n\r\nI 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:\r\n\r\n```js\r\nconsole.log(\"Hello, World!\");\r\nconsole.log(\"Hello, World!\");\r\n```\r\n\r\nSo 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, double, or backtick.\r\n**Example:**\r\n\r\n```js\r\nconsole.log(\"Hello, World!\");\r\nconsole.log(\"Hello, World!\");\r\nconsole.log(`Hello, World!`);\r\n```\r\n\r\n#### Arithmetics\r\n\r\nNow, let us practice more writing JavaScript codes using _console.log()_ on google chrome console for number data types.\r\nIn addition to the text, we can also do mathematical calculations using JavaScript. Let us do the following simple calculations.\r\n\r\n![Arithmetic](images/arithmetic.png)\r\n\r\n```js\r\nconsole.log(2 + 3); // Addition\r\nconsole.log(3 - 2); // Subtraction\r\nconsole.log(2 * 3); // Multiplication\r\nconsole.log(3 / 2); // Division\r\nconsole.log(3 % 2); // Modulus - finding remainder\r\nconsole.log(3 ** 2); // Exponential\r\n```\r\n\r\n### Code Editor\r\n\r\nWe can write our codes on the browser console, but it won't be for bigger projects. In a real working environment, developers use different code editors to write their codes. In this 30 days python JavaScript challenge, we will use visual studio code.\r\n\r\n#### Installing Visual Studio Code\r\n\r\nVisual studio code is a very popular open-source text editor. 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.\r\n\r\n![Vscode](images/vscode.png)\r\n\r\nIf you installed visual studio code, let us start using it.\r\n\r\n#### How to use visual studio code\r\n\r\nOpen 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 labeled icons.\r\n\r\n![Vscode ui](./images/vscode_ui.png)\r\n\r\n![Vscode add project](./images/adding_project_to_vscode.png)\r\n\r\n![Vscode open project](./images/opening_project_on_vscode.png)\r\n\r\n![script file](images/scripts_on_vscode.png)\r\n\r\n![running script](./images/running_script.png)\r\n\r\n![coding running](./images/launched_on_new_tab.png)\r\n\r\n### Adding JavaScript to a web page\r\n\r\nJavaScript can be added to a web page in three ways:\r\n\r\n- **_Inline script_**\r\n- **_Internal script_**\r\n- **_External script_**\r\n\r\nThe following sections show different ways of adding JavaScript code to your web page.\r\n\r\n#### Inline Script\r\n\r\nCreate a folder on your desktop or in any location and create an **_index.html_** file in your folder. Then paste the following code and open it in a browser, either in [Chrome](https://www.google.com/chrome/) or [Firefox](https://www.mozilla.org/en-US/firefox/new/?v=b).\r\n\r\n```html\r\n<!DOCTYPE html>\r\n<html>\r\n  <head>\r\n    <title>JavaScript for Everyone</title>\r\n  </head>\r\n  <body>\r\n    <button onclick=\"alert('Welcome to JavaScript!');\">Click Me</button>\r\n  </body>\r\n</html>\r\n```\r\n\r\n#### Internal script\r\n\r\nInternal script can be written in the _head_ or the _body_ but it is preferred to put it on the body of the html document.\r\n\r\n- Internal script at the head\r\n\r\n```html\r\n<!DOCTYPE html>\r\n<html>\r\n  <head>\r\n    <title>JavaScript for Everyone</title>\r\n    <script>\r\n      console.log(\"Welcome to JavaScript for Everyone\");\r\n    </script>\r\n  </head>\r\n  <body></body>\r\n</html>\r\n```\r\n\r\n- Internal script at the body\r\n\r\n```html\r\n<!DOCTYPE html>\r\n<html>\r\n  <head>\r\n    <title>JavaScript for Everyone</title>\r\n  </head>\r\n  <body>\r\n    <script>\r\n      console.log(\"Welcome to JavaScript for Everyone\");\r\n    </script>\r\n  </body>\r\n</html>\r\n```\r\n\r\n#### External script\r\n\r\nThe external script link can be on the head or body but it is preferred to put it in the body.\r\n\r\n- External script at the head\r\n\r\n```html\r\n<!DOCTYPE html>\r\n  <html>\r\n    <head>\r\n      <title>JavaScript for Everyone</title>\r\n      <script src=\"introduction.js\"></script>\r\n    </head>\r\n    <body>\r\n    </body>\r\n    </html\r\n```\r\n\r\n- External script at the body\r\n\r\n```html\r\n<!DOCTYPE html>\r\n  <html>\r\n    <head>\r\n      <title>JavaScript for Everyone</title>\r\n    </head>\r\n    <body>\r\n      //it could be in the header or in the body\r\n      // Here is the recommended place to put the script\r\n      <script src=\"introduction.js\"></script>\r\n    </body>\r\n    </html\r\n```\r\n\r\n### Exercises:Setting Up your machine\r\n\r\n## Variables\r\n\r\nVariables are _containers_ of data. Variables _store_ data in a memory location. When a variable is declared a memory location is reserved and when it is assigned to a value, the memory space will be filled. To declare a variable we use, _var_, _let_ or _const_ key words. For a variable which changes at different time we use _let_ but if the data doesn't change at all we use _const_. For example PI, country name, gravity.\r\n\r\n- A JavaScript variable name shouldn't begin with a number\r\n- A JavaScript variable name does not allow special characters except dollar sign and underscore.\r\n- A JavaScript variable name follow a camelCase convention.\r\n- A JavaScript variable name shouldn't have space between words. The following are valid examples of JavaScript variables.\r\n\r\nValid variables in JavaScript:\r\n\r\n```js\r\nfirstName;\r\nlastName;\r\ncountry;\r\ncity;\r\ncapitalCity;\r\nage;\r\nisMarried;\r\n\r\nfirst_name;\r\nlast_name;\r\nis_married;\r\ncapital_city;\r\n\r\nnum1;\r\nnum_1;\r\n_num_1;\r\n$num1;\r\nyear2019;\r\nyear_2019;\r\n```\r\n\r\nCamel case(camelCase) or the first way of declaring is conventional in JavaScript. In this material, camelCase variables will be used.\r\n\r\nInvalid variable:\r\n\r\n```sh\r\n  first-name\r\n  1_num\r\n  num_#_1\r\n```\r\n\r\nDeclaring variables\r\n\r\n```js\r\n// Declaring different variables of different data types\r\n\r\nlet firstName = \"Asabeneh\"; // first name of a person\r\nlet lastName = \"Yetayeh\"; // last name of a person\r\nlet country = \"Finland\"; // country\r\nlet city = \"Helsinki\"; // capital city\r\nlet age = 100; // age in years\r\nlet isMarried = true;\r\nconsole.log(firstName, lastName, country, city, age, isMarried); // Asabeneh, Yetayeh, Finland, Helsinki, 100, True\r\n\r\n// Declaring variables with number values\r\n\r\nconst gravity = 9.81; // earth gravity  in m/s2\r\nconst boilingPoint = 100; // water boiling point, temperature in oC\r\nconst PI = 3.14; // geometrical constant\r\nconsole.log(gravity, boilingPoint, PI); // 9.81, 100, 3.14\r\n\r\n// Variables can also be declaring in one line separated by comma\r\n\r\nlet name = \"Asabeneh\", //name of a person\r\n  job = \"teacher\",\r\n  live = \"Finland\";\r\nconsole.log(name, job, live);\r\n```\r\n\r\n### Exercise - 1 : Variables\r\n\r\n1. Declare four variables without assigning values\r\n2. Declare four variables with assigning values\r\n3. Declare variables to store your first name, last name, marital status, country and age in multiple lines\r\n4. Declare variables to store your first name, last name, marital status, country and age in a single line\r\n5. Declare two variables _myAge_ and _yourAge_ and assign them initial values and log to browser console.\r\n   Output:\r\n\r\n   ```sh\r\n   I am 25 years old.\r\n   You are 30 years old.\r\n   ```\r\n\r\n## Comments\r\n\r\nCommenting in JavaScript is similar to other programming languages. Comments can help to make code more readable.\r\nThere are two ways of commenting:\r\n\r\n- _Single line commenting_\r\n- _Multiline commenting_\r\n\r\n```js\r\n// let firstName = 'Asabeneh'; single line comment\r\n// let lastName = 'Yetayeh'; single line comment\r\n```\r\n\r\nMultiline commenting:\r\n\r\n```js\r\n/*\r\n    let location = 'Helsinki';\r\n    let age = 100;\r\n    let isMarried = true;\r\n    This is a Multiple line comment\r\n    */\r\n```\r\n\r\n### Exercise: Comments\r\n\r\n1. Write a single line comment which says, _comments can make code readable_\r\n1. Write a multiline comment which says, _comments can make code readable, easy to use_\r\n   _and informative_\r\n\r\n## Data types\r\n\r\nIn the previous section, we mentioned a little bit about data types. Data or values have data types. Data types describe the characteristics of data. Data types can be divided into two\r\n\r\n1. Primitive data types\r\n2. Non-primitive data types(Object References)\r\n\r\n### Primitive Data Types\r\n\r\nPrimitive data types in JavaScript includes:\r\n\r\n1.  Numbers - Integers, floats\r\n2.  Strings - Any data under single or double quote\r\n3.  Booleans - true or false value\r\n4.  Null - empty value or no value\r\n5.  Undefined - a declared variable without a value\r\n\r\nNon-primitive data types in JavaScript includes:\r\n\r\n1. Objects\r\n2. Functions\r\n3. Arrays\r\n\r\nNow, let us see what exactly mean primitive and non-primitive data types.\r\n_Primitive_ data types are immutable(non-modifiable) data types. Once a primitive data type is created we can not modify it.\r\n**Example:**\r\n\r\n```js\r\nlet word = \"JavaScript\";\r\n```\r\n\r\nIf we try to modify the string stored in variable _word_, JavaScript will raise an error. Any data type under a single quote, double-quote, or backtick is a string data type.\r\n\r\n```js\r\nword[0] = \"Y\";\r\n```\r\n\r\nThis expression does not change the string stored in the variable _word_. So, we can say that strings are not modifiable or immutable.\r\nPrimitive data types are compared by its values. Let us compare different data values. See the example below:\r\n\r\n```js\r\nlet numOne = 3;\r\nlet numTwo = 3;\r\n\r\nconsole.log(numOne == numTwo); // true\r\n\r\nlet js = \"JavaScript\";\r\nlet py = \"Python\";\r\n\r\nconsole.log(js == py); //false\r\n\r\nlet lightOn = true;\r\nlet lightOff = false;\r\n\r\nconsole.log(lightOn == lightOff); // false\r\n```\r\n\r\n### Non-Primitive Data Types\r\n\r\n_Non-primitive_ data types are modifiable or mutable. We can modify the value of non-primitive data types after it gets created.\r\nLet us see by creating an array. An array is a list of data values in a square bracket. Arrays can contain the same or different data types. Array values are referenced by their index. In JavaScript array index starts at zero. I.e., the first element of an array is found at index zero, the second element at index one, and the third element at index two, etc.\r\n\r\n```js\r\nlet nums = [1, 2, 3];\r\nnums[0] = 10;\r\n\r\nconsole.log(nums); // [10, 2, 3]\r\n```\r\n\r\nAs you can see, an array in which a non-primitive data type is mutable. Non-primitive data types can not be compared by value. Even if two non-primitive data types have the same properties and values, they are not strictly equal.\r\n\r\n```js\r\nlet nums = [1, 2, 3];\r\nlet numbers = [1, 2, 3];\r\n\r\nconsole.log(nums == numbers); // false\r\n\r\nlet userOne = {\r\n  name: \"Asabeneh\",\r\n  role: \"teaching\",\r\n  country: \"Finland\",\r\n};\r\n\r\nlet userTwo = {\r\n  name: \"Asabeneh\",\r\n  role: \"teaching\",\r\n  country: \"Finland\",\r\n};\r\n\r\nconsole.log(userOne == userTwo); // false\r\n```\r\n\r\nRule of thumb, we do not compare non-primitive data types. Do not compare array, function, or object.\r\nNon-primitive values are referred to as reference types because they are being compared by reference instead of value. Two objects are only strictly equal if they refer to the same underlying object.\r\n\r\n```js\r\nlet nums = [1, 2, 3];\r\nlet numbers = nums;\r\n\r\nconsole.log(nums == numbers); // true\r\n\r\nlet userOne = {\r\n  name: \"Asabeneh\",\r\n  role: \"teaching\",\r\n  country: \"Finland\",\r\n};\r\n\r\nlet userTwo = userOne;\r\n\r\nconsole.log(userOne == userTwo); // true\r\n```\r\n\r\nIf you have a hard time understanding the difference between primitive data types and non-primitive data types, you are not the only one. Calm down and just go to the next section and try to come back after some time. Now let us start the data types by number type.\r\n\r\n## Numbers\r\n\r\nNumbers are integers and decimal values which can do all the arithmetic operations.\r\nLets' see some examples of Numbers.\r\n\r\n### Declaring number data types\r\n\r\n```js\r\nlet age = 35;\r\nconst gravity = 9.81; //we use const for non-changing values, gravitational constant in  m/s2\r\nlet mass = 72; // mass in Kilogram\r\nconst PI = 3.14; // pi a geometrical constant\r\n\r\n//More Examples\r\nconst boilingPoint = 100; // temperature in oC, boiling point of water which is a constant\r\nconst bodyTemp = 37; // oC average human body temperature, which is a constant\r\n\r\nconsole.log(age, gravity, mass, PI, boilingPoint, bodyTemp);\r\n```\r\n\r\n### Math Object\r\n\r\nIn JavaScript the Math Object provides a lots of methods to work with numbers.\r\n\r\n```js\r\nconst PI = Math.PI;\r\n\r\nconsole.log(PI); // 3.141592653589793\r\n\r\n// Rounding to the closest number\r\n// if above .5 up if less 0.5 down rounding\r\n\r\nconsole.log(Math.round(PI)); // 3 to round values to the nearest number\r\n\r\nconsole.log(Math.round(9.81)); // 10\r\n\r\nconsole.log(Math.floor(PI)); // 3 rounding down\r\n\r\nconsole.log(Math.ceil(PI)); // 4 rounding up\r\n\r\nconsole.log(Math.min(-5, 3, 20, 4, 5, 10)); // -5, returns the minimum value\r\n\r\nconsole.log(Math.max(-5, 3, 20, 4, 5, 10)); // 20, returns the maximum value\r\n\r\nconst randNum = Math.random(); // creates random number between 0 to 0.999999\r\nconsole.log(randNum);\r\n\r\n// Let us  create random number between 0 to 10\r\n\r\nconst num = Math.floor(Math.random() * 11); // creates random number between 0 and 10\r\nconsole.log(num);\r\n\r\n//Absolute value\r\nconsole.log(Math.abs(-10)); //10\r\n\r\n//Square root\r\nconsole.log(Math.sqrt(100)); // 10\r\n\r\nconsole.log(Math.sqrt(2)); //1.4142135623730951\r\n\r\n// Power\r\nconsole.log(Math.pow(3, 2)); // 9\r\n\r\nconsole.log(Math.E); // 2.718\r\n\r\n// Logarithm\r\n//Returns the natural logarithm of base E of x, Math.log(x)\r\nconsole.log(Math.log(2)); // 0.6931471805599453\r\nconsole.log(Math.log(10)); // 2.302585092994046\r\n\r\n// Trigonometry\r\nMath.sin(0);\r\nMath.sin(60);\r\n\r\nMath.cos(0);\r\nMath.cos(60);\r\n```\r\n\r\n#### Random number generator\r\n\r\nThe JavaScript Math Object has a random() method number generator which generates number from 0 to 0.999999999...\r\n\r\n```js\r\nlet randomNum = Math.random(); // generates 0 to 0.999\r\n```\r\n\r\nNow, let us see how we can use random() method to generate a random number between 0 and 10 inclusive.\r\n\r\n```js\r\nlet randomNum = Math.random(); // generates 0 to 0.999\r\nlet numBtnZeroAndTen = randomNum * 11;\r\n\r\nconsole.log(numBtnZeroAndTen); // this gives: min 0 and max 10.99\r\n\r\nlet randomNumRoundToFloor = Math.floor(numBtnZeroAndTen);\r\nconsole.log(randomNumRoundToFloor); // this gives between 0 and 10\r\n```\r\n\r\n## Strings\r\n\r\nStrings are texts, which are under **_single_** or **_double_** quote. To declare a string, we need a variable name, assignment operator, a value under a single quote, double-quote, or backtick.\r\nLets' see some examples of string:\r\n\r\n```js\r\nlet space = \" \"; // an empty space string\r\nlet firstName = \"Asabeneh\";\r\nlet lastName = \"Yetayeh\";\r\nlet country = \"Finland\";\r\nlet city = \"Helsinki\";\r\nlet language = \"JavaScript\";\r\nlet job = \"teacher\";\r\n```\r\n\r\n### String Concatenation\r\n\r\nConnect two or more strings together is called concatenation.\r\n\r\n```js\r\n// Declaring different variables of different data types\r\nlet space = \" \";\r\nlet firstName = \"Asabeneh\";\r\nlet lastName = \"Yetayeh\";\r\nlet country = \"Finland\";\r\nlet city = \"Helsinki\";\r\nlet language = \"JavaScript\";\r\nlet job = \"teacher\";\r\n```\r\n\r\n```js\r\nlet fullName = firstName + space + lastName; // concatenation, merging two string together.\r\nconsole.log(fullName);\r\n```\r\n\r\n```sh\r\nAsabeneh Yetayeh\r\n```\r\n\r\nWe can concatenate string in different ways.\r\n\r\n#### Concatenating using addition operator\r\n\r\nConcatenating using the addition operator is an old way. This way of concatenating is tedious and error-prone. It is good to know how to concatenate this way, but I strongly suggest to use the second way.\r\n\r\n```js\r\n// Declaring different variables of different data types\r\nlet space = \" \";\r\nlet firstName = \"Asabeneh\";\r\nlet lastName = \"Yetayeh\";\r\nlet country = \"Finland\";\r\nlet city = \"Helsinki\";\r\nlet language = \"JavaScript\";\r\nlet job = \"teacher\";\r\nlet age = 250;\r\nlet fullName = firstName + space + lastName;\r\n\r\nlet personInfoOne = fullName + \". I am \" + age + \". I live in \" + country; // ES5\r\n\r\nconsole.log(personInfoOne);\r\n```\r\n\r\n```sh\r\nAsabeneh Yetayeh. I am 250. I live in Finland\r\n```\r\n\r\n#### Long Literal Strings\r\n\r\nA string could be a single character or paragraph or a page. If the string length is too big it does not fit in one line. We can use the backslash character (\\\\) at the end of each line to indicate that the string will continue on the next line.\r\n**Example:**\r\n\r\n```js\r\nconst paragraph =\r\n  \"My name is Asabeneh Yetayeh. I live in Finland, Helsinki.\\\r\nI am a teacher and I love teaching. I teach HTML, CSS, JavaScript, React, Redux, \\\r\nNode.js, Python, Data Analysis and D3.js for anyone who is interested to learn. \\\r\nIn the end of 2019, I was thinking to expand my teaching and to reach \\\r\nto global audience and I started a Python challenge from November 20 - December 19.\\\r\nIt was one of the most rewarding and inspiring experience.\\\r\nNow, we are in 2020. I am enjoying preparing the 30DaysOfJavaScript challenge and \\\r\nI hope you are enjoying too.\";\r\nconsole.log(paragraph);\r\n```\r\n\r\n#### Escape Sequences in string\r\n\r\nIn JavaScript and other programming language \\ followed by some characters is an escape sequence. Let's see the most common escape characters:\r\n\r\n- \\n: new line\r\n- \\t: Tab means(8 spaces)\r\n- \\\\\\\\: Back slash\r\n- \\\\': Single quote (')\r\n- \\\\\":Double quote (\")\r\n\r\n```js\r\nconsole.log(\r\n  \"I hope every one is enjoying the 30 Days Of JavaScript challenge.\\nDo you ?\"\r\n); // line break\r\nconsole.log(\"Days\\tTopics\\tExercises\");\r\nconsole.log(\"Day 1\\t3\\t5\");\r\nconsole.log(\"Day 2\\t3\\t5\");\r\nconsole.log(\"Day 3\\t3\\t5\");\r\nconsole.log(\"Day 4\\t3\\t5\");\r\nconsole.log(\"This is a back slash  symbol (\\\\)\"); // To write a back slash\r\nconsole.log('In every programming language it starts with \"Hello, World!\"');\r\nconsole.log(\"In every programming language it starts with 'Hello, World!'\");\r\nconsole.log(\"The saying 'Seeing is Believing' is't correct in 2020\");\r\n```\r\n\r\n#### Template Literals(Template Strings)\r\n\r\nTo create a template string, we use two backticks. We can inject data as expression inside a template string. To inject data, we enclose the expression with a curly bracket({}) followed by a $ sign. See the syntax below.\r\n\r\n```js\r\n//Syntax\r\n`String literal text``String literal text ${expression}`;\r\n```\r\n\r\n**Example: 1**\r\n\r\n```js\r\nconsole.log(`The sum of 2 and 3 is 5`); // statically writing the data\r\nlet a = 2;\r\nlet b = 3;\r\nconsole.log(`The sum of ${a} and ${b} is ${a + b}`); // injecting the data dynamically\r\n```\r\n\r\n**Example:2**\r\n\r\n```js\r\nlet firstName = \"Asabeneh\";\r\nlet lastName = \"Yetayeh\";\r\nlet country = \"Finland\";\r\nlet city = \"Helsinki\";\r\nlet language = \"JavaScript\";\r\nlet job = \"teacher\";\r\nlet age = 250;\r\nlet fullName = firstName + \" \" + lastName;\r\n\r\nlet personInfoTwo = `I am ${fullName}. I am ${age}. I live in ${country}.`; //ES6 - String interpolation method\r\nlet personInfoThree = `I am ${fullName}. I live in ${city}, ${country}. I am a ${job}. I teach ${language}.`;\r\nconsole.log(personInfoTwo);\r\nconsole.log(personInfoThree);\r\n```\r\n\r\n```sh\r\nI am Asabeneh Yetayeh. I am 250. I live in Finland.\r\nI am Asabeneh Yetayeh. I live in Helsinki, Finland. I am a teacher. I teach JavaScript.\r\n```\r\n\r\nUsing a string template or string interpolation method, we can add expression, which could be a value or some operations(comparison, arithmetic operations, ternary operation).\r\n\r\n```js\r\nlet a = 2;\r\nlet b = 3;\r\nconsole.log(`${a} is greater than ${b}: ${a > b}`);\r\n```\r\n\r\n```sh\r\n2 is greater than 3: false\r\n```\r\n\r\n### String Methods\r\n\r\nEverything in JavaScript is an object. A string is a primitive data type that means we can not modify once it is created. The string object has many string methods. There are different string methods that can help us to work with strings.\r\n\r\n1. _length_: The string _length_ method returns the number of characters in a string included empty space.\r\n   **Example:**\r\n\r\n   ```js\r\n   let js = \"JavaScript\";\r\n   console.log(js.length); // 10\r\n   let firstName = \"Asabeneh\";\r\n   console.log(firstName.length); // 8\r\n   ```\r\n\r\n2. _Accessing characters in a string_: We can access each character in a string using its index. In programming, counting starts from 0. The first index of the string is zero, and the last index is one minus the length of the string.\r\n\r\n![Accessing sting by index](./images/string_indexes.png)\r\n\r\nLet us access different characters in 'JavaScript' string.\r\n\r\n```js\r\nlet string = \"JavaScript\";\r\nlet firstLetter = string[0];\r\n\r\nconsole.log(firstLetter); // J\r\n\r\nlet secondLetter = string[1]; // a\r\nlet thirdLetter = string[2];\r\nlet lastLetter = string[9];\r\n\r\nconsole.log(lastLetter); // t\r\n\r\nlet lastIndex = string.length - 1;\r\n\r\nconsole.log(lastIndex); // 9\r\nconsole.log(string[lastIndex]); // t\r\n```\r\n\r\n3. _toUpperCase()_: this method changes the string to uppercase letters.\r\n\r\n```js\r\nlet string = \"JavaScript\";\r\n\r\nconsole.log(string.toUpperCase()); // JAVASCRIPT\r\n\r\nlet firstName = \"Asabeneh\";\r\n\r\nconsole.log(firstName.toUpperCase()); // ASABENEH\r\n\r\nlet country = \"Finland\";\r\n\r\nconsole.log(country.toUpperCase()); // FINLAND\r\n```\r\n\r\n4. _toLowerCase()_: this method changes the string to lowercase letters.\r\n\r\n```js\r\nlet string = \"JavasCript\";\r\n\r\nconsole.log(string.toLowerCase()); // javascript\r\n\r\nlet firstName = \"Asabeneh\";\r\n\r\nconsole.log(firstName.toLowerCase()); // asabeneh\r\n\r\nlet country = \"Finland\";\r\n\r\nconsole.log(country.toLowerCase()); // finland\r\n```\r\n\r\n5. _substr()_: It takes two arguments, the starting index and number of characters to slice.\r\n\r\n```js\r\nlet string = \"JavaScript\";\r\nconsole.log(string.substr(4, 6)); // Script\r\n\r\nlet country = \"Finland\";\r\nconsole.log(country.substr(3, 4)); // land\r\n```\r\n\r\n6. _substring()_: It takes two arguments, the starting index and the stopping index but it doesn't include the stopping index.\r\n\r\n```js\r\nlet string = \"JavaScript\";\r\n\r\nconsole.log(string.substring(0, 4)); // Java\r\nconsole.log(string.substring(4, 10)); // Script\r\nconsole.log(string.substring(4)); // Script\r\n\r\nlet country = \"Finland\";\r\n\r\nconsole.log(country.substring(0, 3)); // Fin\r\nconsole.log(country.substring(3, 7)); // land\r\nconsole.log(country.substring(3)); // land\r\n```\r\n\r\n7. _split()_: The split method splits a string at a specified place.\r\n\r\n```js\r\nlet string = \"30 Days Of JavaScript\";\r\n\r\nconsole.log(string.split()); // [\"30 Days Of JavaScript\"]\r\nconsole.log(string.split(\" \")); // [\"30\", \"Days\", \"Of\", \"JavaScript\"]\r\n\r\nlet firstName = \"Asabeneh\";\r\n\r\nconsole.log(firstName.split()); // [\"Asabeneh\"]\r\nconsole.log(firstName.split(\"\")); // [\"A\", \"s\", \"a\", \"b\", \"e\", \"n\", \"e\", \"h\"]\r\n\r\nlet countries = \"Finland, Sweden, Norway, Denmark, and Iceland\";\r\n\r\nconsole.log(countries.split(\",\")); // [\"Finland\", \" Sweden\", \" Norway\", \" Denmark\", \" and Iceland\"]\r\nconsole.log(countries.split(\", \")); //  [\"Finland\", \"Sweden\", \"Norway\", \"Denmark\", \"and Iceland\"]\r\n```\r\n\r\n8. _trim()_: Removes trailing space in the beginning or the end of a string.\r\n\r\n```js\r\nlet string = \"   30 Days Of JavaScript   \";\r\n\r\nconsole.log(string);\r\nconsole.log(string.trim(\" \"));\r\n\r\nlet firstName = \" Asabeneh \";\r\n\r\nconsole.log(firstName);\r\nconsole.log(firstName.trim());\r\n```\r\n\r\n```sh\r\n   30 Days Of JavasCript\r\n30 Days Of JavasCript\r\n  Asabeneh\r\nAsabeneh\r\n```\r\n\r\n9. _includes()_: It takes a substring argument and it check if substring argument exists in the string. _includes()_ returns a boolean. It checks if a substring exist in a string and it returns true if it exists and false if it doesn't exist.\r\n\r\n```js\r\nlet string = \"30 Days Of JavaScript\";\r\n\r\nconsole.log(string.includes(\"Days\")); // true\r\nconsole.log(string.includes(\"days\")); // false\r\nconsole.log(string.includes(\"Script\")); // true\r\nconsole.log(string.includes(\"script\")); // false\r\nconsole.log(string.includes(\"java\")); // false\r\nconsole.log(string.includes(\"Java\")); // true\r\n\r\nlet country = \"Finland\";\r\n\r\nconsole.log(country.includes(\"fin\")); // false\r\nconsole.log(country.includes(\"Fin\")); // true\r\nconsole.log(country.includes(\"land\")); // true\r\nconsole.log(country.includes(\"Land\")); // false\r\n```\r\n\r\n10. _replace()_: takes to parameter the old substring and new substring.\r\n\r\n```js\r\nstring.replace(oldsubstring, newsubstring);\r\n```\r\n\r\n```js\r\nlet string = \"30 Days Of JavaScript\";\r\nconsole.log(string.replace(\"JavaScript\", \"Python\")); // 30 Days Of Python\r\n\r\nlet country = \"Finland\";\r\nconsole.log(country.replace(\"Fin\", \"Noman\")); // Nomanland\r\n```\r\n\r\n11. _charAt()_: Takes index and it returns the value at that index\r\n\r\n```js\r\nstring.charAt(index);\r\n```\r\n\r\n```js\r\nlet string = \"30 Days Of JavaScript\";\r\nconsole.log(string.charAt(0)); // 3\r\n\r\nlet lastIndex = string.length - 1;\r\nconsole.log(string.charAt(lastIndex)); // t\r\n```\r\n\r\n12. _charCodeAt()_: Takes index and it returns char code(ASCII number) of the value at that index\r\n\r\n```js\r\nstring.charCodeAt(index);\r\n```\r\n\r\n```js\r\nlet string = \"30 Days Of JavaScript\";\r\nconsole.log(string.charCodeAt(3)); // D ASCII number is 51\r\n\r\nlet lastIndex = string.length - 1;\r\nconsole.log(string.charCodeAt(lastIndex)); // t ASCII is 116\r\n```\r\n\r\n13. _indexOf()_: Takes a substring and if the substring exists in a string it returns the first position of the substring if does not exist it returns -1\r\n\r\n```js\r\nstring.indexOf(substring);\r\n```\r\n\r\n```js\r\nlet string = \"30 Days Of JavaScript\";\r\n\r\nconsole.log(string.indexOf(\"D\")); // 3\r\nconsole.log(string.indexOf(\"Days\")); // 3\r\nconsole.log(string.indexOf(\"days\")); // -1\r\nconsole.log(string.indexOf(\"a\")); // 4\r\nconsole.log(string.indexOf(\"JavaScript\")); // 11\r\nconsole.log(string.indexOf(\"Script\")); //15\r\nconsole.log(string.indexOf(\"script\")); // -1\r\n```\r\n\r\n14. _lastIndexOf()_: Takes a substring and if the substring exists in a string it returns the last position of the substring if it does not exist it returns -1\r\n\r\n```js\r\n//syntax\r\nstring.lastIndexOf(substring);\r\n```\r\n\r\n```js\r\nlet string =\r\n  \"I love JavaScript. If you do not love JavaScript what else can you love.\";\r\n\r\nconsole.log(string.lastIndexOf(\"love\")); // 67\r\nconsole.log(string.lastIndexOf(\"you\")); // 63\r\nconsole.log(string.lastIndexOf(\"JavaScript\")); // 38\r\n```\r\n\r\n15. _concat()_: it takes many substrings and creates concatenation.\r\n\r\n```js\r\nstring.concat(substring, substring, substring);\r\n```\r\n\r\n```js\r\nlet string = \"30\";\r\nconsole.log(string.concat(\"Days\", \"Of\", \"JavaScript\")); // 30DaysOfJavaScript\r\n\r\nlet country = \"Fin\";\r\nconsole.log(country.concat(\"land\")); // Finland\r\n```\r\n\r\n16. _startsWith_: it takes a substring as an argument and it checks if the string starts with that specified substring. It returns a boolean(true or false).\r\n\r\n```js\r\n//syntax\r\nstring.startsWith(substring);\r\n```\r\n\r\n```js\r\nlet string = \"Love is the best to in this world\";\r\n\r\nconsole.log(string.startsWith(\"Love\")); // true\r\nconsole.log(string.startsWith(\"love\")); // false\r\nconsole.log(string.startsWith(\"world\")); // false\r\n\r\nlet country = \"Finland\";\r\n\r\nconsole.log(country.startsWith(\"Fin\")); // true\r\nconsole.log(country.startsWith(\"fin\")); // false\r\nconsole.log(country.startsWith(\"land\")); //  false\r\n```\r\n\r\n17. _endsWith_: it takes a substring as an argument and it checks if the string starts with that specified substring. It returns a boolean(true or false).\r\n\r\n```js\r\nstring.endsWith(substring);\r\n```\r\n\r\n```js\r\nlet string = \"Love is the best to in this world\";\r\n\r\nconsole.log(string.endsWith(\"world\")); // true\r\nconsole.log(string.endsWith(\"love\")); // false\r\nconsole.log(string.endsWith(\"in this world\")); // true\r\n\r\nlet country = \"Finland\";\r\n\r\nconsole.log(country.endsWith(\"land\")); // true\r\nconsole.log(country.endsWith(\"fin\")); // false\r\nconsole.log(country.endsWith(\"Fin\")); //  false\r\n```\r\n\r\n18. _search_: it takes a substring as an argument and it returns the index of the first match.\r\n\r\n```js\r\nstring.search(substring);\r\n```\r\n\r\n```js\r\nlet string =\r\n  \"I love JavaScript. If you do not love JavaScript what else can you love.\";\r\nconsole.log(string.search(\"love\")); // 2\r\n```\r\n\r\n19. _match_: it takes a substring or regular expression pattern as an argument and it returns an array if there is match if not it returns null. Let us see how a regular expression pattern looks like. It starts with / sign and ends with / sign.\r\n\r\n```js\r\nlet string = \"love\";\r\nlet patternOne = /love/; // with out any flag\r\nlet patternTwo = /love/gi; // g-means to search in the whole text, i - case insensitive\r\n```\r\n\r\nMatch syntax\r\n\r\n```js\r\n// syntax\r\nstring.match(substring);\r\n```\r\n\r\n```js\r\nlet string =\r\n  \"I love JavaScript. If you do not love JavaScript what else can you love.\";\r\nconsole.log(string.match(\"love\"));\r\n```\r\n\r\n```sh\r\n[\"love\", index: 2, input: \"I love JavaScript. If you do not love JavaScript what else can you love.\", groups: undefined]\r\n```\r\n\r\n```js\r\nlet pattern = /love/gi;\r\nconsole.log(string.match(pattern)); // [\"love\", \"love\", \"love\"]\r\n```\r\n\r\nLet us extract numbers from text using regular expression. This is not regular expression section, no panic, we will cover regular expression in other section.\r\n\r\n```js\r\nlet txt =\r\n  \"In 2019, I run 30 Days of Python. Now, in 2020 I super exited to start this challenge\";\r\nlet regEx = /\\d+/;\r\n\r\n// d with escape character means d not a normal d instead acts a digit\r\n// + means one or more digit numbers,\r\n// if there is g after that it means global, search everywhere.\r\n\r\nconsole.log(txt.match(regEx)); // [\"2\", \"0\", \"1\", \"9\", \"3\", \"0\", \"2\", \"0\", \"2\", \"0\"]\r\nconsole.log(txt.match(/\\d+/g)); // [\"2019\", \"30\", \"2020\"]\r\n```\r\n\r\n20. _repeat()_: it takes a number argument and it returned the repeated version of the string.\r\n\r\n```js\r\nstring.repeat(n);\r\n```\r\n\r\n```js\r\nlet string = \"love\";\r\nconsole.log(string.repeat(10)); // lovelovelovelovelovelovelovelovelovelove\r\n```\r\n\r\n## Checking Data types and Casting\r\n\r\n### Checking data types\r\n\r\n- Check Data types: To check the data type of a certain data type we use the _typeof_ and we also change one data type to another.\r\n  **Example:**\r\n\r\n```js\r\n// Different javascript data types\r\n// Let's declare different data types\r\n\r\nlet firstName = \"Asabeneh\"; // string\r\nlet lastName = \"Yetayeh\"; // string\r\nlet country = \"Finland\"; // string\r\nlet city = \"Helsinki\"; // string\r\nlet age = 250; // number, it is not my real age, do not worry about it\r\nlet job; // undefined, because a value was not assigned\r\n\r\nconsole.log(typeof \"Asabeneh\"); // string\r\nconsole.log(typeof firstName); // string\r\nconsole.log(typeof 10); // number\r\nconsole.log(typeof 3.14); // number\r\nconsole.log(typeof true); // boolean\r\nconsole.log(typeof false); // boolean\r\nconsole.log(typeof NaN); // number\r\nconsole.log(typeof job); // undefined\r\nconsole.log(typeof undefined); // undefined\r\nconsole.log(typeof null); // object\r\n```\r\n\r\n### Changing data type(Casting)\r\n\r\n- Casting: Converting one data type to another data type. We use _parseInt()_, _parseFloat()_, _Number()_, _+ sign_, _str()_\r\n  When we do arithmetic operations string numbers should be first converted to integer or float if not it returns an error.\r\n\r\n#### String to Int\r\n\r\nWe can convert string number to a number. Any number inside a quote is a string number. An example of a string number: '10', '5', etc.\r\nWe can convert string to number using the following methods:\r\n\r\n- parseInt()\r\n- Number()\r\n- Plus sign(+)\r\n\r\n```js\r\nlet num = \"10\";\r\nlet numInt = parseInt(num);\r\nconsole.log(numInt); // 10\r\n```\r\n\r\n```js\r\nlet num = \"10\";\r\nlet numInt = Number(num);\r\n\r\nconsole.log(numInt); // 10\r\n```\r\n\r\n```js\r\nlet num = \"10\";\r\nlet numInt = +num;\r\n\r\nconsole.log(numInt); // 10\r\n```\r\n\r\n#### String to Float\r\n\r\nWe can convert string float number to a float number. Any float number inside a quote is a string float number. An example of a string float number: '9.81', '3.14', '1.44', etc.\r\nWe can convert string float to number using the following methods:\r\n\r\n- parseFloat()\r\n- Number()\r\n- Plus sign(+)\r\n\r\n```js\r\nlet num = \"9.81\";\r\nlet numFloat = parseFloat(num);\r\n\r\nconsole.log(numFloat); // 9.81\r\n```\r\n\r\n```js\r\nlet num = \"9.81\";\r\nlet numFloat = Number(num);\r\n\r\nconsole.log(numFloat); // 9.81\r\n```\r\n\r\n```js\r\nlet num = \"9.81\";\r\nlet numFloat = +num;\r\n\r\nconsole.log(numInt); // 9.81\r\n```\r\n\r\n#### Float to Int\r\n\r\nWe can convert float numbers to integers.\r\nWe use the following method to convert float to int:\r\n\r\n- parseInt()\r\n\r\n```js\r\nlet num = 9.81;\r\nlet numInt = parseInt(num);\r\n\r\nconsole.log(numInt); // 9\r\n```\r\n\r\n### Exercises: Data Types\r\n\r\n1. Declare variables and assign string, boolean, undefined and null data types\r\n1. The JavaScript **_typeof_** operator uses to check different data types. Check the data type of each variables from question number 1.\r\n\r\n#### Exercise: String\r\n\r\n1. Declare a variable name company and assign it to an initial value **'Coding Academy'**.\r\n1. Print the string on the browser console using **console.log()**\r\n1. Print the **length** of the string on the browser console using _console.log()_\r\n1. Change all the string to capital letters using **toUpperCase()** method\r\n1. Change all the string to lowercase letters using **toLowerCase()** method\r\n1. Cut(slice) out the first word of the string using **slice**, **substr()** or **substring()** method\r\n1. Use **substr** to slice out the phase **because because because** in the following sentence:**'You cannot end a sentence with because because because is a conjunction'**\r\n1. Check if the string contains a word **Academy** using **includes()** method\r\n1. Split the **string** into **array** using **split()** method\r\n1. Split the string Coding Academy at the space using **split()** method\r\n1. 'Facebook, Google, Microsoft, Apple, IBM, Oracle, Amazon' **split** the string at the comma and change it to an array.\r\n1. Change Coding Academy to Microsoft Academy using **replace()** method.\r\n1. What is character at index 10 in 'Coding Academy' string use **charAt()** method.\r\n1. What is the character code of A in 'Coding Academy' string using **charCodeAt()**\r\n1. Use **indexOf** to determine the position of the first occurrence of c in Coding Academy\r\n1. Use **lastIndexOf** to determine the position of the last occurrence of c in Coding Academy.\r\n1. Use **indexOf** to find the position of the first occurrence of the word **because** in the following sentence:**'You cannot end a sentence with because because because is a conjunction'**\r\n1. Use **lastIndexOf** to find the position of the first occurrence of the word **because** in the following sentence:**'You cannot end a sentence with because because because is a conjunction'**\r\n1. Use **search** to find the position of the first occurrence of the word **because** in the following sentence:**'You cannot end a sentence with because because because is a conjunction'**\r\n1. Use **trim()** to remove if there is trailing whitespace at the beginning and the end of a string.E.g ' Coding Academy '.\r\n1. Use **startsWith()** method with the string Coding Academy make the result true\r\n1. Use **endsWith()** method with the string Coding Academy make the result true\r\n1. Use **match()** method to find all the c’s in Coding Academy\r\n1. Use **match()** to count the number all because's in the following sentence:**'You cannot end a sentence with because because because is a conjunction'**\r\n1. Use **concat()** and merge 'Coding' and 'Academy' to a single string, 'Coding Academy'\r\n1. Use **repeat()** method to print Coding Academy 5 times\r\n1. Calculate the total annual income of the person by extract the numbers from the following text. 'He earns 5000 euro from salary per month, 10000 euro annual bonus, 15000 euro online courses per month.'\r\n\r\n### Booleans\r\n\r\nBoolean value is either true or false. Any comparisons return a boolean value which is either true or false.\r\n\r\n```js\r\nlet isLightOn = true;\r\nlet isRaining = false;\r\nlet hungry = false;\r\nlet isMarried = true;\r\n```\r\n\r\n#### Exercise: Booleans\r\n\r\nBoolean value is either true or false.\r\n\r\n1. Write three JavaScript statement which provide truthy value.\r\n1. Write three JavaScript statement which provide falsy value.\r\n1. Use all the following comparison operators to compare the following values: >, < >=, <=, !=, !==,===.\r\n   Which are true or which are false ?\r\n   1. 4 > 3\r\n   1. 4 >= 3\r\n   1. 4 < 3\r\n   1. 4 <= 3\r\n   1. 4 == 4\r\n   1. 4 === 4\r\n   1. 4 != 4\r\n   1. 4 !== 4\r\n   1. 4 != '4'\r\n   1. 4 == '4'\r\n   1. 4 === '4'\r\n\r\n### Undefined\r\n\r\n```js\r\nlet firstName;\r\nconsole.log(firstName); //not defined, because it is not assigned to a value yet\r\n```\r\n\r\n### Null\r\n\r\n```js\r\nlet empty = null;\r\nconsole.log(empty); // -> null , means no value\r\n```\r\n\r\n### Exercise - 6 : Data types\r\n\r\nString, number, boolean, null, undefined and symbol(ES6) are JavaScript primitive data types.\r\n\r\n1. The JavaScript _typeof_ operator uses to check different data types. Check the data type of each variables from question number 1.\r\n\r\n## Operators\r\n\r\n### Arithmetic Operators\r\n\r\nArithmetic operators are mathematical operators:+, -, _, /, _\r\n\r\n```js\r\nlet numOne = 4;\r\nlet numTwo = 3;\r\nlet sum = numOne + numTwo;\r\nlet diff = numOne - numTwo;\r\nlet mult = numOne * numTwo;\r\nlet div = numOne / numTwo;\r\nlet remainder = numOne % numTwo;\r\n\r\nconsole.log(sum, diff, mult, div, remainder); // ->7,1,12,1.33,1\r\n\r\nlet PI = 3.14;\r\nlet radius = 100; // length in meter\r\n\r\nconst gravity = 9.81; // in m/s2\r\nlet mass = 72; // in Kilogram\r\nconst boilingPoint = 100; // temperature in oC, boiling point of water\r\nconst bodyTemp = 37; // body temperature in oC\r\n\r\n// Lets calculate area of a circle\r\n\r\nconst areaOfCircle = PI * radius * radius;\r\nconsole.log(areaOfCircle); // -> 314 m\r\n\r\n// Lets calculate weight of a substance\r\nconst weight = mass * gravity;\r\nconsole.log(weight); // -> 706.32 N(Newton)\r\n\r\n// ConcatEnating string with numbers using string interpolation\r\n/*\r\n The boiling point of water is 100 oC.\r\n Human body temperature is 37 oC.\r\n The gravity of earth is 9.81 m/s2.\r\n */\r\nconsole.log(\r\n  `The boiling point of water is ${boilingPoint} oC.\\nHuman body temperature is ${body} oC.\\nThe gravity of earth is ${gravity} m / s2.`\r\n);\r\n```\r\n\r\n### Exercises : Arithmetic Operators\r\n\r\nJavaScript arithmetic operators are addition(+), subtraction(-), multiplication(\\*), division(/), modulus(%), increment(++) and decrement(--).\r\n\r\n```js\r\nlet operandOne = 4;\r\nlet operandTwo = 3;\r\n```\r\n\r\nUsing the above operands apply different JavaScript arithmetic operators\r\n\r\n### Logical Operators\r\n\r\nThe following symbols are the common logical operators:\r\n&&(ampersand) , ||(pipe) and !(negation).\r\n&& gets true only if the two operands are true.\r\n|| gets true either of the operand is true.\r\n! negates true to false, false to true.\r\n\r\n```js\r\n// && ampersand example\r\n\r\nconst check = 4 > 3 && 10 > 5; // true and true -> true\r\nconst check = 4 > 3 && 10 < 5; // true and false -> false\r\nconst check = 4 < 3 && 10 < 5; // false and false -> false\r\n\r\n// || pipe or, example\r\n\r\nconst check = 4 > 3 || 10 > 5; // true and true -> true\r\nconst check = 4 > 3 || 10 < 5; // true and false -> true\r\nconst check = 4 < 3 || 10 < 5; // false and false -> false\r\n\r\n// ! Negation examples\r\n\r\nlet check = 4 > 3; // -> true\r\nlet check = !(4 > 3); // -> false\r\nlet isLightOn = true; // -> true\r\nlet isLightOff = !isLightOn; // -> false\r\nlet isMarried = !false; // -> true\r\n```\r\n\r\n### Exercises: Logical Operators\r\n\r\nWhich are true or which are false ?\r\n\r\n1. 4 > 3 && 10 < 12\r\n1. 4 > 3 && 10 > 12\r\n1. 4 > 3 || 10 < 12\r\n1. 4 > 3 || 10 > 12\r\n1. !(4 > 3)\r\n1. !(4 < 3)\r\n1. !(false)\r\n1. !(4 > 3 && 10 < 12)\r\n1. !(4 > 3 && 10 > 12)\r\n1. !(4 === '4')\r\n\r\n### Comparison Operators\r\n\r\n```js\r\n4 > 3;\r\n4 >= 4;\r\n4 < 3;\r\n4 <= 3;\r\n4 != 3;\r\n4 !== \"4\";\r\n4 == \"4\";\r\n4 === \"4\";\r\n4 === 4;\r\n```\r\n\r\n### Exercise: Comparison Operators\r\n\r\nBoolean value is either true or false. Any comparison return a boolean either true or false.\r\nUse all the following comparison operators to compare the following values: >, < >=, <=, !=, !==,===.\r\nWhich are true or which are false ?\r\n\r\n1. 4 > 3\r\n1. 4 >= 3\r\n1. 4 < 3\r\n1. 4 <= 3\r\n1. 4 == 4\r\n1. 4 === 4\r\n1. 4 != 4\r\n1. 4 !== 4\r\n1. 4 != '4'\r\n1. 4 == '4'\r\n1. 4 === '4'\r\n\r\n## Conditionals\r\n\r\n### if\r\n\r\nWe use if condition to check only on condition.\r\n\r\n```js\r\nif (condition) {\r\n  // code goes here\r\n}\r\n\r\nlet isRaining = true;\r\nif (isRaining) {\r\n  console.log(\"Remember to take your rain coat.\");\r\n}\r\n```\r\n\r\n### if else\r\n\r\nWhen we have more than one condition we use the if and else condition.\r\n\r\n```js\r\nif (condition) {\r\n  // if the condition meets, this block of code runs\r\n} else {\r\n  // if condition doesn't meet, this block code runs\r\n}\r\n\r\nlet isRaining = true;\r\nif (isRaining) {\r\n  console.log(\"You need a rain coat.\");\r\n} else {\r\n  console.log(\"No need for a rain coat.\");\r\n}\r\n```\r\n\r\n### if else if else\r\n\r\nWhenever we have multiple conditions.\r\n\r\n```js\r\n// if else if else\r\nlet weather = \"sunny\";\r\nif (weather === \"rainy\") {\r\n  console.log(\"You need a rain coat.\");\r\n} else if (weather === \"cloudy\") {\r\n  console.log(\"It might be cold, you need a jacket.\");\r\n} else if (weather === \"sunny\") {\r\n  console.log(\"Go out freely.\");\r\n} else {\r\n  console.log(\"No need for rain coat.\");\r\n}\r\n```\r\n\r\n### switch\r\n\r\nSwitch an alternative for if else if else\r\n\r\n```js\r\nvar weather = \"cloudy\";\r\nswitch (weather) {\r\n  case \"rainy\":\r\n    console.log(\"You need a rain coat.\");\r\n    break;\r\n  case \"cloudy\":\r\n    console.log(\"It might be cold, you need a jacket.\");\r\n    break;\r\n  case \"sunny\":\r\n    console.log(\"Go out freely.\");\r\n    break;\r\n  default:\r\n    console.log(\" No need for rain coat.\");\r\n    break;\r\n}\r\n// Switch More Examples\r\nvar dayUserInput = prompt(\"What day is it ?\");\r\nvar day = dayUserInput.toLowerCase();\r\nswitch (day) {\r\n  case \"monday\":\r\n    console.log(\"Today is Monday\");\r\n    break;\r\n  case \"tuesday\":\r\n    console.log(\"Today is Tuesday\");\r\n    break;\r\n  case \"wednesday\":\r\n    console.log(\"Today is Wednesday\");\r\n    break;\r\n  case \"thursday\":\r\n    console.log(\"Today is Thursday\");\r\n    break;\r\n  case \"friday\":\r\n    console.log(\"Today is Friday\");\r\n    break;\r\n  case \"saturday\":\r\n    console.log(\"Today is Saturday\");\r\n    break;\r\n  case \"sunday\":\r\n    console.log(\"Today is Sunday\");\r\n    break;\r\n\r\n  default:\r\n    console.log(\"It is not a week day.\");\r\n    break;\r\n}\r\n```\r\n\r\n### Ternary Operators\r\n\r\nAnother way to write conditionals is using ternary operators.\r\n\r\n```js\r\nlet isRaining = true;\r\nisRaining\r\n  ? console.log(\"You need a rain coat.\")\r\n  : console.log(\"No need for a rain coat.\");\r\n```\r\n\r\n### Exercise: Conditionals\r\n\r\n1. Get user input using prompt(“Enter your age:”). If user is 18 or older , give feedback:You are old enough to drive but if not 18 give feedback to wait for the years he supposed to wait for.\r\n   Output:\r\n\r\n   ```sh\r\n   Enter your age: 30\r\n   You are old enough to drive.\r\n   ```\r\n\r\n   Output:\r\n\r\n   ```sh\r\n   Enter your age:15\r\n   You are left with 3 years to drive.\r\n   ```\r\n\r\n1. Compare the values of myAge and yourAge using if … else. Based on the comparison log to console who is older (me or you). Use prompt(“Enter your age:”) to get the age as input.\r\n   Output:\r\n\r\n   ```sh\r\n   Enter your age: 30\r\n   You are 5 years older than me.\r\n   ```\r\n\r\n1. If a is greater than b return a is greater than b else a is less than b.\r\n   Output:\r\n\r\n   ```sh\r\n    let a = 4\r\n    let b = 3\r\n    4 is greater than 3\r\n   ```\r\n\r\n1. Write a code which give grade students according to theirs scores:\r\n   - 80-100, A\r\n   - 70-89, B\r\n   - 60-69, C\r\n   - 50-59, D\r\n   - 0 -49, F\r\n1. Check if the season is Autumn, Winter, Spring or Summer.\r\n   If the user input is:\r\n   - September, October or November, the season is Autumn.\r\n   - December, January or February, the season is Winter.\r\n   - March, April or May, the season is Spring\r\n   - June, July or August, the season is Summer\r\n\r\n## Loops\r\n\r\nIn programming languages to carry out repetitive task we use different kinds of loop. The following examples are the commonly used loops.\r\n\r\n### For Loop\r\n\r\n```js\r\n// for loop structure\r\nfor(initialization, condition, increment/decrement){\r\n  // code goes here\r\n}\r\nfor(let i = 0; i <= 5; i++){\r\n  console.log(i)\r\n}\r\n\r\n```\r\n\r\n### While loop\r\n\r\n```js\r\nlet i = 0;\r\nwhile (i <= 5) {\r\n  console.log(i);\r\n  i++;\r\n}\r\n```\r\n\r\n### Do while loop\r\n\r\n```js\r\nlet i = 0;\r\ndo {\r\n  console.log(i);\r\n  i++;\r\n} while (i <= 5);\r\n```\r\n\r\n### Exercises:Loops\r\n\r\n1. Iterate 0 to 10 using for loop, do the same using while and do while loop.\r\n1. Iterate 10 to 0 using for loop, do the same using while and do while loop.\r\n1. Write a loop that makes seven calls to console.log to output the following triangle:\r\n\r\n   ```js\r\n       #\r\n       ##\r\n       ###\r\n       ####\r\n       #####\r\n       ######\r\n       #######\r\n   ```\r\n\r\n1. Iterate the array, ['HTML', 'CSS', 'JavaScript'] using a for loop and print out the items.\r\n1. Use for loop to iterate from 0 to 100 and print only even numbers\r\n1. Use for loop to iterate from 0 to 100 and print only odd numbers\r\n1. Use for loop to iterate from 0 to 100 and print and print the sum of all numbers.\r\n\r\n   ```js\r\n   The sum all numbers is 5050.\r\n   ```\r\n\r\n1. Use for loop to iterate from 0 to 100 and print the sum of all evens and the sum of all odds.\r\n\r\n   ```js\r\n   The sum of all evens is 2550. And the sum of all odds is 2500.\r\n   ```\r\n\r\n## Arrays\r\n\r\nIn contrast to variables array can store _multiple values_. Each value in an array has an _index_ and each index has _a reference in a memory address_. Each value can be accessed by using their _indexes_. The index of an array starts from _zero_ and the last element is less by one from the length of the array.\r\n\r\n```js\r\nconst numbers = [0, 3.14, 9.81, 37, 98.6, 100]; // set of numbers\r\n\r\nconsole.log(numbers.length) // => to know the size of the array, which is 6\r\nconsole.log(numbers)        // -> [0, 3.14, 9.81, 37, 98.6, 100]\r\nconsole.log(numbers[0])     //  -> 0\r\nconsole.log(numbers[5])     //  -> 100\r\n\r\nlet lastIndex = numbers.length - 1;\r\nconsole.log(numbers[lastIndex]) -> 100\r\nconst webTechs = [\r\n  'HTML',\r\n  'CSS',\r\n  'JavaScript',\r\n  'React',\r\n  'Redux',\r\n  'Node',\r\n  'MongoDB'\r\n]; // List of web technologies\r\n\r\nconsole.log(webTechs)        // all the array items\r\nconsole.log(webTechs.length) // => to know the size of the array, which is 7\r\nconsole.log(webTechs[0])     //  -> HTML\r\nconsole.log(webTechs[6])     //  -> MongoDB\r\n\r\nlet lastIndex = webTechs.length - 1;\r\nconsole.log(webTechs[lastIndex]) -> MongoDB\r\nconst countries = [\r\n  'Albania',\r\n  'Bolivia',\r\n  'Canada',\r\n  'Denmark',\r\n  'Ethiopia',\r\n  'Finland',\r\n  'Germany',\r\n  'Hungary',\r\n  'Ireland',\r\n  'Japan',\r\n  'Kenya'\r\n]; // List of countries;\r\n\r\nconsole.log(countries)     // -> all countries in array\r\nconsole.log(countries[0])  //  -> Albania\r\nconsole.log(countries[10]) //  -> Kenya\r\n\r\nlet lastIndex = countries.length - 1;\r\nconsole.log(countries[lastIndex]) -> // Kenya\r\n\r\nconst shoppingCart = [\r\n  'Milk',\r\n  'Mango',\r\n  'Tomato',\r\n  'Potato',\r\n  'Avocado',\r\n  'Meat',\r\n  'Eggs',\r\n  'Sugar'\r\n]; // List of food products\r\n\r\nconsole.log(shoppingCart)     // -> all shoppingCart in array\r\nconsole.log(shoppingCart[0])  //  -> Milk\r\nconsole.log(shoppingCart[7])  //  -> Sugar\r\n\r\nlet lastIndex = shoppingCart.length - 1;\r\nconsole.log(shoppingCart[lastIndex]) -> // Sugar\r\n```\r\n\r\n### Exercise : Arrays\r\n\r\n1. Declare an _empty_ array;\r\n1. Declare an array with more than 5 number of items\r\n1. Find the length of your array\r\n1. Get the first item, the middle item and the last item of the array\r\n1. Declare an array called _mixedDataTypes_,put different data types and in your array and the array size should be greater than 5\r\n1. Declare an array variable name itCompanies and assign initial values Facebook, Google, Microsoft, Apple, IBM, Oracle and Amazon.\r\n1. Print the array using _console.log()_\r\n1. Print the number of companies in the array\r\n1. Print the first company, middle and last company\r\n1. Print out each company\r\n1. Change companies to uppercase and print them out\r\n1. Print the array like as a sentence: Facebook, Google, Microsoft, Apple, IBM,Oracle and Amazon are big IT companies.\r\n1. Check if a certain company exists in the itCompanies array. If it exist return the company else return a company is _not found_.\r\n1. Filter out companies which have more than one 'o' without the filter method\r\n1. Sort the array using _sort()_ method\r\n1. Reverse the array without _reverse_ method\r\n1. Reverse the array using _reverse()_ method\r\n1. Slice out the first 3 companies from the array\r\n1. Slice out the last 3 companies from the array\r\n1. Slice out the middle IT company or companies from the array\r\n1. Remove the first IT company from the array\r\n1. Remove the middle IT company or companies from the array\r\n1. Remove the last IT company from the array\r\n1. Remove all IT companies\r\n\r\n## More on Arrays\r\n\r\nThere are different methods to manipulate an array. These are some of the available methods to deal with arrays:_Array,length, concat, indexOf, slice, splice, join, toString, includes, lastIndexOf, isArray, fill, push, pop, shift, unshift_\r\nArray:To create an array.\r\n\r\n```js\r\nconst arr = Array(); // creates an an empty array\r\nconsole.log(arr);\r\n\r\nconst eightEmptyValues = Array(8); // it creates eight empty values\r\nconsole.log(eightEmptyValues); // [empty x 8]\r\n```\r\n\r\n- _fill_: Fill all the array elements with a static value\r\n\r\n```js\r\nconst arr = Array(); // creates an an empty array\r\nconsole.log(arr);\r\nconst eightXvalues = Array(8).fill(\"X\"); // it creates eight element values\r\nconsole.log(eightXvalues); // ['X', 'X','X','X','X','X','X','X']\r\n```\r\n\r\n- _concat_: To concaten","readmeFilename":"README.md"}