|
@@ -0,0 +1,301 @@
|
|
|
+// Task 3 persons
|
|
|
+let a = {
|
|
|
+ name: "Vika",
|
|
|
+ surname: "Yurchenko",
|
|
|
+};
|
|
|
+let b = {
|
|
|
+ name: "Ivan",
|
|
|
+ surname: "Ivanov",
|
|
|
+};
|
|
|
+let c = {
|
|
|
+ name: "Petro",
|
|
|
+ surname: "Petrov",
|
|
|
+};
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+// Task different fields
|
|
|
+a.age = "15";
|
|
|
+b.fathername = "Petrovna";
|
|
|
+c.sex = "m";
|
|
|
+
|
|
|
+
|
|
|
+//Task fields check
|
|
|
+// let result = typeof(a.key);
|
|
|
+// alert(result);
|
|
|
+
|
|
|
+// if ('key' in a) {
|
|
|
+// alert('yes');
|
|
|
+// };
|
|
|
+
|
|
|
+
|
|
|
+//Task array of persons
|
|
|
+let persons = [{name: "Dima", surname: "Dimon"}];
|
|
|
+persons.push(a, b, c);
|
|
|
+
|
|
|
+
|
|
|
+//Task loop of persons
|
|
|
+// for (let i = 0; i < persons.length; i++) {
|
|
|
+// console.log(persons[i]);
|
|
|
+// };
|
|
|
+
|
|
|
+
|
|
|
+//Task loop of name and surname
|
|
|
+// for (let i = 0; i < persons.length; i++) {
|
|
|
+// let name = persons[i].name;
|
|
|
+// let surname = persons[i].surname;
|
|
|
+// console.log( name, surname);
|
|
|
+// };
|
|
|
+
|
|
|
+
|
|
|
+//Task loop of loop of values
|
|
|
+
|
|
|
+// for (let i = 0; i < persons.length; i++) {
|
|
|
+// let vallues = persons[i];
|
|
|
+// for (key in persons[i] ) { c
|
|
|
+// console.log(persons[i][key]);
|
|
|
+// };
|
|
|
+// };
|
|
|
+
|
|
|
+
|
|
|
+// Task fullName
|
|
|
+// for (let i = 0; i < persons.length; i++ ) {
|
|
|
+// if (persons[i].name && persons[i].surname) {
|
|
|
+// persons[i].fullName = '';
|
|
|
+// };
|
|
|
+// };
|
|
|
+// console.log(persons);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+//Task serialize
|
|
|
+// let stringJson = JSON.stringify(persons);
|
|
|
+// console.log(stringJson);
|
|
|
+
|
|
|
+
|
|
|
+//Task deserialize
|
|
|
+// let strJson = '{"name": "Vova", "surname": "Vovanov"}';
|
|
|
+// persons.push( JSON.parse(strJson) );
|
|
|
+// console.log(persons);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+//Task HTML
|
|
|
+// var str = "<table border='1'>"
|
|
|
+// for (let i=0;i < persons.length; i++){
|
|
|
+// str += '<tr>';
|
|
|
+// for (key in persons[i]) {
|
|
|
+// str += `<th> ${key}<th> <th> ${persons[i][key]} </th>`;
|
|
|
+// };
|
|
|
+// str +='</tr>' ;
|
|
|
+// };
|
|
|
+// str += "</table>"
|
|
|
+
|
|
|
+// console.log(str);
|
|
|
+// document.write(str);
|
|
|
+
|
|
|
+
|
|
|
+// Task HTML tr color
|
|
|
+// var str = "<table border='1'>"
|
|
|
+// for (let i=0;i < persons.length; i++){
|
|
|
+// let tr = '<tr>';
|
|
|
+// if (i % 2 == 0) {
|
|
|
+// tr = '<tr style="background-color: red">';
|
|
|
+// str += tr;
|
|
|
+// };
|
|
|
+// if (i % 2 != 0 ) {
|
|
|
+// str += tr;
|
|
|
+// };
|
|
|
+// for (key in persons[i]) {
|
|
|
+// str += `<th> ${key}<th> <th> ${persons[i][key]} </th>`;
|
|
|
+// };
|
|
|
+// str += '</tr>';
|
|
|
+// };
|
|
|
+// str += "</table>"
|
|
|
+
|
|
|
+// console.log(str);
|
|
|
+// document.write(str);
|
|
|
+
|
|
|
+
|
|
|
+//Task HTML th optional
|
|
|
+// let str = "<table border='1'>";
|
|
|
+// let tr = '<tr>';
|
|
|
+// let property = [];
|
|
|
+
|
|
|
+// for (let i = 0; i < persons.length; i++ ) {
|
|
|
+// for (key in persons[i]) {
|
|
|
+// property.push(key);
|
|
|
+// };
|
|
|
+// };console.log(property);
|
|
|
+
|
|
|
+// let propertyFiltr = property.filter(function(item, pos) {
|
|
|
+// return property.indexOf(item) == pos;
|
|
|
+// }); console.log(propertyFiltr);
|
|
|
+
|
|
|
+// str += tr;
|
|
|
+
|
|
|
+// for (let i = 0; i < propertyFiltr.length; i++){
|
|
|
+// str += `<th> ${propertyFiltr[i]} </th>`;
|
|
|
+// };
|
|
|
+// str +='</tr>';
|
|
|
+
|
|
|
+// for (let i = 0; i < persons.length; i++) {
|
|
|
+// str += tr;
|
|
|
+// for (let q = 0; q < propertyFiltr.length; q++) {
|
|
|
+
|
|
|
+// if(persons[i][propertyFiltr[q]] != undefined) {
|
|
|
+// str += `<td> ${persons[i][propertyFiltr[q]]} </td>`;
|
|
|
+// };
|
|
|
+// if(persons[i][propertyFiltr[q]] == undefined) {
|
|
|
+// str += `<td> - </td>`;
|
|
|
+// };
|
|
|
+
|
|
|
+// };
|
|
|
+// str += '</tr>';
|
|
|
+// };
|
|
|
+// str += "</table>";
|
|
|
+
|
|
|
+// console.log(str);
|
|
|
+// document.write(str);
|
|
|
+
|
|
|
+
|
|
|
+//Task Задание на синий пояс.
|
|
|
+// function changeObjInHtmlTree (obj) {
|
|
|
+// let str = '';
|
|
|
+// let {tagName, subTags, text, attrs} = obj;
|
|
|
+
|
|
|
+// str += `<${tagName} `;
|
|
|
+
|
|
|
+// if (attrs){
|
|
|
+// for (let [key, value] of Object.entries(attrs)){
|
|
|
+// str += `${key} = ${value}`;
|
|
|
+// };
|
|
|
+// };
|
|
|
+
|
|
|
+// str += `>`;
|
|
|
+
|
|
|
+// if (text) {
|
|
|
+// str += `${text}`;
|
|
|
+// };
|
|
|
+
|
|
|
+// if (subTags) {
|
|
|
+// let children = subTags;
|
|
|
+
|
|
|
+// for (let i = 0; i < children.length; i++) {
|
|
|
+
|
|
|
+// let {tagName, subTags, text, attrs} = children[i];
|
|
|
+// str += `<${tagName}`;
|
|
|
+
|
|
|
+// if (attrs){
|
|
|
+// for (let [key, value] of Object.entries(attrs)){
|
|
|
+// str += `${key} = ${value}`;
|
|
|
+// };
|
|
|
+// };
|
|
|
+
|
|
|
+// if (text) {
|
|
|
+// str += `${text}`;
|
|
|
+// };
|
|
|
+// str += `>`;
|
|
|
+
|
|
|
+// if (subTags) {
|
|
|
+// let children1 = subTags;
|
|
|
+
|
|
|
+// for (let q = 0; q < children1.length; q++){
|
|
|
+// let {tagName, subTags, text, attrs} = children1[q];
|
|
|
+// str += `<${tagName}> `;
|
|
|
+
|
|
|
+// if (attrs){
|
|
|
+// for (let [key, value] of Object.entries(attrs)){
|
|
|
+// str += `${key} = ${value}`;
|
|
|
+// };
|
|
|
+// };
|
|
|
+
|
|
|
+// if (text) {
|
|
|
+// str += `${text}`;
|
|
|
+// };
|
|
|
+
|
|
|
+// str += `</${tagName}>\n`;
|
|
|
+// };
|
|
|
+// str += `</${tagName}>\n`;
|
|
|
+// };
|
|
|
+// };
|
|
|
+// };
|
|
|
+// str += `</${tagName}>`;
|
|
|
+// return (console.log(str));
|
|
|
+// };
|
|
|
+
|
|
|
+// var someTree = {
|
|
|
+// tagName: "table", //html tag
|
|
|
+// subTags: [ //вложенные тэги
|
|
|
+// {
|
|
|
+// tagName: "tr",
|
|
|
+// subTags: [
|
|
|
+// {
|
|
|
+// tagName: "td",
|
|
|
+// text: "some text",
|
|
|
+// },
|
|
|
+// {
|
|
|
+// tagName: "td",
|
|
|
+// text: "some text 2",
|
|
|
+// }
|
|
|
+// ]
|
|
|
+// }
|
|
|
+// ],
|
|
|
+// attrs:
|
|
|
+// {
|
|
|
+// border: 1,
|
|
|
+// },
|
|
|
+// };
|
|
|
+
|
|
|
+// changeObjInHtmlTree(someTree);
|
|
|
+
|
|
|
+
|
|
|
+//Task destruct array
|
|
|
+// let arr = [1,2,3,4,5, "a", "b", "c"];
|
|
|
+// let [ odd1, even1, odd2, even2, odd3, ...arr1] = arr;
|
|
|
+
|
|
|
+
|
|
|
+//Task destruct string
|
|
|
+// let arr = [1, "abc"];
|
|
|
+// let [number, [s1, s2, s3] ] = arr;
|
|
|
+
|
|
|
+
|
|
|
+//Task destruct 2
|
|
|
+// let obj = {name: 'Ivan',
|
|
|
+// surname: 'Petrov',
|
|
|
+// children: [{name: 'Maria'}, {name: 'Nikolay'}]}
|
|
|
+
|
|
|
+// let {name, surname, children: [{name: name1}, {name: name2} ]} = obj;
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+//Task destruct 3
|
|
|
+// let arr = [1,2,3,4, 5,6,7,10];
|
|
|
+//let {length} = arr;
|
|
|
+// let {0:n, 1:m, length} = arr; //a, b has already been declared
|
|
|
+
|
|
|
+
|
|
|
+//Task Задание на черный пояс
|
|
|
+
|
|
|
+// let history = "1212";
|
|
|
+// let newValue = '1';
|
|
|
+// let predictArray = {};
|
|
|
+
|
|
|
+// for (let i = 0; newValue !== null; i++) {
|
|
|
+
|
|
|
+// let predictValue = predictArray[history];
|
|
|
+
|
|
|
+// newValue = prompt('Enter number 1 or 2');
|
|
|
+
|
|
|
+
|
|
|
+// if (!(predictArray.hasOwnProperty(history))) {
|
|
|
+// predictArray[history] = newValue;
|
|
|
+// predictValue = Math.round( Math.random() * 2);
|
|
|
+// };
|
|
|
+
|
|
|
+// history += newValue;
|
|
|
+// history = history.substring(1);
|
|
|
+
|
|
|
+
|
|
|
+// newValue == predictValue ? alert('You are not winner') : alert('you guessed');
|
|
|
+// };
|