Browse Source

HW5 done without BlackBelt

maryluis 4 years ago
parent
commit
fdaa0e5a3e
2 changed files with 412 additions and 0 deletions
  1. 11 0
      homework5js/exersices.html
  2. 401 0
      homework5js/script.js

+ 11 - 0
homework5js/exersices.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>

+ 401 - 0
homework5js/script.js

@@ -0,0 +1,401 @@
+//////html tree
+function htmlTree() {    
+    var 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"
+                        }
+                    }
+                ]
+            }
+        ],
+    }
+    alert(body.subTags[1].subTags[1].text)
+    alert(body.subTags[0].subTags[3].attrs.id)
+}
+// htmlTree()
+//////
+
+//////
+/////declarative fields
+/////object links
+function declarativeFriends() {
+    var notebook = {
+        brand: prompt("Name of brand of notebook"),
+        type:  prompt("Number of type in style 'XXX XX'"),
+        model: prompt("Model code"),
+        ram: +prompt("Ram"),
+        size: prompt("Size"),
+        weight: +prompt("Weight in style X.X"),
+        resolution: {
+            width: +prompt("Width"),
+            height: +prompt("Height"),
+        },
+    };
+    
+    var phone = {
+        brand: prompt("Name of brand of phone"),
+        model: prompt("Model code"),
+        ram: +prompt("Ram"),
+        color: prompt("What's color?"),
+    };
+    
+    var person = {
+        name: prompt("Write your name?"),
+        surname: prompt("Write your surname?"),
+        married: confirm("Are you married? Click 'ok' if answer is 'yes' and 'cancel' if 'no'"),
+    }
+    person.laptop = notebook;
+    person.smartphone = phone;
+    phone.owner = person;
+    notebook.owner = person;
+
+
+    alert("Notebook \n owner: " + notebook.owner.name + "\n brand: " + notebook.brand + "\n type: " + notebook.type + "\n model: " + notebook.model + "\n ram: " + notebook.ram + "\n size: " + notebook.size + "\n weight: " + notebook.weight + "\n width: " + notebook.resolution.width + "\n height: " + notebook.resolution.height)
+    alert("Phone\n owner: " + phone.owner.name + "\n brand: " + phone.brand + "\n model: " + phone.model + "\n ram: " + phone.ram + "\n color: " + phone.color)
+    alert("Person\n name " + person.name + "\n surname: " + person.surname + "\n married: " + person.married + "\n laptop: " + notebook.brand + "\n smartphone: " + phone.brand)
+
+
+    if (person.smartphone.owner.laptop.owner.smartphone == person.smartphone){
+        alert ("You're superman")
+   } else {
+       alert ("Try again, loser")
+   }
+
+}
+// declarativeFriends()
+//////////////
+
+
+/////
+/////imperative array fill 3
+debugger
+function imperativeArray() {
+    let imperative = [];
+    imperative[0] = prompt("How old are you?"), imperative[1] = prompt("How old is your father?"), imperative[2] = prompt("How old is your mother?")
+    alert("So you are " + imperative[0] + " years old. Your father is " + imperative[1] + " and mother is " + imperative[2])
+}
+imperativeArray()
+////////
+
+
+//////
+///while confirm
+function whileConfirm(question) {
+    question = false;
+    while(question === false) {
+        question = confirm("Are you're dead?")
+    }
+}
+// whileConfirm()
+
+//////////
+
+
+
+
+////array fill
+function arrayFill() {
+    var array = [];
+    var once = true;
+    while(!!once === true) {
+        once = prompt("Write something")
+        array.push(once)
+    }
+    alert("The array's length is " + array.length)
+}
+// arrayFill()
+///////
+
+
+/////array fill nopush
+function arrayFillNopush() {
+    var i = 0;
+    var array = [];
+    var once = prompt("Write something");
+    while(!!once === true) {
+        array[i++] = once;
+        once = prompt("Write something");
+    } 
+    alert("The array's length is " + array.length)
+}
+// arrayFillNopush()
+
+
+
+////infinite probability
+function infiniteProbably() {
+    let haha = true;
+    let i = 0;
+    let array = []
+    debugger
+    while (haha === true) {
+        i = Math.random();
+        array.push(i)
+        if (i > 0.9) {
+            break;
+        }
+        confirm("And again")
+}
+alert ("You had " + array.length + " expected output")
+}
+// infiniteProbably()
+//////
+
+
+///////empty loop
+function emptyLoop() {
+    var again = null;
+    while(again === null) {
+        again = prompt("And again?")
+    }
+}
+// emptyLoop()
+///////////
+
+
+
+//////progression sum
+function progressionSum() {
+    let b = (+prompt("Chose your number"))
+    let sum = 1;
+    let a = 1;
+    for (let i = 1; b > a; i++){ 
+        a = a + 3;    
+        if (a > b) {
+            alert(sum + " but it can have an error in 1-2 count")
+            return
+         } else {
+             sum = sum + a;
+         }   
+    }
+alert (sum)
+
+}
+// progressionSum()
+//////////////////
+
+
+////chess one line
+function chessOneLine() {
+    let num = +prompt("String length is...");
+    let string = "";
+    for(;num > 0; num = num - 1){
+        if (num % 2 == 0) {
+            string += "#";
+        } else {
+            string += " ";
+        }
+    }
+    return console.log(string)
+}
+// chessOneLine()
+///////////////
+
+
+
+///////
+/////numbers
+function numberCucle() {
+    let stringMass = "";
+    for(let i = 0; i < 10; i++) {
+        let string = "";
+        for (let j = 0; j < 10; j++) {
+            string += j
+        }
+        stringMass += string + "\n"
+    } 
+    console.log(stringMass)
+}
+// numberCucle()
+///////////////////
+
+
+//////////
+////chess
+function chess(){
+    let desk = "";
+    let string = "";
+    let x = +prompt("Please write a size of horizontal")
+    let y = +prompt("Please write a size of vertical") 
+    for(let i = 0; i < y; y--){
+        for(let j = 0; j < x; x--) {
+            if(y % 2 === 0){
+                if(x % 2 === 0) {
+                    string += "#";
+                } else {
+                    string += ".";
+                }
+            } else {
+                if(x % 2 === 0) {
+                    string += ".";
+                } else {
+                    string += "#";
+                }
+            }
+        }
+        desk += string + "\n"
+    }
+console.log(desk)
+}
+// chess()
+////////////
+
+
+/////////
+//cubes
+function cubes() {
+    var array = [];
+    var arrayString = "";
+    array.length = +prompt("And array length is...");
+    for(let i = 0; i < array.length; i++) {
+        array[i] = Math.pow(i, 3)
+        arrayString += array[i] + " "
+    }
+    alert(arrayString)
+}
+// cubes()
+///////////////////////
+
+
+
+///////////////
+////multiply table
+function multiplyTable() {
+    var table = [];
+    for(let i = 0; i < 10; i++) {
+        table[i] = [];
+        for(let j = 0; j < 10; j++){
+            table[i][j] = ((i) * j)
+            
+        }
+
+    }
+    console.log(table)
+alert(table[5][6])
+alert(table[7][2])
+}
+// multiplyTable()
+//////////////////
+
+
+///////////
+///matrix to html table
+function matrixTable() {
+debugger
+
+    var table = [];
+    for(let i = 0; i < 10; i++) {
+        var newDiv = document.createElement("div");
+        table[i] = [];
+        for(let j = 0; j < 10; j++){
+            var newSpan = document.createElement("span");
+            newSpan.style.display = "inline-block";
+            newSpan.style.width = "30px"
+            table[i][j] = ((i) * j);
+            newSpan.innerHTML = table[i][j]; 
+            newDiv.appendChild(newSpan); 
+        }
+        document.body.append(newDiv);
+    }
+
+}
+// matrixTable()
+//////////////////
+
+
+
+////////////////
+/////blue belt
+function blueBelt() {
+    var triangle = "";
+    var string = "";
+    var sharp = "#";
+    var dottRep = 5;
+    for(let j = 0; j < 6; j++) {
+        var dott = ".";
+        dott = dott.repeat(dottRep);
+        string += dott + sharp + dott + "\n";
+        dottRep = dottRep - 1;
+        sharp += "##"
+    }
+    triangle += string + "\n";
+    console.log(triangle)
+}
+// blueBelt()
+/////////////////
+
+
+
+////////////////
+//blackBelt
+debugger
+var predictArray = [];
+var historyArr = [1, 1, 1, 1];
+var myMove = Math.round(Math.random());
+
+// function blackBelt(history) {
+//     var yourMove = +prompt("Your move (0 or 1");
+//     if (yourMove === 1 || yourMove === 0) {
+        
+//         historyArr.shift();
+//         historyArr.push(yourMove);
+
+//         myMove = predictArray[historyArr[0]][historyArr[1]][historyArr[2]][historyArr[3]];
+
+//         predictArray[historyArr[0]][historyArr[1]][historyArr[2]][historyArr[3]] = yourMove;
+
+
+//         if (myMove === yourMove){
+//             alert("I knew it. Let's try again")
+//             return blackBelt()
+//         } else {
+//             alert ("You win. Let's try again")
+//             return blackBelt()
+//         }
+//     } else {
+//         alert ("Error. Try again")
+//         return blackBelt()
+//     }
+// }
+// blackBelt(historyArr);