Browse Source

hometask 06 - functions is done

pocu46 4 years ago
parent
commit
cc0ead15e9
5 changed files with 206 additions and 58 deletions
  1. 25 25
      04/script.js
  2. 11 0
      05/index.html
  3. 59 0
      05/script.js
  4. 86 33
      06/script.js
  5. 25 0
      Chat/index.html

+ 25 - 25
04/script.js

@@ -170,11 +170,11 @@
 
 // console.log(someText);
 
-let someText = prompt("Enter some text");
+// let someText = prompt("Enter some text");
 
-while(someText = prompt("Enter some text")) {}
+// while(someText = prompt("Enter some text")) {}
 
-console.log(someText);
+// console.log(someText);
 
 // --------------------------------progression sum---------------------------------------------
 
@@ -245,33 +245,33 @@ console.log(someText);
 
 // --------------------------------black task---------------------------------------------
 
-// let forcast = Math.random();
-// if(forcast < 0.5) {
-//     forcast = 0
-// } else {
-//     forcast = 1
-// }
+let forcast = Math.random();
+if(forcast < 0.5) {
+    forcast = 0
+} else {
+    forcast = 1
+}
 
-// console.log(`Gipsy says ${forcast}`);
+console.log(`Gipsy says ${forcast}`);
 
-// let userNumber = +prompt("Enter o or 1  dhvjbv", "0 or 1");            //   Нужно починить
+let userNumber = +prompt("Enter o or 1  dhvjbv", "0 or 1");            //   Нужно починить
 
-// console.log(typeof userNumber);
+console.log(typeof userNumber);
 // debugger;
-// while(userNumber !== 0 || userNumber !== 1) {
-// // while(userNumber !== Number) {
-//     alert("You need to enter 0 or 1");
-//     userNumber = +prompt("Enter o or 1", "0 or 1");
-// }
+while(!+prompt) {
+// while(userNumber !== Number) {
+    alert("You need to enter 0 or 1");
+    userNumber = +prompt("Enter o or 1", "0 or 1");
+}
 
-// let history = [1, 1, 1, 1];
+let history = [1, 1, 1, 1];
 
-// let resume = true;
+let resume = true;
 
-// while(resume === true) {
-//     history.push(userNumber);
-//     history.shift();
-//     resume = confirm("Do you want to continue?");
-// }
+while(resume === true) {
+    history.push(userNumber);
+    history.shift();
+    resume = confirm("Do you want to continue?");
+}
 
-// console.log(history);
+console.log(history);

+ 11 - 0
05/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>

+ 59 - 0
05/script.js

@@ -0,0 +1,59 @@
+// ------------------------------3 persons----------------------------------------------
+
+// let a = {
+//     name: "Victor",
+//     surname: "Basharov",
+// }
+
+// let b = {
+//     name: "Dmitriy",
+//     surname: "Ivanov",
+// }
+
+// let c = {
+//     name: "John",
+//     surname: "Doe",
+// }
+
+// ------------------------------different fields----------------------------------------------
+
+// let a = {
+//     name: "Victor",
+//     surname: "Basharov",
+//     age: 35
+// }
+
+// let b = {
+//     name: "Dmitriy",
+//     surname: "Ivanov",
+//     fathername: "Alexandrovich"
+// }
+
+// let c = {
+//     name: "John",
+//     surname: "Doe",
+//     sex: "Male"
+// }
+
+// ------------------------------fields check----------------------------------------------
+
+// for(let key1 in a) {
+//     if(key1 === "age") {
+//         alert(key1 + ': ' + a[key1]);
+//     }
+// }
+
+// for(let key2 in b) {
+//     if(key2 === "fathername") {
+//         alert(key2 + ': ' + b[key2]);
+//     }
+// }
+
+// for(let key3 in c) {
+//     if(key3 === "sex") {
+//         alert(key3 + ': ' + c[key3]);
+//     }
+// }
+
+// ------------------------------array of persons----------------------------------------------
+

+ 86 - 33
06/script.js

@@ -2,17 +2,17 @@
 
 // --------------------------------------------a--------------------------------------------------------------
 
-// function a(key) {
-//     alert(key);
-// }
+function a(key) {
+    alert(key);
+}
 
 // a("Hello Stranger");
 
 // --------------------------------------------cube--------------------------------------------------------------
 
-// function cube(number) {
-//     return number = number * number * number;
-// }
+function cube(number) {
+    return number = number * number * number;
+}
 
 // alert(cube(3));
 
@@ -21,10 +21,12 @@
 // let digit1 = +prompt("Enter first digit");
 // let digit2 = +prompt("Enter second digit");
 
-// function avg2(num1, num2) {
-//     let avg;
-//     return avg = (num1 + num2) / 2;
-// }
+function avg2(num1, num2) {
+    let avg = (num1 + num2) / 2;
+    return avg;
+}
+
+// alert(avg2+prompt("Enter first digit"), +prompt("Enter second digit")));
 
 // --------------------------------------------sum3--------------------------------------------------------------
 
