This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const btn = document.querySelector('.btn-get-post'); | |
| const btnAddPost = document.querySelector('.btn-add-post'); | |
| const container = document.querySelector('.container'); | |
| function getPost(cb) { | |
| const xhr = new XMLHttpRequest(); | |
| xhr.open('GET', 'https://jsonplaceholder.typicode.com/posts'); | |
| xhr.send(); | |
| xhr.addEventListener('load', () => { | |
| const responseJson = JSON.parse(xhr.responseText); | |
| cb(responseJson); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * @type {DocumentFragment} | |
| */ | |
| const fragment = document.createDocumentFragment(); | |
| const colors = ['tomato', 'orange', 'red', 'yellow']; | |
| const text = ['this is tomato', 'this is orange', 'this is red', 'this is yellow']; | |
| const styles = ['tomato', 'orange','red','yellow']; | |
| colors.forEach((value, index) => { | |
| const item = document.createElement('div'); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let str = 'i am in the easycode'; | |
| str.split(/\s+/).map((char) => char[0].toUpperCase() + char.substring(1)).join(' '); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Function array sum square | |
| * @param numbers | |
| * @returns {number} | |
| */ | |
| function squareSum(numbers) { | |
| let arrSum = numbers.map(value => value ** 2); | |
| let sum = 0; | |
| for (let i = 0; i < arrSum.length; i++) { | |
| sum += arrSum[i]; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Creat prototype for object STRING where first letter to upper case | |
| * | |
| * @returns {string} | |
| */ | |
| String.prototype.toJadenCase = function () { | |
| return this.replace(/( |^)[а-яёa-z]/gi, function (string) { | |
| return string.toUpperCase(); | |
| }); | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * | |
| * @param a = array | |
| * @param b = array | |
| * @returns {*[]} difference between a and b | |
| */ | |
| function arr_diff(a, b) { | |
| let aa = []; | |
| let bb = []; | |
| for (let i = 0; i < a.length; i++) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const btn = document.querySelector('.btn'); | |
| btn.addEventListener('click', function () { | |
| var req = new XMLHttpRequest(); | |
| var API_KEY = 'API_KEY'; | |
| // Сохраняем адрес API | |
| var url = 'https://translate.yandex.net/api/v1.5/tr.json/translate'; | |
| // Формируем полный адрес запроса: | |
| url += '?key=' + API_KEY; // добавляем к запросу ключ API | |
| url += '&text='; // текст для перевода |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const link = document.querySelector('.link'); | |
| link.addEventListener('click', function (ev) { | |
| ev.preventDefault(); | |
| console.log(ev.type); | |
| }); | |
| const textarea = document.querySelector('textarea'); | |
| const key = document.querySelector('.key'); | |
| textarea.addEventListener('keydown', function (ev) { | |
| if (ev.key === 'Enter') { | |
| ev.preventDefault(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| *XMLHttpRequest | |
| */ | |
| const request = new XMLHttpRequest(); | |
| request.open('Get', '/data.txt'); | |
| request.send(); | |
| request.onload = function () { | |
| console.log(request.responseText); | |
| }; | |
| /* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * The Constructor Of The Parent | |
| * @param firstName | |
| * @param lastName | |
| * @constructor | |
| */ | |
| function User(firstName, lastName) { | |
| //this = {} | |
| this.firstName = firstName; | |
| this.lastName = lastName; |