Valerii Zahumonnyi hai 1 ano
pai
achega
33cfdd0692
Modificáronse 2 ficheiros con 107 adicións e 0 borrados
  1. 12 0
      JavaScript/HW_06/index.html
  2. 95 0
      JavaScript/HW_06/myjs.js

+ 12 - 0
JavaScript/HW_06/index.html

@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+    <meta charset="UTF-8">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>HW_06</title>
+</head>
+<body>
+    <script src="myjs.js"></script>
+</body>
+</html>

+ 95 - 0
JavaScript/HW_06/myjs.js

@@ -0,0 +1,95 @@
+//a
+function a(text) {
+    alert(text)
+}
+
+//cube
+function cube(a) {
+    return Math.pow(a, 3)
+}
+
+//avg2
+function avg2(a, b) {
+    return (a + b) / 2
+}
+
+//sum3
+function sum3(a, b, c = 0) {
+    return  a + b + c;
+}
+
+//intRandom
+function intRandom(a = 0, b = 0) {
+    return Math.round(Math.random() * (b - a) + a);
+}
+
+//greetAll
+function greetAll() {
+    let greeting = [];
+    for(let i = 0; i < arguments.length; i++) {
+        greeting.push(` ${arguments[i]}`)
+    }
+    return alert(`Hello ${greeting}!!!`)
+}
+
+//sum
+function sum() {
+    let result = 0
+    for(let parametr of arguments) {
+        result += parametr
+    }
+    return result
+}
+
+//Union
+function aSample() {
+    return a("Привет!")
+}
+function cubeSample() {
+    return cube(8)
+}
+function avg2Sample() {
+    return avg2(10, 20)
+}
+function sum3Sample() {
+    return sum3(20, 30, 50)
+}
+function intRandomSample() {
+    return intRandom(1, 10)
+}
+function greetAllSample() {
+    return greetAll("Superman", "SpiderMan", "Captain Obvious")
+}
+function sumSample() {
+    return sum(21, 32, 55, 78)
+}
+
+var sample = prompt('Enter task name: ')
+        switch (sample.toLowerCase()) {
+            case 'a': a("Привет!")
+                break;
+            case 'cube': cubeSample()
+                break;
+            case 'avg2': avg2Sample()
+                break;
+            case 'sum3': sum3Sample()
+                break;
+            case 'intRandom': intRandomSample()
+                break;
+            case 'greetAll': greetAllSample()
+                break;
+            case 'sum': sumSample()
+                break;
+            default: alert('Error!!!')    
+        }
+
+//Union declarative
+let sampleObject = {
+    a: aSample(),
+    cube: cubeSample(),
+    avg2: avg2Sample(),
+    sum3: sum3Sample(),
+    intRandom: intRandomSample(),
+    greetAll: greetAllSample(),
+    sum: sumSample(),
+};