Browse Source

<HW6>upd done

Mark 1 year ago
parent
commit
86e5934b0c
1 changed files with 45 additions and 28 deletions
  1. 45 28
      06/main.js

+ 45 - 28
06/main.js

@@ -11,22 +11,33 @@ function cube() {
 cube()
 
 // avg2
-function avg2(a, b) {
+function avg2() {
+   let a = +prompt('num1')
+   let b = +prompt('num2')
    console.log((a + b) / 2);
 }
-avg2(5, 10)
-avg2(1, 2)
+avg2()
+// avg2(5, 10)
+// avg2(1, 2)
 
 // sum3
 function sum3(a, b, c) {
    a = a || 0;
    b = b || 0;
    c = c || 0;
-   return a + b + c;
+   a = +prompt('num1')
+   b = +prompt('num2')
+   c = +prompt('num3')
+   return console.log(a + b + c);
+
 }
-console.log(sum3(1, 2, 3))
-console.log(sum3(5, 10, 100500))
-console.log(sum3(5, 10))
+sum3()
+
+// console.log(sum3(1, 2, 3))
+// console.log(sum3(5, 10, 100500))
+// console.log(sum3(5, 10))
+
+
 
 // intRandom
 // function intRandom(min, max) {
@@ -35,17 +46,21 @@ console.log(sum3(5, 10))
 //    let result = Math.random() * (max - min) + min;
 //    return Math.round(result)
 // }
-function intRandom(min, max) {
+function intRandom() {
+   let min = +prompt('min');
+   let max = +prompt('max');
    if (max === undefined) {
       max = min
       min = 0
    }
-   return Math.floor(Math.random() * (max - min + 1) + min)
+   return console.log(Math.floor(Math.random() * (max - min + 1) + min))
 }
-console.log(intRandom(2, 15))
-console.log(intRandom(-1, -1))
-console.log(intRandom(0, 1))
-console.log(intRandom(10))
+intRandom()
+// console.log(intRandom(2, 15))
+// console.log(intRandom(-1, -1))
+// console.log(intRandom(0, 1))
+// console.log(intRandom(10))
+
 
 // greetAll
 function greetAll(...arguments) {
@@ -70,9 +85,11 @@ sum(1)
 sum(2)
 sum(10, 20, 40, 100)
 
+
+
 // Union
-var sample = prompt("Введите название задания")
-switch (sample.toLowerCase()) {
+var sample = prompt("Введите название задания").toLowerCase()
+switch (sample) {
    case "a": a()
       break;
    case "cube": cube()
@@ -81,9 +98,9 @@ switch (sample.toLowerCase()) {
       break;
    case "sum3": sum3()
       break;
-   case "intRandom": intRandom()
+   case "intrandom": intRandom()
       break;
-   case "greetAll": greetAll()
+   case "greetall": greetAll()
       break;
    case "sum": sum()
       break;
@@ -91,15 +108,15 @@ switch (sample.toLowerCase()) {
 
 
 // Union declarative
-var sample = prompt("Введите название задания").toLowerCase()
-var sample2;
-var sample1 = {
-   a: a(),
-   cube: cube(),
-   avg2: avg2(),
-   sum3: sum3(),
-   intRandom: intRandom(),
-   greetAll: greetAll(),
-   sum: sum(),
+var sample = {
+   a() { a() },
+   cube() { cube() },
+   avg2() { avg2() },
+   sum3() { sum3() },
+   intrandom() { intRandom() },
+   greetall() { greetAll("Superman", "SpiderMan", "Captain Obvious") },
+   sum() { sum(10, 20, 40, 100) }
+
 }
-sample2 = sample[`${sample}`]
+console.log(sample[prompt('enter')]())
+