|
@@ -1,324 +1,332 @@
|
|
|
"use strict";
|
|
|
|
|
|
-//*TODO: html tree
|
|
|
-// let body = {
|
|
|
-// tagName: 'body',
|
|
|
-// subTags: [{
|
|
|
-// tagName: 'div',
|
|
|
-// subTags: [{
|
|
|
-// tagName: "span",
|
|
|
-// text: "Enter a data please:",
|
|
|
-// },
|
|
|
-// {
|
|
|
-// tagName: "input",
|
|
|
-// attrs: {
|
|
|
-// type: "text",
|
|
|
-// id: "name",
|
|
|
-// },
|
|
|
-// },
|
|
|
-// {
|
|
|
-// tagName: "input",
|
|
|
-// attrs: {
|
|
|
-// type: "text",
|
|
|
-// id: "surname",
|
|
|
-// },
|
|
|
-// },
|
|
|
-// ]
|
|
|
-// },
|
|
|
-// {
|
|
|
-// tagName: 'div',
|
|
|
-// subTags: [{
|
|
|
-// tagName: "button",
|
|
|
-// text: "OK",
|
|
|
-// attrs: {
|
|
|
-// id: "ok",
|
|
|
-// },
|
|
|
-// },
|
|
|
-// {
|
|
|
-// tagName: "button",
|
|
|
-// text: "Cancel",
|
|
|
-// attrs: {
|
|
|
-// id: "cancel",
|
|
|
-// },
|
|
|
-// },
|
|
|
-// ]
|
|
|
-// }
|
|
|
-// ]
|
|
|
-// }
|
|
|
-
|
|
|
-// console.log(body.subTags[1].subTags[1].text);
|
|
|
-// console.log(body.subTags[0].subTags[2].attrs.id);
|
|
|
-
|
|
|
-
|
|
|
-//*TODO: declarative fields
|
|
|
-// let notebook = {
|
|
|
-// brand: prompt("Enter a brand your notebook","HP"),
|
|
|
-// type: prompt("Enter a type your notebook","440 G4"),
|
|
|
-// model: prompt("Enter a model your notebook","Y7Z75EA"),
|
|
|
-// ram: +prompt("Enter a ram your notebook","4"),
|
|
|
-// size: prompt("Enter a size your notebook","14"),
|
|
|
-// weight: +prompt("Enter a weight your notebook","1.8,"),
|
|
|
-// resolution: {
|
|
|
-// width: +prompt("Enter a screen width in px","1920"),
|
|
|
-// height: +prompt("Enter a screen height in px","1080"),
|
|
|
-// },
|
|
|
-// owner: prompt("Enter the owner of the notebook","Alex"),
|
|
|
-// };
|
|
|
-
|
|
|
-// let phone = {
|
|
|
-// brand: prompt("Enter a brand your phone","meizu"),
|
|
|
-// model: prompt("Enter a model your phone","m2"),
|
|
|
-// ram: +prompt("Enter a ram your phone","2"),
|
|
|
-// color: prompt("Enter a color your phone","black"),
|
|
|
-// owner: prompt("Enter the owner of the phone","Kate"),
|
|
|
-// };
|
|
|
-
|
|
|
-// let person = {
|
|
|
-// name: prompt("Enter a your name","Donald"),
|
|
|
-// surname: prompt("Enter a your surname","Trump"),
|
|
|
-// married: confirm("Are you married?"),
|
|
|
-// smartphone: confirm("Do you have a smartphone?"),
|
|
|
-// laptop: confirm("Do you have a laptop?"),
|
|
|
-// }
|
|
|
-
|
|
|
-
|
|
|
-//*TODO: object links
|
|
|
-// person.smartphone = notebook;
|
|
|
-// notebook.owner = person;
|
|
|
-// person.laptop = phone;
|
|
|
-// phone.owner = person;
|
|
|
-
|
|
|
-// console.log(person.smartphone.owner.laptop.owner.smartphone == person.smartphone)
|
|
|
-
|
|
|
-
|
|
|
-//*TODO: imperative array fill 3
|
|
|
-// let arr = [];
|
|
|
-
|
|
|
-// for (let i = 0; i < 3; i++) {
|
|
|
-// let userAnswer = prompt("Напиши 3 своих любимых сериала", "");
|
|
|
-// arr.push(userAnswer);
|
|
|
-// }
|
|
|
-// console.log(arr);
|
|
|
-
|
|
|
-
|
|
|
-//*TODO: while confirm
|
|
|
-// while(confirm("Hi") == false) {
|
|
|
-
|
|
|
-// if (confirm("Hi") !== false) {
|
|
|
-// break;
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
-
|
|
|
-//*TODO: array fill
|
|
|
-// let arr = [];
|
|
|
-
|
|
|
-// while(true) {
|
|
|
-// let userAnswer = prompt("Перечисли свои любимые фильмы", "");
|
|
|
-
|
|
|
-// if(isNaN(userAnswer)) {
|
|
|
-// arr.push(userAnswer);
|
|
|
-// };
|
|
|
-
|
|
|
-// if (userAnswer == null) {
|
|
|
-// break;
|
|
|
-// }
|
|
|
-// }
|
|
|
-// console.log(arr);
|
|
|
-
|
|
|
-
|
|
|
-//*TODO: array fill nopush
|
|
|
-// let arr = [];
|
|
|
-// let i = 0;
|
|
|
-
|
|
|
-// while(true) {
|
|
|
-// let userAnswer = prompt("Перечисли свои любимые фильмы", "");
|
|
|
-
|
|
|
-// if(isNaN(userAnswer)) {
|
|
|
-// arr[i] = userAnswer;
|
|
|
-// }
|
|
|
-
|
|
|
-// if (userAnswer == null) {
|
|
|
-// break;
|
|
|
-// }
|
|
|
-// i++;
|
|
|
-// }
|
|
|
-// console.log(arr);
|
|
|
-
|
|
|
-
|
|
|
-//*TODO: infinite probability
|
|
|
-// let i = 0;
|
|
|
-// let randomNumber = 0;
|
|
|
-// while(true) {
|
|
|
-// randomNumber = Math.random(i);
|
|
|
-
|
|
|
-// if (randomNumber > 0.9) {
|
|
|
-// break;
|
|
|
-// }
|
|
|
-// i++;
|
|
|
-// console.log(randomNumber);
|
|
|
-// }
|
|
|
-
|
|
|
-// alert(i);
|
|
|
-
|
|
|
-
|
|
|
-//*TODO: empty loop
|
|
|
-// while(prompt() === null) {
|
|
|
-// }
|
|
|
-
|
|
|
-
|
|
|
-//*TODO: progression sum
|
|
|
-// let userNumber = prompt("Введите число", "");
|
|
|
-// let progressionSum = 0;
|
|
|
-// for (let i = 0; i < userNumber; i++) {
|
|
|
-// console.log(i);
|
|
|
-// progressionSum = progressionSum + (1 + (i * 3));
|
|
|
-// }
|
|
|
-
|
|
|
-// console.log(progressionSum);
|
|
|
-
|
|
|
-
|
|
|
-//*TODO: chess one line
|
|
|
-// let str = "";
|
|
|
-// for (let i = 0; i < 5; i++) {
|
|
|
-// str += "# ";
|
|
|
-// }
|
|
|
-// console.log(str);
|
|
|
-
|
|
|
-
|
|
|
-//*TODO: numbers
|
|
|
-// let str = "";
|
|
|
-
|
|
|
-// for (let a = 0; a < 10; a++) {
|
|
|
-// for (let i = 0; i < 10; i++) {
|
|
|
-// str += i;
|
|
|
-// }
|
|
|
-// str += "\n";
|
|
|
-// }
|
|
|
-
|
|
|
-// console.log(str);
|
|
|
-
|
|
|
-
|
|
|
-//*TODO: chess
|
|
|
-// let str = "";
|
|
|
-
|
|
|
-// for (let i = 0; i < 10; i++) {
|
|
|
-// for (let x = 0; x < 10; x++) {
|
|
|
-// if ((x + i) % 2 == 0)
|
|
|
-// str += ". ";
|
|
|
-// else
|
|
|
-// str += "# ";
|
|
|
-// }
|
|
|
-// str += "\n";
|
|
|
-// }
|
|
|
-
|
|
|
-// console.log(str);
|
|
|
-
|
|
|
-
|
|
|
-//*TODO: cubes
|
|
|
-// let arr = [0, 1, 2, 5, 10];
|
|
|
-
|
|
|
-// let num = 0;
|
|
|
-// let arrMode = [];
|
|
|
-// for (let key of arr) {
|
|
|
-// let cube = num * num * num;
|
|
|
-// arrMode.push(cube);
|
|
|
-// num++;
|
|
|
-// }
|
|
|
-
|
|
|
-// console.log(arrMode)
|
|
|
-
|
|
|
-
|
|
|
-//*TODO: multiply table
|
|
|
-// let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
|
|
-// let arrMode = [];
|
|
|
-
|
|
|
-// for (let keyN of arr) {
|
|
|
-// arrMode[keyN] = [];
|
|
|
-// for (let keyM of arr) {
|
|
|
-// arrMode[keyN][keyM] = (keyN * keyM);
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
-// console.log(arrMode[7][2])
|
|
|
-
|
|
|
-
|
|
|
-//*TODO: matrix to html table
|
|
|
-// let tab = document.getElementById("table");
|
|
|
-
|
|
|
-// let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
|
|
-// let arrMode = [];
|
|
|
-// let html = "<table>";
|
|
|
-// for (let keyN of arr) {
|
|
|
-// arrMode[keyN] = [];
|
|
|
-// for (let keyM of arr) {
|
|
|
-// arrMode[keyN][keyM] = (keyN * keyM);
|
|
|
-// html +=
|
|
|
-// `<tr>
|
|
|
-// <td>${keyN}</td>
|
|
|
-// <td>${keyM}</td>
|
|
|
-// <td>${keyN * keyM}</td>
|
|
|
-// </tr>`
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
-// html += "</table>";
|
|
|
-// tab.innerHTML = html;
|
|
|
-
|
|
|
-
|
|
|
-//*TODO: Задание на синий пояс: Треугольник
|
|
|
-// let i = 0,
|
|
|
-// j = 0;
|
|
|
-
|
|
|
-// let dot = "",
|
|
|
-// grid = "";
|
|
|
-
|
|
|
-// while (i < 5) {
|
|
|
-// dot = "";
|
|
|
-// grid = "";
|
|
|
-// for (j = 1; j < 5 - i; j++) {
|
|
|
-// dot += ". ";
|
|
|
-// }
|
|
|
-
|
|
|
-// for (j = 0; j < 2 * i + 1; j++) {
|
|
|
-// grid += "# ";
|
|
|
-// }
|
|
|
-// console.log(dot + grid + dot);
|
|
|
-// i++;
|
|
|
-// }
|
|
|
-
|
|
|
-
|
|
|
-//*TODO: Задание на черный пояс: Электронная гадалка
|
|
|
-// let userNumber;
|
|
|
-// let prediction = [];
|
|
|
-// let historySize = 4;
|
|
|
-
|
|
|
-// for (let i = 1; i <= 5; i++) {
|
|
|
-// if (prediction.length < historySize) {
|
|
|
-// console.log("prediction = RANDOM " + Math.round(Math.random()));
|
|
|
-// userNumber = +prompt("Введите число", "");
|
|
|
-// prediction.push(userNumber);
|
|
|
-// } else {
|
|
|
-// console.log("prediction = HISTORY " + prediction[0]);
|
|
|
-// userNumber = +prompt("Введите число", "");
|
|
|
-// prediction.push(userNumber);
|
|
|
-// prediction.shift();
|
|
|
-// }
|
|
|
-// }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+function htmlTree() {
|
|
|
+ let body = {
|
|
|
+ tagName: 'body',
|
|
|
+ subTags: [{
|
|
|
+ tagName: 'div',
|
|
|
+ subTags: [{
|
|
|
+ tagName: "span",
|
|
|
+ text: "Enter a data please:",
|
|
|
+ },
|
|
|
+ {
|
|
|
+ tagName: "input",
|
|
|
+ attrs: {
|
|
|
+ type: "text",
|
|
|
+ id: "name",
|
|
|
+ },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ tagName: "input",
|
|
|
+ attrs: {
|
|
|
+ type: "text",
|
|
|
+ id: "surname",
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ]
|
|
|
+ },
|
|
|
+ {
|
|
|
+ tagName: 'div',
|
|
|
+ subTags: [{
|
|
|
+ tagName: "button",
|
|
|
+ text: "OK",
|
|
|
+ attrs: {
|
|
|
+ id: "ok",
|
|
|
+ },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ tagName: "button",
|
|
|
+ text: "Cancel",
|
|
|
+ attrs: {
|
|
|
+ id: "cancel",
|
|
|
+ },
|
|
|
+ },
|
|
|
+ ]
|
|
|
+ }
|
|
|
+ ]
|
|
|
+ }
|
|
|
+
|
|
|
+ console.log(body.subTags[1].subTags[1].text);
|
|
|
+ console.log(body.subTags[0].subTags[2].attrs.id);
|
|
|
+}
|
|
|
+// htmlTree()
|
|
|
+
|
|
|
+
|
|
|
+function declarativeFields() {
|
|
|
+ let notebook = {
|
|
|
+ brand: prompt("Enter a brand your notebook", "HP"),
|
|
|
+ type: prompt("Enter a type your notebook", "440 G4"),
|
|
|
+ model: prompt("Enter a model your notebook", "Y7Z75EA"),
|
|
|
+ ram: +prompt("Enter a ram your notebook", "4"),
|
|
|
+ size: prompt("Enter a size your notebook", "14"),
|
|
|
+ weight: +prompt("Enter a weight your notebook", "1.8,"),
|
|
|
+ resolution: {
|
|
|
+ width: +prompt("Enter a screen width in px", "1920"),
|
|
|
+ height: +prompt("Enter a screen height in px", "1080"),
|
|
|
+ },
|
|
|
+ owner: prompt("Enter the owner of the notebook", "Alex"),
|
|
|
+ };
|
|
|
+
|
|
|
+ let phone = {
|
|
|
+ brand: prompt("Enter a brand your phone", "meizu"),
|
|
|
+ model: prompt("Enter a model your phone", "m2"),
|
|
|
+ ram: +prompt("Enter a ram your phone", "2"),
|
|
|
+ color: prompt("Enter a color your phone", "black"),
|
|
|
+ owner: prompt("Enter the owner of the phone", "Kate"),
|
|
|
+ };
|
|
|
+
|
|
|
+ let person = {
|
|
|
+ name: prompt("Enter a your name", "Donald"),
|
|
|
+ surname: prompt("Enter a your surname", "Trump"),
|
|
|
+ married: confirm("Are you married?"),
|
|
|
+ smartphone: confirm("Do you have a smartphone?"),
|
|
|
+ laptop: confirm("Do you have a laptop?"),
|
|
|
+ }
|
|
|
+
|
|
|
+ person.smartphone = notebook;
|
|
|
+ notebook.owner = person;
|
|
|
+ person.laptop = phone;
|
|
|
+ phone.owner = person;
|
|
|
+
|
|
|
+ console.log(person.smartphone.owner.laptop.owner.smartphone == person.smartphone)
|
|
|
+}
|
|
|
+// declarativeFields()
|
|
|
+
|
|
|
+
|
|
|
+function imperativeArray() {
|
|
|
+ let arr = [];
|
|
|
+
|
|
|
+ for (let i = 0; i < 3; i++) {
|
|
|
+ let userAnswer = prompt("Напиши 3 своих любимых сериала", "");
|
|
|
+ arr.push(userAnswer);
|
|
|
+ }
|
|
|
+ console.log(arr);
|
|
|
+}
|
|
|
+// imperativeArray()
|
|
|
+
|
|
|
+
|
|
|
+function whileConfirm() {
|
|
|
+ while (confirm("Hi") == false) {
|
|
|
+
|
|
|
+ if (confirm("Hi") !== false) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+// whileConfirm()
|
|
|
+
|
|
|
+
|
|
|
+function arrayFill() {
|
|
|
+ let arr = [];
|
|
|
+
|
|
|
+ while (true) {
|
|
|
+ let userAnswer = prompt("Перечисли свои любимые фильмы", "");
|
|
|
+
|
|
|
+ if (isNaN(userAnswer)) {
|
|
|
+ arr.push(userAnswer);
|
|
|
+ };
|
|
|
+
|
|
|
+ if (userAnswer == null) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ console.log(arr);
|
|
|
+}
|
|
|
+// arrayFill()
|
|
|
+
|
|
|
+
|
|
|
+function arrayFillNopush() {
|
|
|
+ let arr = [];
|
|
|
+ let i = 0;
|
|
|
+
|
|
|
+ while (true) {
|
|
|
+ let userAnswer = prompt("Перечисли свои любимые фильмы", "");
|
|
|
+
|
|
|
+ if (isNaN(userAnswer)) {
|
|
|
+ arr[i] = userAnswer;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (userAnswer == null) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ console.log(arr);
|
|
|
+}
|
|
|
+// arrayFillNopush()
|
|
|
+
|
|
|
+
|
|
|
+function infiniteProbability() {
|
|
|
+ let i = 0;
|
|
|
+ let randomNumber = 0;
|
|
|
+ while (true) {
|
|
|
+ randomNumber = Math.random(i);
|
|
|
+
|
|
|
+ if (randomNumber > 0.9) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ i++;
|
|
|
+ console.log(randomNumber);
|
|
|
+ }
|
|
|
+
|
|
|
+ alert(i);
|
|
|
+}
|
|
|
+// infiniteProbability()
|
|
|
+
|
|
|
+
|
|
|
+function emptyLoop() {
|
|
|
+ while (prompt() === null) {}
|
|
|
+}
|
|
|
+// emptyLoop()
|
|
|
+
|
|
|
+
|
|
|
+function progressionSum() {
|
|
|
+ let userNumber = prompt("Введите число", "");
|
|
|
+ let progressionSum = 0;
|
|
|
+ for (let i = 0; i < userNumber; i++) {
|
|
|
+ progressionSum = progressionSum + (1 + (i * 3));
|
|
|
+ }
|
|
|
+ console.log(progressionSum);
|
|
|
+}
|
|
|
+// progressionSum()
|
|
|
+
|
|
|
+
|
|
|
+function chessOneLine() {
|
|
|
+ let str = "";
|
|
|
+ for (let i = 0; i < 5; i++) {
|
|
|
+ str += "# ";
|
|
|
+ }
|
|
|
+ console.log(str);
|
|
|
+}
|
|
|
+// chessOneLine()
|
|
|
+
|
|
|
+
|
|
|
+function numbers() {
|
|
|
+ let str = "";
|
|
|
+
|
|
|
+ for (let a = 0; a < 10; a++) {
|
|
|
+ for (let i = 0; i < 10; i++) {
|
|
|
+ str += i;
|
|
|
+ }
|
|
|
+ str += "\n";
|
|
|
+ }
|
|
|
+ console.log(str);
|
|
|
+}
|
|
|
+// numbers()
|
|
|
+
|
|
|
+
|
|
|
+function chess() {
|
|
|
+ let str = "";
|
|
|
+
|
|
|
+ for (let i = 0; i < 10; i++) {
|
|
|
+ for (let x = 0; x < 10; x++) {
|
|
|
+ if ((x + i) % 2 == 0)
|
|
|
+ str += ". ";
|
|
|
+ else
|
|
|
+ str += "# ";
|
|
|
+ }
|
|
|
+ str += "\n";
|
|
|
+ }
|
|
|
+ console.log(str);
|
|
|
+}
|
|
|
+// chess()
|
|
|
+
|
|
|
+
|
|
|
+function cubes() {
|
|
|
+ let arr = [0, 1, 2, 5, 10];
|
|
|
+
|
|
|
+ let num = 0;
|
|
|
+ let arrMode = [];
|
|
|
+ for (let key of arr) {
|
|
|
+ let cube = num * num * num;
|
|
|
+ arrMode.push(cube);
|
|
|
+ num++;
|
|
|
+ }
|
|
|
+ console.log(arrMode)
|
|
|
+}
|
|
|
+// cubes()
|
|
|
+
|
|
|
+
|
|
|
+function multiplyTable() {
|
|
|
+ let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
|
|
+ let arrMode = [];
|
|
|
+
|
|
|
+ for (let keyN of arr) {
|
|
|
+ arrMode[keyN] = [];
|
|
|
+ for (let keyM of arr) {
|
|
|
+ arrMode[keyN][keyM] = (keyN * keyM);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ console.log(arrMode[7][2])
|
|
|
+}
|
|
|
+// multiplyTable()
|
|
|
+
|
|
|
+
|
|
|
+function matrix() {
|
|
|
+ let tab = document.getElementById("table");
|
|
|
+
|
|
|
+ let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
|
|
|
+ let arrMode = [];
|
|
|
+ let html = "<table>";
|
|
|
+ for (let keyN of arr) {
|
|
|
+ arrMode[keyN] = [];
|
|
|
+ for (let keyM of arr) {
|
|
|
+ arrMode[keyN][keyM] = (keyN * keyM);
|
|
|
+ html +=
|
|
|
+ `<tr>
|
|
|
+ <td>${keyN}</td>
|
|
|
+ <td>${keyM}</td>
|
|
|
+ <td>${keyN * keyM}</td>
|
|
|
+ </tr>`
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ html += "</table>";
|
|
|
+ tab.innerHTML = html;
|
|
|
+}
|
|
|
+// matrix()
|
|
|
+
|
|
|
+
|
|
|
+function triangle() {
|
|
|
+ let i = 0,
|
|
|
+ j = 0;
|
|
|
+
|
|
|
+ let dot = "",
|
|
|
+ grid = "";
|
|
|
+
|
|
|
+ while (i < 5) {
|
|
|
+ dot = "";
|
|
|
+ grid = "";
|
|
|
+ for (j = 1; j < 5 - i; j++) {
|
|
|
+ dot += ". ";
|
|
|
+ }
|
|
|
+
|
|
|
+ for (j = 0; j < 2 * i + 1; j++) {
|
|
|
+ grid += "# ";
|
|
|
+ }
|
|
|
+ console.log(dot + grid + dot);
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+}
|
|
|
+// triangle()
|
|
|
+
|
|
|
+
|
|
|
+function electronicFortuneTeller() {
|
|
|
+ let userNumber;
|
|
|
+ let prediction = [];
|
|
|
+ let historySize = 4;
|
|
|
+
|
|
|
+ for (let i = 1; i <= 5; i++) {
|
|
|
+ if (prediction.length < historySize) {
|
|
|
+ console.log("prediction = RANDOM " + Math.round(Math.random()));
|
|
|
+ userNumber = +prompt("Введите число", "");
|
|
|
+ prediction.push(userNumber);
|
|
|
+ } else {
|
|
|
+ console.log("prediction = HISTORY " + prediction[0]);
|
|
|
+ userNumber = +prompt("Введите число", "");
|
|
|
+ prediction.push(userNumber);
|
|
|
+ prediction.shift();
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|
|
|
+// electronicFortuneTeller()
|