Nastaliya 5 vuotta sitten
vanhempi
commit
7a2a9e9b3f
1 muutettua tiedostoa jossa 144 lisäystä ja 0 poistoa
  1. 144 0
      HW14_Nechiporuck.html

+ 144 - 0
HW14_Nechiporuck.html

@@ -0,0 +1,144 @@
+<!DOCTYPE html>
+<html lang="en">
+<head>
+  <meta charset="UTF-8">
+  <meta name="viewport" content="width=device-width, initial-scale=1.0">
+  <meta http-equiv="X-UA-Compatible" content="ie=edge">
+  <title>Document</title>
+  <style type="text/css">
+    label{
+      display: inline-block;
+      width:80px;
+      margin-top: 15px;
+    }
+    input{
+      margin-top: 15px;
+    }
+  </style>
+</head>
+<body>
+  <select id="citySelect"></select>
+    <form action="#">
+      <div id="myDiv">
+        <label for="name"> Login: </label>
+        <input type="text" name="Name" placeholder="Enter your Login" id="name">
+      <br>
+        <label for="password"> Password: </label>
+        <input type="password" name="password" placeholder="Enter your password" id="password">
+    <br>
+     <!-- button -->
+        <input type="button" name="Login"  value="Login" onclick="ClickLogin()">
+      </div>
+    </form>
+    <script type="text/javascript">
+      
+//1. a
+function a(text){
+    alert(text)
+}
+a("Привет!") // вызывает alert("Привет!")
+
+//2. cube
+function cube(number){
+    return number*number*number
+}
+
+//3. avg2
+//напишите функцию тут
+avg2(1,2) // возвращает 1.5
+avg2(10,5) // возвращает 7.5
+function avg2(a,b) {
+    return (a + b) / 2
+}
+
+//4. sum3
+sum3(1,2,3) // => 6
+sum3(5,10,100500) // => 100515
+sum3(5,10) // => 15
+function sum3(a,b,c=0){
+    return a+b+c
+}
+
+//5. intRandom
+intRandom(2,15) // возвращает целое случайное число от 2 до 15 (включительно)
+intRandom(-1,-1) // вернет -1
+intRandom(0,1) // вернет 0 или 1
+intRandom(10) // вернет 0 до 10 включительно
+function intRandom(first = 0, second = 0){
+  result = Math.round(Math.random()*(second-first))+first  
+  return result
+}
+
+//6. greetAll
+greetAll("Superman") // выводит alert "Hello Superman"
+greetAll("Superman", "SpiderMan") // выводит alert "Hello Superman, SpiderMan"
+greetAll("Superman", "SpiderMan", "Captain Obvious") // выводит alert "Hello Superman, SpiderMan, Captain Obvious"
+function greetAll(){
+    str = "Hello"
+    var count=1
+    for (var name of arguments){
+        str += (count ===1 ? " ":", ") + name
+        count +=1
+    }
+    alert(str)
+}
+
+//7. sum
+sum(1) // => 1
+sum(2) // => 2
+sum(10,20,40,100) // => 170
+function sum(){
+    var result=0
+    for (var argument of arguments){
+       result += argument 
+    }
+    return result
+}
+
+//8. Union
+var sample = prompt("Введите название задания")
+switch (sample.toLowerCase()){
+    case "a": a(prompt("Введите текст"))
+              break
+    case "cube": cube(+prompt("Введите число"))
+              break
+    case "avg2": avg2(+prompt("Введите число1"),+prompt("Введите число2"))
+              break
+    case "sum3": sum3(+prompt("Введите число1"),+prompt("Введите число2"),+prompt("Введите число3"))
+              break
+    case "intrandom": intRandom(+prompt("Введите нижнюю границу"),+prompt("Введите верхнюю границу"))
+              break
+    case "greetall":  { var arg = []
+                do{str = prompt('Введите имя')    
+                   arg.push(str)
+              }
+              while (str)   
+              greetAll(arg)
+              break}
+    case "sum": 
+              { var arg = []
+                do{str = +prompt('enter number')    
+                   arg.push(str)
+              }
+              while (str)
+              sum(arg) 
+              break}                                     
+}
+
+//9. Union declarative
+      var tasks = {a:a(),
+                   cube : cube(),
+                   avg2 : avg2(),
+                   sum3 :sum3(), 
+                   intrandom :intRandom() ,
+                   greetall :greetAll() ,
+                   sum :sum() 
+                 }
+var sample = prompt("Введите название задания")
+if (sample in tasks){
+  tasks[sample]
+}
+
+    </script>
+</body>
+</html>