|
@@ -0,0 +1,156 @@
|
|
|
+<!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>Document</title>
|
|
|
+</head>
|
|
|
+<body>
|
|
|
+ <script>
|
|
|
+//A
|
|
|
+ function a(text){
|
|
|
+ return alert(text)
|
|
|
+ }
|
|
|
+ function aSample(){
|
|
|
+ a("Привет!") // вызывает alert("Привет!")
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+//CUBE
|
|
|
+ function cube(num){
|
|
|
+
|
|
|
+ return num*num*num
|
|
|
+ }
|
|
|
+
|
|
|
+ function cubeSample(){
|
|
|
+ console.log("input: 5; output: "+cube(5)) // => 125
|
|
|
+ }
|
|
|
+
|
|
|
+//AVG2
|
|
|
+
|
|
|
+ function avg2(a,b){
|
|
|
+
|
|
|
+ return (a + b) / 2
|
|
|
+ }
|
|
|
+
|
|
|
+ function avg2Sample(){
|
|
|
+ console.log("input: 1,2; output: "+avg2(1,2)) // возвращает 1.5
|
|
|
+ console.log("input: 10,5; output: "+avg2(10,5)) // возвращает 7.5
|
|
|
+ }
|
|
|
+
|
|
|
+//SUM3
|
|
|
+
|
|
|
+ function sum3(num1 =0,num2=0,num3=0){
|
|
|
+
|
|
|
+ return num1+num2+num3
|
|
|
+ }
|
|
|
+
|
|
|
+ function sum3Sample(){
|
|
|
+ console.log("input: 1,2,3; output: "+sum3(1,2,3)) // => 6
|
|
|
+ console.log("input: 5,10,100500; output: "+sum3(5,10,100500)) // => 100515
|
|
|
+ console.log("input: 5,10; output: "+sum3(5,10)) // => 15
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+//INTRANDOM
|
|
|
+ function intRandom(a,b){
|
|
|
+
|
|
|
+ if(!b){
|
|
|
+ b=a
|
|
|
+ a=0
|
|
|
+ }
|
|
|
+ return(Math.round(Math.random()*(b-a)+a))
|
|
|
+ }
|
|
|
+
|
|
|
+ function intRandomSample(){
|
|
|
+ console.log("input: 2,15; output: "+ intRandom(2,15)) // возвращает целое случайное число от 2 до 15 (включительно)
|
|
|
+ console.log("input: -1,-1; output: "+intRandom(-1,-1)) // вернет -1
|
|
|
+ console.log("input: 0,1; output: "+intRandom(0,1)) // вернет 0 или 1
|
|
|
+ console.log("input: 10; output: "+intRandom(10)) // вернет 0 до 10 включительно
|
|
|
+ }
|
|
|
+
|
|
|
+//GREETALL
|
|
|
+
|
|
|
+
|
|
|
+ function greetAll(...params){
|
|
|
+
|
|
|
+ let str = "Hello"
|
|
|
+ for(let el of params){
|
|
|
+ str += params.indexOf(el) ===0 ? ` ${el}` : `, ${el}`
|
|
|
+ }
|
|
|
+ alert(str)
|
|
|
+ }
|
|
|
+
|
|
|
+ function greetAllSample(){
|
|
|
+ console.log("input: Superman; output: "+greetAll("Superman"))
|
|
|
+ console.log("input: Superman, SpiderMan; output: "+greetAll("Superman", "SpiderMan"))
|
|
|
+ console.log("input: Superman, SpiderMan, Captain Obvious; output: "+greetAll("Superman", "SpiderMan", "Captain Obvious"))
|
|
|
+ }
|
|
|
+
|
|
|
+//SUM
|
|
|
+
|
|
|
+ function sum(...params){
|
|
|
+
|
|
|
+ let sum = 0
|
|
|
+ for(let num of params){
|
|
|
+ sum+= +num
|
|
|
+ }
|
|
|
+ return sum
|
|
|
+ }
|
|
|
+ function sumSample(){
|
|
|
+ console.log("input: 1; output: "+sum(1))
|
|
|
+ console.log("input: 2; output: "+sum(2))
|
|
|
+ console.log("input: 10,20,40,100; output: "+sum(10,20,40,100))
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+//UNION
|
|
|
+ for(;;){
|
|
|
+ let task = prompt("Введите название задания")?.toUpperCase()
|
|
|
+ if(!task){
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ switch (task){
|
|
|
+ case "A": aSample()
|
|
|
+ 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
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+//UNION DECLARATIVE
|
|
|
+ // let tasks = {
|
|
|
+ // "A": aSample,
|
|
|
+ // "CUBE": cubeSample,
|
|
|
+ // "AVG2": avg2Sample,
|
|
|
+ // "SUM3": sum3Sample,
|
|
|
+ // "INTRANDOM": intRandomSample,
|
|
|
+ // "GREETALL": greetAllSample,
|
|
|
+ // "SUM": sumSample
|
|
|
+ // }
|
|
|
+
|
|
|
+ // for(;;){
|
|
|
+ // let task = prompt("Введите название задания")?.toUpperCase()
|
|
|
+ // if(!task){
|
|
|
+ // break;
|
|
|
+ // }
|
|
|
+ // tasks[task]()
|
|
|
+
|
|
|
+ // }
|
|
|
+
|
|
|
+ </script>
|
|
|
+</body>
|
|
|
+</html>
|