123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317 |
- // ДЗ: Вложенные декларативные структуры и код в них. Отображение циклических и древовидных структур. Циклы.
- // html tree------------------------------------------------------------------------------------------------;
- let body = {
- tagName: "body",
- subTags: [
- {
- tagName: "div",
- subTags: [
- {
- tagName: "span",
- text: "Enter a data please:",
- },
- {
- tagName: "br",
- },
- {
- 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);
- // ID другого input
- console.log(body.subTags[0].subTags[3].attrs.id);
- // declarative fields--------------------------------------------------------------------------------------------------------------------------------------------;
- // let clientsCar = {
- // brand: prompt("Enter a brand car"),
- // model: prompt("Enter a model of car"),
- // volume: +prompt("choose volume of your future car"),
- // color: prompt("What color you wish?"),
- // HP: +prompt("Enter horse power what you need"),
- // };
- // let clientCard = {
- // name: prompt("Enter your name, please"),
- // surname: prompt("Enter your surname, please"),
- // age: +prompt("Enter your age, please"),
- // education: prompt(
- // "enter your educational level (higher education, secondary education, etc."
- // ),
- // gender: prompt("choose your gender: man, woman"),
- // sallery: +prompt("what is your annual income?"),
- // };
- // let noteOfDream = {
- // brand: prompt("what brand of laptop would you like?"),
- // model: prompt("select laptop model "),
- // CPU: prompt("select the CPU"),
- // GPU: prompt("choose graphics: built-in or discrete "),
- // GPU_memory: +prompt(
- // "if you chose discrete graphics, select the amount of video memory you want "
- // ),
- // display: {
- // width: +prompt("enter width of resolution"),
- // height: +prompt("enter height of resolution"),
- // refresh_rate: prompt("What level of screen refresh is right for you?"),
- // },
- // storage: {
- // type: prompt("SSD or HDD"),
- // volume: +prompt("How many Gb you need?"),
- // },
- // };
- // object links---------------------------------------------------------------------------------------------;
- let clientsCar = {
- brand: prompt("Enter a brand car"),
- model: prompt("Enter a model of car"),
- volume: +prompt("choose volume of your future car"),
- color: prompt("What color you wish?"),
- HP: +prompt("Enter horse power what you need"),
- };
- let clientCard = {
- name: prompt("Enter your name, please"),
- surname: prompt("Enter your surname, please"),
- age: +prompt("Enter your age, please"),
- education: prompt(
- "enter your educational level (higher education, secondary education, etc."
- ),
- gender: prompt("choose your gender: man, woman"),
- sallery: +prompt("what is your annual income?"),
- };
- let noteOfDream = {
- brand: prompt("what brand of laptop would you like?"),
- model: prompt("select laptop model "),
- CPU: prompt("select the CPU"),
- GPU: prompt("choose graphics: built-in or discrete "),
- GPU_memory: +prompt(
- "if you chose discrete graphics, select the amount of video memory you want "
- ),
- display: {
- width: +prompt("enter width of resolution"),
- height: +prompt("enter height of resolution"),
- refresh_rate: prompt("What level of screen refresh is right for you?"),
- },
- storage: {
- type: prompt("SSD or HDD"),
- volume: +prompt("How many Gb you need?"),
- },
- };
- clientsCar.owner = clientCard.name;
- clientCard.car = clientsCar.brand;
- clientCard.notebook = noteOfDream.brand;
- console.log(clientsCar);
- console.log(clientCard);
- console.log(noteOfDream);
- // imperative array fill 3----------------------------------------------------------------------------------;
- // let foodList = [
- // prompt("Enter 1 product in list"),
- // prompt("Enter 1 product in list"),
- // prompt("Enter 1 product in list"),
- // ];
- // while confirm--------------------------------------------------------------------------------------------;
- // let userConfirm;
- // do {
- // userConfirm = confirm("Do you want buy anything?");
- // console.log(userConfirm);
- // } while (userConfirm == false);
- // array fill-----------------------------------------------------------------------------------------------;
- // let productsList = [];
- // do {
- // userChoice = prompt("What you must buy in shop?");
- // productsList.push(userChoice);
- // console.log(productsList);
- // } while (userChoice !== null);
- // array fill nopush----------------------------------------------------------------------------------------;
- // let productsList = [];
- // let userChoice;
- // for (i = 0; userChoice !== null; i++) {
- // userChoice = prompt("What you must buy in shop?");
- // productsList[i] = userChoice;
- // console.log(productsList);
- // }
- // infinite probability-------------------------------------------------------------------------------------;
- // for (let i = 0; true; i++)
- // if (Math.random() > 0.9) {
- // alert(++i);
- // break;
- // }
- // empty loop-----------------------------------------------------------------------------------------------;
- while (prompt() === null);
- // progression sum------------------------------------------------------------------------------------------;
- // function fn(n) {
- // for (let s = (i = 1); i < n; s += i += 3) {}
- // return s;
- // }
- // alert(fn(7));
- // chess online-------------------------------------------------------------------------------------------;
- // let str = "";
- // for (i = 0; i <= 10; i++) {
- // str += " " + "#";
- // }
- // console.log(str);
- // numbers--------------------------------------------------------------------------------------------------;
- // let numbers = "";
- // for (j = 0; j <= 9; j++) {
- // numbers += "\n";
- // for (i = 0; i <= 9; i++) {
- // numbers += i;
- // }
- // }
- // console.log(numbers);
- // chess----------------------------------------------------------------------------------------------------;
- // const dot = ".";
- // const tag = "#";
- // let res = "";
- // for (let i = 0; i < 10; i++) {
- // let str = "";
- // for (let j = 0; j < 12; j++) {
- // str += (i + j) & 1 ? tag : dot;
- // }
- // res += str + "\n";
- // }
- // console.log(res);
- // cubes----------------------------------------------------------------------------------------------------;
- let cubes = [];
- let n = 100;
- for (i = 0; i < n; i++) {
- cubes.push(i ** 3);
- }
- console.log(cubes);
- // multiply table-------------------------------------------------------------------------------------------;
- let multiplication = Array(11);
- for (let i = 0; i < 11; i++) {
- multiplication[i] = [...Array(11)].map((_, j) => i * j);
- }
- console.log(multiplication);
- // matrix to html table-------------------------------------------------------------------------------------;
- document.write("<style>td, caption {font-family: arial}</style>");
- document.write('<table align="center" bgcolor="7ffa92" ');
- document.write('cellspacing="0" cellpadding="4" ');
- document.write('border="2" style="border-collapse: collapse">');
- document.write(
- "<caption><p><b>Multiplication table in decimal system</caption></b>"
- );
- for (let row = 0; row <= 10; row++) {
- document.write("<tr>");
- for (let col = 0; col <= 10; col++) {
- if (row == 0 || col == 0) {
- codeTD = '<td align="center" width="4%" bgcolor="b1c4b4">';
- if (row == col) {
- codeContent = "<b>&#" + "215;</b>";
- } else if (row == 0) {
- codeContent = "<b>" + col + "</b>";
- } else if (col == 0) {
- codeContent = "<b>" + row + "</b>";
- }
- } else {
- codeTD = '<td align="center">';
- if (row == col) {
- codeContent = "<b>" + row * col + "</b>";
- } else {
- codeContent = row * col;
- }
- }
- document.write(codeTD + codeContent + "</td>");
- }
- document.write("</tr>");
- }
- document.write("<table>");
- // Задание на синий пояс: Треугольник-----------------------------------------------------------------------;
- let lines = (line = 6),
- a = ".",
- b = "#";
- for (; line-- > 0; ) {
- console.log(
- Array(line + 1).join(a) +
- Array(2 * (lines - line)).join(b) +
- Array(line + 1).join(a)
- );
- }
|