123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293 |
- <!DOCTYPE html>
- <html>
- <head>
- <meta charset="utf-8">
- <title></title>
- </head>
- <body>
- <div id="container"></div>
- <script>
- //----------3 persons --- different fields --- fields check
- /*let a={
- name:'John',
- surname:'Johnson'
- };
- let b={
- name:"Ivan",
- surname:"Ivanov"
- };
- let c={
- name:'Kevin',
- surname:"McKalister"
- };
- a.sex='man';
- a.age=17;
- b.fathername='Jonson';
- c.age=19;
- let key =prompt('','');
- if(key in a){
- alert(a[key]);
- }*/
- //----------array of persons
- /* let a={
- name:'John',
- surname:'Johnson'
- };
- let b={
- name:"Ivan",
- surname:"Ivanov"
- };
- let c={
- name:'Kevin',
- surname:"McKalister"
- };
- let persons=[a,b,c];
- persons.push({name:"Frank", surname:'Lampard'});
-
- //loop of persons
- for(let item of persons){
- console.log(item);
- }
- //loop of name and surname
- for(let item of persons){
- console.log(item.name+" "+item.surname);
- }
- //loop of loop of values
- for(let item of persons){
- for(let name of Object.values(item)){
- console.log(name);
- }
- }
- //fullName
- for(let item of persons){
- item.fullName=item.name+" "+item.surname;
- console.log(item.fullName);
- }
- console.log(persons);
- //serialize
- let json=JSON.stringify(persons,null,2);
- console.log(json);
- //deserialize
- let d=JSON.parse(json)[0];
- console.log(d);
- persons.push(d);
- console.log(persons);*/
-
- //----------HTML
- /*let str = "<table border='1'><tr><td>Имя</td><td>Фамилия</td></tr>";
- for (let i=0;i<persons.length;i++){
- let g=persons[i];
- str += `<tr><td>${g.name}</td><td>${g.surname}</td></tr>`;
- }
- str += "</table>";
- document.write(str);*/
- //----------HTML optional fields --- HTML tr color
- /*
- let str = "<table border='1'>";
- for (let i=0;i<persons.length;i++){
-
- let g=persons[i];
- if(i%2){
- str+="<tr bgcolor='yellow'>";
- }else{
- str+='<tr>';
- }
- for(let item in g){
- if(item){
- str+=`<td>${item}: ${g[item]}</td>`;
- }
- }
- str+='</tr>';
- }
- str += "</table>";
- document.write(str);*/
- //---------HTML th optional
- /*persons[2].age=19;
- persons[3].age=27;
- persons[3].sex='man';
- let keys=[];
- for(let item of persons){
- for(let i of Object.keys(item)){
- if(!keys.includes(i)){
- keys.push(i);
- }
- }
- }
- console.log(keys);
- let str = "<table border='1'><tr>";
- for(let i of keys){
- str+=`<th>${i}</th>`;
- }
- str+='</tr>';
- for(let item of persons){
- str+='<tr>';
- for(let it in item){
- for(let i=0;i<keys.length;i++){
- if(keys[i]==it){
- str+=`<td bgcolor='yellow'>${item[it]}</td>`;
- }
- }
- }
- str+='</tr>';
- }
- document.write(str);*/
- //----------Blue belt
- //появляется ячейка table -> {tbody}? -> tr -> td
- var someTree = {
- tagName: "table",
- subTags: [
- {
- tagName: "tr",
- subTags: [
- {
- tagName: "td",
- text: "some text",
- },
- {
- tagName: "td",
- text: "some text 2",
- }
- ]
- }
- ],
- attrs: {
- border: 1,
- },
- }
- let str='';
- for(let item in someTree){
- if(item=='tagName'){
- let [key] = Object.keys(someTree['attrs']);
- let [value]= Object.values(someTree['attrs']);
- str+=`<${someTree['tagName']} ${key}=${value}>`;
- }
-
- if(item=='subTags'){
- for(let item2 of someTree[item]){
- for(let item3 in item2){
- // str+=`<${item2['tagName']}>`;
- if(item3=='subTags'){
- for(let item4 of item2['subTags']){
- console.log(item4);
- for(let item5 in item4){
- if(item5=='tagName'){
- str+=`<${item4['tagName']}>${item4['text']}</${item4['tagName']}>`;
- }
- }
- }
- }
- }
- }
- }
-
- }
- document.write(str);
- //------destruct array
- //четные числав переменные even1, even2
- /*let arr=[1,2,3,4,5,'a','b','c'];
- for(let i=0; i<arr.length; i++) {
- for(let j=0; j<arr.length; j++ ){
- if(arr[j]%2 === 1){
- arr.splice(j,1)
- break;
- }
- }
- };
- let [even1,even2]=arr;
- console.log(arr);
- console.log(even1+" : "+even2); */
- //нечетные в odd1, odd2, odd3
- /*let arr2=[1,2,3,4,5,'a','b','c'];
- let [odd1,odd2,odd3]=arr2.filter(x=>x%2);
- console.log(odd1+" : "+odd2+' : '+odd3);*/
- //буквы в отдельный массив
- /*let arr3=arr2.filter(function(x){
- if(!Number(x)){
- return x;
- }
- });
- console.log(arr3);*/
- //------destruct string
- //число в переменную number
- /*let arr=[1,'abc'];
- let [number]=arr;
- console.log(number);*/
- //букву а в переменную s1
- //букву b в переменную s2
- //букву с в переменную s3
- /*let [s1,s2,s3]=[...arr[1]];
- console.log(s1+" : "+s2+" : "+s3);*/
- //------destruct 2
- /*let obj = {
- name: 'Ivan',
- surname: 'Petrov',
- children: [
- {
- name: 'Maria'
- },
- {
- name: 'Nikolay'
- }
- ]
- };
- let {children:[{name:name1},{name:name2}]}=obj;
- console.log(name1 + " : "+name2);*/
- //------destruct 3
- /*let arr = [1,2,3,4,5,6,7,10];
- let [a,b]=arr;
- let {length}=arr;
- console.log(a+' : '+b+' : '+length);*/
-
- //------Black belt
- //in process
-
-
-
-
-
- </script>
- </body>
- </html>
|