123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332 |
- "use strict";
- 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()
|