123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144 |
- <!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-6</title>
- </head>
- <body>
- <script>
- //a
- function a() {
- alert("привет!!!")
- }
- a()
- //cube
- function cube(a) {
- return a ** 3;
- }
- alert(cube());
- alert(cube(3));
- //avg2
- function avg2(a, b) {
- return (a + b) / 2;
- }
- alert(avg2(1, 2))
- alert(avg2(10, 5))
- //sum3
- function sum3(a, b, c) {
- a = a || 0
- b = b || 0
- c = c || 0
- return (a + b + c)
- }
- alert(sum3(1, 2, 3));
- alert(sum3(5, 10, 100500));
- alert(sum3(5, 10));
- //intRandom
- function intRandom(a, b) {
- a = a || 0
- b = b || 0
- return Math.round(Math.random() * (b - a) + a);
- }
- alert(intRandom(2, 15));
- alert(intRandom(-1, -1));
- alert(intRandom(0, 1));
- alert(intRandom(10));
- //greetAll
- function greetAll(...params) {
- let add = "";
- for (i = 0; i < params.length; i++) {
- add += params[i] + " "
- }
- return alert("Hello " + add)
- }
- greetAll("Superman")
- greetAll("Superman", "SpiderMan")
- greetAll("Superman", "SpiderMan", "Captain Obvious")
- //sum
- function sum(...numbers) {
- var sum = 0;
- for (i = 0; i < numbers.length; i++) {
- sum += numbers[i];
- }
- return sum;
- }
- alert(sum(1))
- alert(sum(2))
- alert(sum(10, 20, 40, 100))
- //Union
- var sample = prompt("Введите название задания")
- switch (sample.toLowerCase()) {
- case "a":
- a()
- break
- case "cube":
- cube()
- break
- case "avg2":
- avg2()
- break;
- case "sum3":
- sum3()
- break;
- case "intRandom":
- intRandom()
- break;
- case "greetAll":
- greetAll()
- break
- case "sum":
- sum()
- break;
- }
- //Union declarative
-
- let sample2 = {
- a(){
- a("Привет")
- },
- cube() {
- cube(3)
- },
- avg2() {
- avg2(1 ,2)
- },
- sum3() {
- sum3(5, 10, 100500)
- },
- intRandom() {
- intRandom(-1, -1)
- },
- greetAll() {
- greetAll("Superman", "SpiderMan")
- },
- sum() {
- sum(10, 20, 40, 100)
- },
- }
- console.log(sample2[prompt("Введите название задания")]());
-
-
- </script>
- </body>
- </html>
|