123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156 |
- <!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>
- function a(text){
- return alert(text)
- }
- function aSample(){
- a("Привет!")
- }
- function cube(num){
- return num*num*num
- }
- function cubeSample(){
- console.log("input: 5; output: "+cube(5))
- }
- function avg2(a,b){
- return (a + b) / 2
- }
- function avg2Sample(){
- console.log("input: 1,2; output: "+avg2(1,2))
- console.log("input: 10,5; output: "+avg2(10,5))
- }
- 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))
- console.log("input: 5,10,100500; output: "+sum3(5,10,100500))
- console.log("input: 5,10; output: "+sum3(5,10))
- }
- 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))
- console.log("input: -1,-1; output: "+intRandom(-1,-1))
- console.log("input: 0,1; output: "+intRandom(0,1))
- console.log("input: 10; output: "+intRandom(10))
- }
- 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"))
- }
- 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))
- }
- 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
- }
- }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- </script>
- </body>
- </html>
|