Jelajahi Sumber

4 hometask almost done

pocu46 4 tahun lalu
induk
melakukan
22c5d6dd38
2 mengubah file dengan 263 tambahan dan 0 penghapusan
  1. 11 0
      04/index.html
  2. 252 0
      04/script.js

+ 11 - 0
04/index.html

@@ -0,0 +1,11 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>Document</title>
+</head>
+<body>
+    <script src="./script.js"></script>
+</body>
+</html>

+ 252 - 0
04/script.js

@@ -0,0 +1,252 @@
+// --------------------------------html tree---------------------------------------------
+
+// let htmlTree = {
+//     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'
+//                     }
+//                 }
+//             ]
+//         }
+//     ]
+// }
+
+
+// alert(htmlTree.subTags[1].subTags[1].attrs.id);
+// alert(htmlTree.subTags[0].subTags[3].attrs.id);
+
+// --------------------------------declarative fields---------------------------------------------
+
+// var notebook = {
+//     brand: prompt("Enter Brand"),
+//     type:  prompt("Enter Type"),
+//     model: prompt("Enter Model"),
+//     ram: +prompt("Enter RAM number"),
+//     size: prompt("Enter Size"),
+//     weight: +prompt("Enter Weight"),
+//     resolution: {
+//         width: +prompt("Enter Width"),
+//         height: +prompt("Enter Height"),
+//     },
+// };
+
+// var phone = {
+//     brand: prompt("Enter Brand"),
+//     model: prompt("Enter Model"),
+//     ram: +prompt("Enter RAM number"),
+//     color: prompt("Enter Color"),
+// };
+
+// var person = {
+//     name: prompt("Enter Name"),
+//     surname: prompt("Enter Surname"),
+//     married: confirm("Married?"),
+// }
+
+// person.smartphone = "OnePlus 6t";
+// person.laptop = "Huawei D15";
+
+// notebook.owner = "Sid";
+
+// phone.owner = "Sid";
+
+// console.log(notebook);
+// console.log(phone);
+// console.log(person);
+
+// --------------------------------imperative array fill 3---------------------------------------------
+
+// let myArr1 = [];
+
+// myArr1.push(prompt("Enter element 1"));
+// myArr1.push(prompt("Enter element 2"));
+// myArr1.push(prompt("Enter element 3"));
+
+// console.log(myArr1);
+
+// let myArr2 = [];
+
+// for(let i=0; i<3; i++) {
+//     myArr2.push(prompt(`Enter element ${i+1}`));   // До сих пор не понимаю разницу между императивным и декларативным подходами
+// }                                                  // Поэтому написал 2 примера 
+
+// console.log(myArr2);
+
+// --------------------------------while confirm---------------------------------------------
+
+// let confirmLoop = false;
+
+// while(confirmLoop === false) {
+//     confirmLoop = confirm("Press No to continue loop");
+// } 
+
+// --------------------------------array fill---------------------------------------------
+
+// let newElement = prompt("Enter new element");
+// let arrayInLoop = [];
+
+// while(newElement != null) {
+//     newElement = prompt("Enter new element");
+//     arrayInLoop.push(newElement);
+// } 
+
+// console.log(arrayInLoop);
+
+// --------------------------------array fill nopush---------------------------------------------
+
+// let newElement = prompt("Enter new element");
+// let arrayInLoop = [];
+// let key = 0;
+
+// while(newElement != null) {
+//     arrayInLoop[key++] = newElement;
+//     newElement = prompt("Enter new element");
+// } 
+
+// console.log(arrayInLoop);
+
+// --------------------------------infinite probability---------------------------------------------
+
+// let random = Math.random();    // Я могу перенести эту строку над if и удалить в 143 ???
+// let counter = 1;
+
+// while(counter != 0) {    
+//     if(random > 0.9) {
+//         break;
+//     }
+//     counter++;
+//     random = Math.random();
+// }
+
+// alert(counter);
+
+// --------------------------------empty loop---------------------------------------------
+
+// let someText = prompt("Enter some text");
+
+// while(someText != null ) {
+//     someText = prompt("Enter some text");      // Не знаю как написать без тела цикла
+// }
+
+// console.log(someText);
+
+// --------------------------------progression sum---------------------------------------------
+
+// let progressionLenght = +prompt("Enter progression lenght", "Should be a Number");
+// let progressionTotal = 1;
+
+// for(let i=1; i<progressionLenght; i++) {
+//     progressionTotal += 3;
+// }
+
+// console.log(`progressionTotal = ${progressionTotal}`);
+
+// --------------------------------chess one line---------------------------------------------
+
+// let strLenght = +prompt("Enter string lenght", "Should be a Number");
+// let str = " ";
+
+// for(let i=0; i<Math.floor(strLenght / 2); i++) {
+//     str += " #";
+// }
+
+// if(strLenght % 2) {
+//     str += " ";
+// }
+
+// console.log(str);
+
+// --------------------------------numbers---------------------------------------------
+
+// let str = '';
+// let strNum = +prompt("Enter Strings number", "Should be a number");
+
+// for(let i=0; i<strNum; i++) {
+//     for(let j=0; j<10; j++) {
+//         str += j;
+//     }
+//     str = str + '\n';
+// }
+
+// console.log(str);
+
+// --------------------------------cubes---------------------------------------------
+
+// let arr = [];
+// let arrLenght = +prompt("Enter Array lenght");
+
+// for(let i=0; i<arrLenght; i++) {
+//     arr.push(i * i);
+// }
+
+// console.log(arr);
+
+// --------------------------------black task---------------------------------------------
+
+// let forcast = Math.random();
+// if(forcast < 0.5) {
+//     forcast = 0
+// } else {
+//     forcast = 1
+// }
+
+// console.log(`Gipsy says ${forcast}`);
+
+// let userNumber = +prompt("Enter o or 1", "0 or 1");            //   Нужно починить
+
+// // while(userNumber != 0 || userNumber != 1) {
+// //     alert("You need to enter 0 or 1");
+// //     userNumber = +prompt("Enter o or 1", "0 or 1");
+// // }
+
+// let history = [1, 1, 1, 1];
+
+// let resume = true;
+
+// while(resume === true) {
+//     history.push(userNumber);
+//     history.shift();
+//     resume = confirm("Do you want to continue?");
+// }
+
+// console.log(history);