@@ -32,10 +34,10 @@
 // let digit2 = +prompt("Enter second digit");
 // let digit3 = +prompt("Enter third digit");
 
-// function sum3(num1, num2, num3) {
-//     let sum;
-//     return sum = num1 + num2 + num3;
-// }
+function sum3(num1, num2, num3) {
+    let sum = num1 + num2 + num3;
+    return sum;
+}
 
 // alert(sum3(digit1, digit2, digit3));
 
@@ -44,22 +46,33 @@
 //     return sum = num1 + num2 + num3;      // Just wanted to try Arrow Functions
 // }
 
-// alert(sum3(digit1, digit2, digit3));
+// alert(sum3(+prompt("Enter first digit"), +prompt("Enter second digit"), +prompt("Enter third digit")));
 
 // --------------------------------------------intRandom--------------------------------------------------------------
 
 // function intRandom(min, max) {
-//     let num = Math.round(Math.random() * 10);            // Need to fix 
+//     let num = Math.round(Math.random() * max);            // Need to fix 
+//     if(num < 0) {
+//         num -= min;
+//     }
 //     if(num < min) {
 //         num = num + min;
 //     }
-//     if(num > max) {
-//         num = num - max;
-//     }
 
 //     return num;
 // }
 
+function intRandom(min, max) {
+
+    if(max != prompt) {
+        max = min;
+        min = 0;
+    }
+
+    let num = min - 0.5 + Math.random() * (max - min + 1);
+    return Math.round(num);
+}
+
 // alert(intRandom(+prompt("Enter Min value"), +prompt("Enter Max value")));
 // console.log(intRandom());
 
@@ -73,24 +86,64 @@
 
 //_____________________________________________This one is done as in requirements___________________________________________________________________
 
-// function greetingsAll() {  
-//     let names = [];
-//     for(let param of arguments) {
-//         names.push(param);
-//     }
-//     alert(`Hello ${names}`);
-// }
+function greetingsAll() {  
+    let names = [];
+    for(let param of arguments) {
+        names.push(param);
+    }
+    alert(`Hello ${names}`);
+}
 
 // greetingsAll("Sam", "Dean", "Jonathan");
 
 // --------------------------------------------sum--------------------------------------------------------------
 
-// function sum() {
-//     let total = 0;
-//     for(let key of arguments) {
-//         total += key;
-//     }
-//     return total;
+function sum() {
+    let total = 0;
+    for(let key of arguments) {
+        total += key;
+    }
+    return total;
+}
+
+// alert(sum(10, 25, 33, 46, 56));
+
+// --------------------------------------------Union--------------------------------------------------------------
+
+// let union = prompt("Введите название задания")
+// switch (union.toLowerCase()){
+//     case "a": a("Hello Stranger");
+//               break
+//     case "cube": alert(cube(3));
+//               break
+//     case "avg2": alert(avg2(+prompt("Enter first digit"), +prompt("Enter second digit")));
+//               break
+//     case "sum3": alert(sum3(+prompt("Enter first digit"), +prompt("Enter second digit"), +prompt("Enter third digit")));
+//               break
+//     case "intrandom": alert(intRandom(+prompt("Enter Min value"), +prompt("Enter Max value")));
+//               break
+//     case "greetAll": greetingsAll("Sam", "Dean", "Jonathan");
+//               break
+//     case "sum": alert(sum(10, 25, 33, 46, 56));
+//               break
 // }
 
-// console.log(sum(10, 25, 33, 46, 56));
+// --------------------------------------------Union declarative--------------------------------------------------------------
+
+let taskNames = {
+    "a": a,
+    "cube": cube,
+    "avg2": avg2,                                         // Doesn't work for now
+    "sum3": sum3,
+    "intrandom": intRandom,
+    "greetAll": greetingsAll,
+    "sum": sum
+}
+
+let taskToStart = prompt("Введите название задания");
+
+for(let key in taskNames) {
+    if(key === taskToStart) {
+        alert(key);
+    }
+}

+ 25 - 0
Chat/index.html

@@ -0,0 +1,25 @@
+<!DOCTYPE HTML>
+<html>
+    <head>
+        <title>
+            Static File Index.HTML
+        </title>
+        <script src='https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.js'></script>
+    </head>
+    <body>
+        <input id="nick" type="text" >
+        <input id="message" type="text" >
+        <!-- <input id="send" type="button" >
+     -->
+     <button id="send">send</button>
+        <div id='formContainer'>
+        </div>
+        <script>
+            const socket = io('http://192.168.1.20:5000/')
+            // socket.emit
+            send.onclick=() =>{
+console.log(nick.value+'   '+ message.value)
+}
+        </script>
+    </body>
+</html>