|
@@ -53,5 +53,214 @@ persons[3] = {
|
|
|
// }
|
|
|
// }
|
|
|
|
|
|
+//9task
|
|
|
+var personsJson = JSON.stringify(persons)
|
|
|
+console.log(personsJson)
|
|
|
+console.log(typeof personsJson)
|
|
|
|
|
|
+//10task
|
|
|
+var alesha = JSON.parse('{"name": "Alex", "surname": "Alekseev", "fathername": "Alekseevich", "age": 33, "sex": male}')
|
|
|
+persons.push(alesha)
|
|
|
+console.log(persons)
|
|
|
|
|
|
+//11task
|
|
|
+var table = "";
|
|
|
+table += '<table border = 1>'
|
|
|
+table += '\n\t<tr>'
|
|
|
+table += `\n\t\t<th>\n\t\t\tSurame\n\t\t</th>`
|
|
|
+table += `\n\t\t<th>\n\t\t\tName\n\t\t</th>`
|
|
|
+table += '</tr>'
|
|
|
+for (let i=0; i < persons.length; i++){
|
|
|
+ table += '\n\t<tr>'
|
|
|
+ table += `\n\t\t<td>\n\t\t\t${persons[i]["surname"]}\n\t\t</td>`
|
|
|
+ table += `\n\t\t<td>\n\t\t\t${persons[i]["name"]}\n\t\t</td>`
|
|
|
+ table += '</tr>'
|
|
|
+}
|
|
|
+table += '</table>'
|
|
|
+document.write(table)
|
|
|
+
|
|
|
+//12task
|
|
|
+var table = "";
|
|
|
+table += '<table border = 1>'
|
|
|
+for (let i=0; i < persons.length; i++){
|
|
|
+ table += '\n\t<tr>'
|
|
|
+ for (let key in persons[i]) {
|
|
|
+ table += `\n\t\t<td>\n\t\t\t${persons[i][key]}\n\t\t</td>`
|
|
|
+ }
|
|
|
+ table += '</tr>'
|
|
|
+}
|
|
|
+table += '</table>'
|
|
|
+document.write(table)
|
|
|
+
|
|
|
+//13task
|
|
|
+var table = "";
|
|
|
+table += '<table border = 1>'
|
|
|
+for (let i=0; i < persons.length; i++){
|
|
|
+ if (i%2) {
|
|
|
+ table += '\n\t<tr bgcolor="lightgrey">'
|
|
|
+ }
|
|
|
+ else {table += '\n\t<tr>'}
|
|
|
+ for (let key in persons[i]) {
|
|
|
+ table += `\n\t\t<td>\n\t\t\t${persons[i][key]}\n\t\t</td>`
|
|
|
+ }
|
|
|
+ table += '</tr>'
|
|
|
+}
|
|
|
+table += '</table>'
|
|
|
+document.write(table)
|
|
|
+
|
|
|
+//14task
|
|
|
+var table = "";
|
|
|
+table += '<table border = 1>'
|
|
|
+table += '\n\t<tr bgcolor="#90ee90">'
|
|
|
+for (let key in personsKeys){
|
|
|
+ table += `\n\t\t<th>\n\t\t\t${personsKeys[key]}\n\t\t</th>`
|
|
|
+}
|
|
|
+table += '</tr>'
|
|
|
+for (let i=0; i < persons.length; i++){
|
|
|
+ if (i%2) {
|
|
|
+ table += '\n\t<tr bgcolor="lightgrey">'
|
|
|
+ }
|
|
|
+ else {table += '\n\t<tr>'}
|
|
|
+ for (let key in personsKeys) {
|
|
|
+ if (personsKeys[key] in persons[i]) {
|
|
|
+ table += `\n\t\t<td>\n\t\t\t${persons[i][personsKeys[key]]}\n\t\t</td>`
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ table += `\n\t\t<td></td>`
|
|
|
+ }
|
|
|
+ }
|
|
|
+ table += '</tr>'
|
|
|
+}
|
|
|
+table += '</table>'
|
|
|
+document.write(table)
|
|
|
+
|
|
|
+//15task
|
|
|
+var someTree = {
|
|
|
+ tagName: "table",
|
|
|
+ subTags: [ //vlozhennie tegi
|
|
|
+ {
|
|
|
+ tagName: "tr",
|
|
|
+ subTags: [
|
|
|
+ {
|
|
|
+ tagName: "td",
|
|
|
+ text: "some text",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ tagName: "td",
|
|
|
+ text: "some text 2",
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ ],
|
|
|
+ attrs:
|
|
|
+ {
|
|
|
+ border: 1,
|
|
|
+ },
|
|
|
+}
|
|
|
+
|
|
|
+const createHtmlTree = function (objectHtml, tag, attr, content, children) { //object and standart names of keys
|
|
|
+ var strHtmlTree = "";
|
|
|
+ strHtmlTree += `<${objectHtml[tag]}`
|
|
|
+ if (attr in objectHtml) {
|
|
|
+ for (let key in objectHtml[attr]) {
|
|
|
+ strHtmlTree += ` ${key} = "${objectHtml[attr][key]}"`
|
|
|
+ }
|
|
|
+ }
|
|
|
+ strHtmlTree += `>`
|
|
|
+ if (content in objectHtml) {
|
|
|
+ strHtmlTree += objectHtml[content]
|
|
|
+ }
|
|
|
+ if (children in objectHtml) {
|
|
|
+ for (let i=0; i < objectHtml[children].length; i++) {
|
|
|
+ strHtmlTree += createHtmlTree(objectHtml[children][i], tag, attr, content, children)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (undefined !== objectHtml[content] || objectHtml[children].length > 0) {
|
|
|
+ strHtmlTree += `</${objectHtml[tag]}>`
|
|
|
+ }
|
|
|
+ return strHtmlTree;
|
|
|
+}
|
|
|
+
|
|
|
+document.write(createHtmlTree(someTree, "tagName", "attrs", "text", "subTags"))
|
|
|
+
|
|
|
+var body = {
|
|
|
+ name: 'body',
|
|
|
+ atr: {},
|
|
|
+ children: [
|
|
|
+ {
|
|
|
+ name: 'div',
|
|
|
+ atr: {},
|
|
|
+ children: [
|
|
|
+ {
|
|
|
+ name: 'span',
|
|
|
+ atr: {},
|
|
|
+ children: [],
|
|
|
+ content: "Enter a data please:"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: 'br',
|
|
|
+ atr: {},
|
|
|
+ children: [],
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: "input",
|
|
|
+ atr: {
|
|
|
+ id: "name",
|
|
|
+ type: "text"
|
|
|
+ },
|
|
|
+ children: []
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: "input",
|
|
|
+ atr: {
|
|
|
+ id: "surname",
|
|
|
+ type: "text"
|
|
|
+ },
|
|
|
+ children: []
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: 'div',
|
|
|
+ atr: {},
|
|
|
+ children: [
|
|
|
+ {
|
|
|
+ name: "button",
|
|
|
+ atr: {
|
|
|
+ id: "ok"
|
|
|
+ },
|
|
|
+ children: [],
|
|
|
+ content: "OK"
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: "button",
|
|
|
+ atr: {
|
|
|
+ id: "cancel"
|
|
|
+ },
|
|
|
+ children: [],
|
|
|
+ content: "Cancel"
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ ]
|
|
|
+}
|
|
|
+
|
|
|
+document.write(createHtmlTree(body, "name", "atr", "content", "children"))
|
|
|
+
|
|
|
+//black poyas
|
|
|
+var userHistory = "1111";
|
|
|
+var predictObject = {};
|
|
|
+
|
|
|
+for (let i = 0; i < 16; i++) {
|
|
|
+ predictObject[i.toString(2)] = Math.floor(Math.random()*2);
|
|
|
+}
|
|
|
+do {
|
|
|
+ var answer = (confirm("Хочешь поиграть в 'какой руке монета'? "))
|
|
|
+ let prediction = ((1 === predictObject[userHistory]) ? "монета в правой" : "монета в левой")
|
|
|
+ console.log(prediction)
|
|
|
+ userHistory += (predictObject[userHistory] = Number(confirm("Вы выбрали?")))
|
|
|
+ userHistory = userHistory.substring(1)
|
|
|
+
|
|
|
+ alert (`Ваша ${prediction} руке`)
|
|
|
+ var agree = confirm ("Я угадал")
|
|
|
+} while (agree !== true )
|