Browse Source

Функции 1

Vladislav342 2 years ago
parent
commit
14776c61a4
1 changed files with 142 additions and 0 deletions
  1. 142 0
      HW_05/index.html

+ 142 - 0
HW_05/index.html

@@ -0,0 +1,142 @@
+<!DOCTYPE html>
+<html>
+<head>
+	<meta charset="utf-8">
+	<title></title>
+</head>
+<body>
+
+	<script>
+		
+//------a
+		function a(word){
+			alert(word);
+		}
+
+		function sSample(){
+			a('Hello');
+		}
+		
+
+//------cube
+		function cube(x){
+			alert(x*x*x);
+		}
+
+		function cubeSample(){
+			cube(3);
+		}
+		
+
+//------avg2
+		function avg2(a,b){
+			alert((a+b)/2);
+		}
+
+		function avg2Sample(){
+			avg2(1,2);
+		}
+
+//------sum3
+		function sum3(a=0,b=0,c=0){
+			alert(a+b+c);
+		}
+
+		function sum3Sample(){
+			sum(1,2)
+		}
+
+//------intRandom
+		function intRandom(a=0,b=0){
+			let rand=a+Math.random()*(b+1-a);
+			console.log(Math.floor(rand));
+		}
+
+		function intRandomSample(){
+			intRandom(10)
+		}
+
+//------greetAll
+		function greetAll(...who){
+			/*for(let i=0;i<arguments.length;i++){
+				alert('Hello,'+arguments[i]);
+			}*/
+			alert('Hello,'+who);
+		}
+
+		function greetAllSample(){
+			greetAll('Superman','Spider-man');
+		}
+		
+
+//------sum
+		function sum(){
+			let res=0;
+			for(let i=0;i<arguments.length;i++){
+				res+=arguments[i];
+			}
+			alert(res);
+		}
+
+		function sumSample(){
+			alert(sum(1,2,3,4,5));
+		}
+	
+
+//------Union
+		/*let sample=prompt('Введите название задания','');
+		switch(sample.toLowerCase()){
+			case'a':aSample();
+					break;
+			case 'cube':cubeSample();
+						break;
+			case 'avg2':avg2Sample();
+						break;
+			case 'sum3':sum3Sample();
+						break;
+			case 'intrandom':intRandom();
+							 break;
+			case 'greetall':greetAllSample();
+							break;
+			case 'sum':sumSample();
+						break;
+		}	*/
+
+//------Union declarative
+		let obj={
+			a:function(word=prompt('Введите слово','')){
+				a(word);
+			},
+			cube:function(num=+prompt('Введите число','')){
+				cube(num);
+			},
+			avg2:function(num1=+prompt('Введите первое число',''),num2=+prompt('Введите второе число','')){
+				avg2(num1,num2);
+			},
+			sum3:function sum3Sample(num1=+prompt('Введите первое число',''),num2=+prompt('Введите второе число',''),num3=+prompt('Введите третье число','')){
+			sum(num1,num2,num3);
+			},
+			intrandom:function(num1=+prompt('min',''),num2=+prompt('max','')){
+				intRandom(num1,num2);
+			},
+			greetall:function(who=prompt('Введите имя (имена)')){
+				greetAll(who);
+			}
+		};
+
+		let key=prompt('Введите название функции','');
+
+		for(let item in obj){
+			if(item.toLowerCase()==key.toLowerCase()){
+				obj[item]();
+			}
+		}
+
+		
+
+
+
+	</script>
+
+</body>
+</html>