|
@@ -56,38 +56,41 @@ function htmlTree() {
|
|
|
// declarativeFields()
|
|
|
function declarativeFields() {
|
|
|
var notebook = {
|
|
|
- brand: "HP",
|
|
|
- type: "440 G4",
|
|
|
- model: "Y7Z75EA",
|
|
|
- ram: 4,
|
|
|
- size: "14",
|
|
|
- weight: 1.8,
|
|
|
+ brand: prompt("Enter a brand",""),
|
|
|
+ type: prompt("Enter a type",""),
|
|
|
+ model: prompt("Enter a model",""),
|
|
|
+ ram: +prompt("Enter amount of ram (gb)",""),
|
|
|
+ size: prompt("Enter a size of screen (inch)",""),
|
|
|
+ weight: +prompt("Enter a weight (kg)",""),
|
|
|
resolution: {
|
|
|
- width: 1920,
|
|
|
- height: 1080,
|
|
|
+ width: +prompt("Enter a resolution width (px)",""),
|
|
|
+ height: +prompt("Enter a resolution height (px)",""),
|
|
|
},
|
|
|
};
|
|
|
+ console.log(notebook);
|
|
|
|
|
|
var phone = {
|
|
|
- brand: "meizu",
|
|
|
- model: "m2",
|
|
|
- ram: 2,
|
|
|
- color: "black",
|
|
|
+ brand: prompt("Enter a brand",""),
|
|
|
+ model: prompt("Enter a model",""),
|
|
|
+ ram: +prompt("Enter amount of ram (gb)",""),
|
|
|
+ color: prompt("Enter a color",""),
|
|
|
};
|
|
|
+ console.log(phone);
|
|
|
|
|
|
var person = {
|
|
|
- name: "Donald",
|
|
|
- surname: "Trump",
|
|
|
- married: true,
|
|
|
+ name: prompt("Enter a name",""),
|
|
|
+ surname: prompt("Enter a surname",""),
|
|
|
+ married: confirm("Is person married?",""),
|
|
|
}
|
|
|
+ console.log(person);
|
|
|
}
|
|
|
|
|
|
// tableMult()
|
|
|
function tableMult() {
|
|
|
let str = '<table>'
|
|
|
- for (let rowIndex=1; rowIndex<10; rowIndex++){
|
|
|
+ for (let rowIndex=1; rowIndex<10; rowIndex++) {
|
|
|
str += '<tr>'
|
|
|
- for (j=1; j<10; j++){
|
|
|
+ for (let j=1; j<10; j++) {
|
|
|
str += `<td>${rowIndex*j}</td>`
|
|
|
}
|
|
|
str += '</tr>'
|
|
@@ -124,27 +127,259 @@ function tableMultObj() {
|
|
|
document.write(str)
|
|
|
}
|
|
|
|
|
|
-htmlTree()
|
|
|
-function htmlTree() {
|
|
|
+// objectLinks()
|
|
|
+function objectLinks() {
|
|
|
+ var notebook = {
|
|
|
+ brand: "HP",
|
|
|
+ type: "440 G4",
|
|
|
+ model: "Y7Z75EA",
|
|
|
+ ram: 4,
|
|
|
+ size: "14",
|
|
|
+ weight: 1.8,
|
|
|
+ resolution: {
|
|
|
+ width: 1920,
|
|
|
+ height: 1080,
|
|
|
+ },
|
|
|
+ };
|
|
|
+
|
|
|
+ var phone = {
|
|
|
+ brand: "meizu",
|
|
|
+ model: "m2",
|
|
|
+ ram: 2,
|
|
|
+ color: "black",
|
|
|
+ };
|
|
|
+
|
|
|
+ var person = {
|
|
|
+ name: "Donald",
|
|
|
+ surname: "Trump",
|
|
|
+ married: true,
|
|
|
+ };
|
|
|
+ person.smartphone = phone;
|
|
|
+ person.laptop = notebook;
|
|
|
+ phone.owner = person;
|
|
|
+ notebook.owner = person;
|
|
|
|
|
|
+ console.log(person.smartphone.owner.laptop.owner.smartphone == person.smartphone);
|
|
|
}
|
|
|
|
|
|
-htmlTree()
|
|
|
-function htmlTree() {
|
|
|
|
|
|
+// imperativeArrayFill3()
|
|
|
+function imperativeArrayFill3() {
|
|
|
+ let arr = [];
|
|
|
+ arr[0] = prompt("Вводи элемент массива","")
|
|
|
+ arr[1] = prompt("Вводи элемент массива","")
|
|
|
+ arr[2] = prompt("Вводи элемент массива","")
|
|
|
+ console.log(arr);
|
|
|
}
|
|
|
|
|
|
-htmlTree()
|
|
|
-function htmlTree() {
|
|
|
+// whileConfirm()
|
|
|
+function whileConfirm() {
|
|
|
+ let a = true;
|
|
|
+ while (a) {
|
|
|
+ a = confirm('Продолжить цикл?')
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
+// arrayFill()
|
|
|
+function arrayFill() {
|
|
|
+ let arr = [];
|
|
|
+ let res = null;
|
|
|
+ do {
|
|
|
+ res = prompt("Вводи элемент массива","");
|
|
|
+ if (res !== null) {
|
|
|
+ arr.push(res);
|
|
|
+ }
|
|
|
+ } while (res !== null)
|
|
|
+ console.log(arr);
|
|
|
}
|
|
|
|
|
|
-htmlTree()
|
|
|
-function htmlTree() {
|
|
|
+// arrayFillNopush()
|
|
|
+function arrayFillNopush() {
|
|
|
+ let arr = [];
|
|
|
+ let res = null;
|
|
|
+ let i = 0;
|
|
|
+ do {
|
|
|
+ res = prompt("Вводи элемент массива","");
|
|
|
+ if (res !== null) {
|
|
|
+ arr[i] = res;
|
|
|
+ }
|
|
|
+ i++;
|
|
|
+ } while (res !== null)
|
|
|
+ console.log(arr);
|
|
|
+}
|
|
|
|
|
|
+// infiniteProbability()
|
|
|
+function infiniteProbability() {
|
|
|
+ let i = 0;
|
|
|
+ while (true) {
|
|
|
+ if (Math.random() > 0.9) {
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ i++;
|
|
|
+ }
|
|
|
+ console.log(`Количество итераций: ${i}`);
|
|
|
}
|
|
|
|
|
|
-htmlTree()
|
|
|
-function htmlTree() {
|
|
|
+// emptyLoop()
|
|
|
+function emptyLoop() {
|
|
|
+ for (let i = 0; i !== null; i = prompt("Продолжить цикл?","")) {}
|
|
|
+}
|
|
|
+
|
|
|
+// progressionSum()
|
|
|
+function progressionSum() {
|
|
|
+ let n = Number(prompt("До какого числа продолжать прогрессию?",""));
|
|
|
+ let sum = 0;
|
|
|
+ for (let i = 1; i <= n; i += 3) {
|
|
|
+ sum += i;
|
|
|
+ }
|
|
|
+ console.log(sum);
|
|
|
+}
|
|
|
+
|
|
|
+// chessOneLine()
|
|
|
+function chessOneLine() {
|
|
|
+ let size = +prompt("Введите длинну строки","");
|
|
|
+ let str = '';
|
|
|
+ for (let i = 0; i < size; i++) {
|
|
|
+ if (i % 2 === 0) {
|
|
|
+ str += ' ';
|
|
|
+ } else {
|
|
|
+ str += '#';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ console.log(str);
|
|
|
+}
|
|
|
+
|
|
|
+// numbers()
|
|
|
+function numbers() {
|
|
|
+ let str = ''
|
|
|
+ for (let i=0; i < 10; i++) {
|
|
|
+ for (let j=0; j < 10; j++) {
|
|
|
+ str += `${j}`
|
|
|
+ }
|
|
|
+ str += '\n'
|
|
|
+ }
|
|
|
+ console.log(str)
|
|
|
+}
|
|
|
+
|
|
|
+// chess()
|
|
|
+function chess() {
|
|
|
+ let size = +prompt("Введите размер поля","")
|
|
|
|
|
|
-}
|
|
|
+ let str = ''
|
|
|
+ let counter = 0
|
|
|
+ while (counter < size) {
|
|
|
+ counter++
|
|
|
+ if (counter % 2 === 0) {
|
|
|
+ for (let counter2 = 0; counter2 < size; counter2++) {
|
|
|
+ if (counter2 % 2 === 0) {
|
|
|
+ str += '.'
|
|
|
+ } else {
|
|
|
+ str += '#'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ str += '\n'
|
|
|
+ } else {
|
|
|
+ for (let counter3 = 0; counter3 < size; counter3++) {
|
|
|
+ if (counter3 % 2 === 0) {
|
|
|
+ str += '#'
|
|
|
+ } else {
|
|
|
+ str += '.'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ str += '\n'
|
|
|
+ }
|
|
|
+ }
|
|
|
+ console.log(str)
|
|
|
+}
|
|
|
+
|
|
|
+// cubes()
|
|
|
+function cubes() {
|
|
|
+ let arr = []
|
|
|
+ let inputNumber = +prompt("Введите длинну массива","")
|
|
|
+ let i = 0
|
|
|
+ while (i < inputNumber) {
|
|
|
+ let element = (i ** 3)
|
|
|
+ arr.push(element)
|
|
|
+ i++
|
|
|
+ }
|
|
|
+ console.log(arr)
|
|
|
+}
|
|
|
+
|
|
|
+// multiplyTable()
|
|
|
+function multiplyTable() {
|
|
|
+ let arr = []
|
|
|
+ for (let i=0; i < 10; i++) {
|
|
|
+ arr[i] = []
|
|
|
+ for (let j=0; j < 10; j++) {
|
|
|
+ arr[i].push(i*j)
|
|
|
+ }
|
|
|
+ }
|
|
|
+ console.log(arr)
|
|
|
+ return arr
|
|
|
+}
|
|
|
+
|
|
|
+// matrixToHtmlTable()
|
|
|
+function matrixToHtmlTable() {
|
|
|
+ let inputArr = multiplyTable()
|
|
|
+ let str = '<table>'
|
|
|
+ for (let i = 0; i < inputArr.length; i++) {
|
|
|
+ str += '<tr>'
|
|
|
+ for (let j = 0; j < inputArr[i].length; j++) {
|
|
|
+ str += `<td>${inputArr[i][j]}</td>`
|
|
|
+ }
|
|
|
+ str += '</tr>'
|
|
|
+ }
|
|
|
+ str += '</table>'
|
|
|
+ document.write(str)
|
|
|
+}
|
|
|
+
|
|
|
+// triangle()
|
|
|
+function triangle() {
|
|
|
+ let height = +prompt("Введите высоту треугольника","")
|
|
|
+ let width = (height * 2 - 1)
|
|
|
+ let arr = []
|
|
|
+ let str = ''
|
|
|
+
|
|
|
+ for (let colCounter = 0; colCounter < width; colCounter++) {
|
|
|
+ arr[colCounter] = []
|
|
|
+ for (rowCounter = 0; rowCounter < height; rowCounter++) {
|
|
|
+ if (colCounter < height) {
|
|
|
+ if (rowCounter <= colCounter) {
|
|
|
+ arr[colCounter].push('#')
|
|
|
+ } else {
|
|
|
+ arr[colCounter].push('.')
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (rowCounter < (width - colCounter)) {
|
|
|
+ arr[colCounter].push('#')
|
|
|
+ } else {
|
|
|
+ arr[colCounter].push('.')
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+// console.log(arr)
|
|
|
+
|
|
|
+ for (let j = 1; j <= arr[0].length; j++) {
|
|
|
+ for (let i = 0; i < arr.length; i++) {
|
|
|
+ str += `${arr[i][arr[i].length - j]}`
|
|
|
+ }
|
|
|
+ str += '\n'
|
|
|
+ }
|
|
|
+ console.log(str)
|
|
|
+}
|
|
|
+
|
|
|
+fortuneTeller ()
|
|
|
+function fortuneTeller() {
|
|
|
+ history = [1,1,1,1]
|
|
|
+
|
|
|
+ let loop = true;
|
|
|
+ while (loop) {
|
|
|
+ let userInput = +confirm('Нажмите ОК, если выбираете 1\nНажмите Отмена, если выбираете 0')
|
|
|
+ console.log(userInput)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ loop = confirm('Еще?')
|
|
|
+ }
|
|
|
+}
|