|
@@ -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(),
|
|
|
+};
|