Viktor97 il y a 1 an
commit
860d128e6e
1 fichiers modifiés avec 135 ajouts et 0 suppressions
  1. 135 0
      index.js

+ 135 - 0
index.js

@@ -0,0 +1,135 @@
+//a
+function a() {
+    alert("Привет, Вася")
+}
+
+
+//cube
+function cube(b) {
+   return b = b ** 3
+    
+}
+
+
+//avg2
+function avg2(a,b) {
+    return (a+b)/2
+}
+
+
+//sum3
+function sum3(a, b, c) {
+ a = a || 0
+ b = b || 0
+ c = c || 0
+  let g =  a + b + c
+    return g
+}
+
+//intRandom
+function intRandom(a, b) {
+    
+    if (b === undefined) {
+        z = Math.round(Math.random()*a) 
+    } else {
+        z =   ((Math.round(Math.random() * (b - a))+a))
+    }
+       
+    return z
+}
+
+
+//greetAll  других вариантов не нашел
+
+let p = ""
+function greetAll() {
+    for (i = 0; i < arguments.length; i++){
+        p = p + " " + arguments[i]
+        
+    }
+    p
+    alert(`Hello, ${p}`)
+}
+
+//sum
+
+let sum1 = 0
+function sum() {
+    for (i = 0; i < arguments.length; i++){
+        sum1 += arguments[i]
+    }
+    return
+}
+
+
+//Union
+
+let challenge = prompt("Enter which task")
+switch (challenge.toLowerCase()) {
+    case 'a':  a()
+        break
+    case 'cube': cube(5)
+        break
+    case 'avg2': avg2(a,b)
+        break
+    case 'sum3': sum3(a, b, c)
+        break
+    case 'intRandom': intRandom(a, b)
+        break
+    case 'greetAll': greetAll()
+        break
+    case 'sum': sum()
+        break
+}
+
+
+
+//Union declarative
+
+
+
+function aSemple() {
+    return a()
+}
+
+function cubeSemple() {
+    return cube(5)
+}
+
+function avg2Semple() {
+    return avg2(5,10)
+}
+
+function sum3Semple() {
+    return sum3(5,6,8)
+}
+
+function intRandomSemple() {
+    return intRandom(2,20)
+}
+
+function greetAllSemple() {
+    return greetAll('VAsa', 'Sisa', 'Popa')
+}
+
+function sumSemple() {
+    return sum(1,2,3,4,5,6)
+}
+
+
+
+let unionDeclarative = {
+    a: aSemple(),
+    cube: cubeSemple(),
+    avg2: avg2Semple(),
+    sum3: sum3Semple(),
+    intRandom: intRandomSemple(),
+    greetALL: greetAllSemple(),
+    sum: sumSemple()
+    
+}
+
+
+let quiestion = prompt('Enter which task', 'task')
+alert( unionDeclarative[quiestion] )
+