Mark пре 2 година
родитељ
комит
6447946b3c
1 измењених фајлова са 289 додато и 0 уклоњено
  1. 289 0
      05/main.js

+ 289 - 0
05/main.js

@@ -0,0 +1,289 @@
+// 3 persons///////////////////////////////
+var a = {
+   name: "Ivan",
+   surname: "Ivanov",
+}
+
+var b = {
+   name: "Petr",
+   surname: "Petrov",
+}
+
+var c = {
+   name: "Stepan",
+   surname: "Stepanov",
+}
+
+
+// different fields////////////////////////
+var a = {
+   name: "Ivan",
+   surname: "Ivanov",
+   sex: "male",
+}
+
+var b = {
+   name: "Petr",
+   surname: "Petrov",
+   fathername: "Petrovich",
+}
+
+var c = {
+   name: "Stepan",
+   surname: "Stepanov",
+   age: 33,
+}
+
+
+
+// fields check////////////////////////////
+var a = {
+   name: "Ivan",
+   surname: "Ivanov",
+   sex: "male",
+
+}
+var b = {
+   name: "Petr",
+   surname: "Petrov",
+   fathername: "Petrovich",
+}
+var c = {
+   name: "Stepan",
+   surname: "Stepanov",
+   age: 33,
+}
+if ('sex' in a) {
+   alert("found word in a!")
+}
+if ('fathername' in b) {
+   alert("found word in b!")
+}
+if (typeof { age: 33 } === 'object') { alert("found in c!") }
+
+
+
+// array of persons////////////////////////
+var a = {
+   name: "Ivan",
+   surname: "Ivanov",
+   sex: "male",
+
+}
+var b = {
+   name: "Petr",
+   surname: "Petrov",
+   fathername: "Petrovich",
+}
+var c = {
+   name: "Stepan",
+   surname: "Stepanov",
+   age: 33,
+}
+var persons = []
+persons.push(a, b, c, {
+   name: "Vasya", surname: "Vasiliev", fathername: "Vasilievich"
+})
+console.log(persons)
+
+
+
+// loop of persons//////////////////////////
+var a = {
+   name: "Ivan",
+   surname: "Ivanov",
+   sex: "male",
+
+}
+var b = {
+   name: "Petr",
+   surname: "Petrov",
+   fathername: "Petrovich",
+}
+var c = {
+   name: "Stepan",
+   surname: "Stepanov",
+   age: 33,
+}
+var persons = []
+persons.push(a, b, c, {
+   name: "Vasya", surname: "Vasiliev", fathername: "Vasilievich"
+})
+for (let i = 0; i < persons.length; i++) {
+   console.log(persons[i]);
+}
+
+
+
+// loop of name and surname//////////////////
+var a = {
+   name: "Ivan",
+   surname: "Ivanov",
+   sex: "male",
+
+}
+var b = {
+   name: "Petr",
+   surname: "Petrov",
+   fathername: "Petrovich",
+}
+var c = {
+   name: "Stepan",
+   surname: "Stepanov",
+   age: 33,
+}
+var persons = []
+persons.push(a, b, c, {
+   name: "Vasya", surname: "Vasiliev", fathername: "Vasilievich"
+})
+for (let i = 0; i < persons.length; i++) {
+   console.log(persons[i].name, persons[i].surname);
+}
+
+
+// loop of loop of values////////////////////
+var a = {
+   name: "Ivan",
+   surname: "Ivanov",
+   sex: "male",
+
+}
+var b = {
+   name: "Petr",
+   surname: "Petrov",
+   fathername: "Petrovich",
+}
+var c = {
+   name: "Stepan",
+   surname: "Stepanov",
+   age: 33,
+}
+var persons = []
+persons.push(a, b, c, {
+   name: "Vasya", surname: "Vasiliev", fathername: "Vasilievich"
+})
+for (let i = 0; i < persons.length; i++) {
+   for (let values in persons[i]) { console.log(persons[i][values]); }
+}
+
+
+// fullName///////////////////////////////////
+var a = {
+   name: "Ivan",
+   surname: "Ivanov",
+   sex: "male",
+
+}
+var b = {
+   name: "Petr",
+   surname: "Petrov",
+   fathername: "Petrovich",
+}
+var c = {
+   name: "Stepan",
+   surname: "Stepanov",
+   age: 33,
+}
+var persons = []
+persons.push(a, b, c, {
+   name: "Vasya", surname: "Vasiliev", fathername: "Vasilievich"
+})
+for (let i = 0; i < persons.length; i++) {
+   if (persons[i].name && persons[i].surname) {
+      persons[i].fullName = persons[i].name + " " + persons[i].surname;
+   }
+   else if (persons[i].fathername) { persons[i].fullName = persons[i].name + " " + persons[i].fathername + " " + persons[i].surname; }
+
+   console.log(persons[i].fullName)
+}
+
+
+// serialize//////////////////////////////////
+JSON.stringify(persons)
+
+
+// deserialize////////////////////////////////
+persons.push(JSON.parse('{"name":"Steve","surname":"Jobs","sex":"male"}'))
+console.log(persons)
+
+// HTML///////////////////////////////////////
+var str = "<table border='1'>\n"
+for (let i = 0; i < persons.length; i++) {
+
+   console.log(persons[i]);
+   str += `<tr><td>${persons[i].name}</td>\n
+   <td>${persons[i].surname}</td></tr>\n`
+}
+str += "</table>"
+
+console.log(str)
+document.write(str)
+
+// HTML optional fields///////////////////////
+// var a = {
+//    name: "Ivan",
+//    surname: "Ivanov",
+//    fathername: "Ivanovich",
+//    sex: "male",
+//    age: 33,
+// }
+// var b = {
+//    name: "Petr",
+//    surname: "Petrov",
+//    fathername: "Petrovich",
+//    sex: "male",
+//    age: 33,
+// }
+// var c = {
+//    name: "Stepan",
+//    surname: "Stepanov",
+//    fathername: "Stepanovich",
+//    sex: "male",
+//    age: 33,
+// }
+// var persons1 = []
+// persons1.push(a, b, c, {
+//    name: "Vasya", surname: "Vasiliev", fathername: "Vasilievich", sex: "male", age: 33,
+// })
+// for (let i = 0; i < persons1.length; i++) {
+//    console.log(persons1[i]);
+// }
+var str = "<table border='1'>"
+for (let i = 0; i < persons1.length; i++) {
+
+   console.log(persons1[i]);
+   str += `<tr><td>${persons1[i].name}</td><td>${persons1[i].surname}</td>
+   <td>${persons1[i].fathername}</td><td>${persons1[i].age}</td><td>${persons1[i].sex}</td></tr>`
+}
+str += "</table>"
+console.log(str)
+document.write(str)
+
+
+
+// HTML tr color//////////////////////////////
+var str = "<table border='1'>"
+for (let i = 0; i < persons1.length; i++) {
+   console.log(persons1[i]);
+   if (i % 2 === 0) {
+      str += `<tr style="background-color:maroon"><td>${persons1[i].name}</td><td>${persons1[i].surname}</td>
+   <td>${persons1[i].fathername}</td><td>${persons1[i].age}</td><td>${persons1[i].sex}</td></tr>`
+   }
+   else {
+      str += `<tr><td>${persons1[i].name}</td><td>${persons1[i].surname}</td>
+   <td>${persons1[i].fathername}</td><td>${persons1[i].age}</td><td>${persons1[i].sex}</td></tr>`
+   }
+}
+str += "</table>"
+console.log(str)
+document.write(str)
+
+
+// HTML th optional///////////////////////////
+
+
+
+
+
+
+