Browse Source

homework 5 and 6

kurkabein 2 years ago
parent
commit
244f5e7172
4 changed files with 168 additions and 0 deletions
  1. 12 0
      homework_5_functions/index.html
  2. 67 0
      homework_5_functions/main.js
  3. 16 0
      homework_6_dom/index.html
  4. 73 0
      homework_6_dom/main.js

+ 12 - 0
homework_5_functions/index.html

@@ -0,0 +1,12 @@
+<!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 src="main.js"></script>
+</body>
+</html>

+ 67 - 0
homework_5_functions/main.js

@@ -0,0 +1,67 @@
+ function a (text="called function alert") {
+    alert(text);
+}
+/* a("hello"); */ 
+
+/* function cube (number) {
+    return number **3;
+}
+
+a(cube(3)); */
+
+/* function avg(a,b){
+    return ((a+b)/2);
+}
+
+a(avg(1,2));
+a(avg(10,5)); */
+
+
+/* function sum3 (a=0,b=0,c=0) {
+    return a+b+c;
+}
+
+a(sum3(1,2,3));
+a(sum3(5,10,100500));
+a(sum3(10,5)); */
+
+
+/* function intRandom (min,max=0) {
+    if(max == 0 ){
+        return Math.floor(Math.random()* (min-max+1))+max;
+    }
+    return Math.floor(Math.random()* (max-min+1))+min;
+}
+
+a(intRandom(100)); */
+
+/* function greetAll(...names) {
+    let greetArr = [];
+    for(let i = 0 ; i< arguments.length; i++){
+        greetArr.push(names[i]);
+    }
+    alert(greetArr);
+}
+
+greetAll("SPYDIK","KYRKA","VETAL"); */
+
+function sum(...numarr){
+    /* let result=0;
+    for(let i =0; i<arguments.length;i++){
+         debugger;
+        result=result+arguments[i];
+    }
+    alert(result); */
+    let arrforsum = [];
+    for(let i = 0; i<arguments.length; i++){
+        arrforsum.push(numarr[i]);
+    }
+    let sum = 0 ;
+    for(let i =0; i<arrforsum.length;i++){
+        sum=sum+arrforsum[i];
+    }
+    alert(sum);
+    /* return alert(numarr.reduce((a,b) => a+b)); */
+}
+
+sum(...[10,2,20]);

+ 16 - 0
homework_6_dom/index.html

@@ -0,0 +1,16 @@
+<!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>
+    <input  placeholder="input first number" id="firstNumber">
+    <input  placeholder="input second number" id="secondNumber">
+    <button id="calc">Sum 2 numbers</button>
+    <input placeholder="result" id="result">
+    <script src="main.js"></script>
+</body>
+</html>

+ 73 - 0
homework_6_dom/main.js

@@ -0,0 +1,73 @@
+//multiply table  если поменять обявление колонок то можно будит подсвечивать сразу все ячейки колонки
+
+/* let boddy = document.querySelector('body');
+
+let table = document.createElement('table')
+let tbody = document.createElement('tbody')
+
+
+for(let rowIndex = 1; rowIndex<10; rowIndex++){
+
+    let rows = document.createElement('tr');
+
+    for(let cellIndex = 1; cellIndex<10; cellIndex++){
+            let cell = document.createElement('td');
+            let cellText = document.createTextNode(rowIndex*cellIndex);
+            cell.appendChild(cellText);
+            rows.appendChild(cell);
+            cell.onmouseover = function(event) {
+                event.target.style.background = "silver";
+            }
+            cell.onmouseleave = function(event) {
+                event.target.style.background = "";
+            }
+            
+        }
+    tbody.appendChild(rows);
+    rows.addEventListener("mouseover", function hoverOnRow(){
+        this.style.backgroundColor="green";
+    });
+    rows.addEventListener("mouseleave", function hoverOnRowEnd(){
+        this.style.backgroundColor="";
+    });    
+}
+table.appendChild(tbody);
+boddy.appendChild(table);
+ */
+
+
+/* let sumBtn = document.getElementById('calc'); */
+/* function sumNumbers(a,b) {
+    return a+b;
+} */
+/* sumBtn.addEventListener('click', function sumNumbers(){
+    let firstNumber = +(document.getElementById('firstNumber').value);
+    let secondNumber = +(document.getElementById('secondNumber').value);    
+    return console.log(firstNumber+secondNumber);
+}) */
+
+
+/* document.getElementById('firstNumber').addEventListener('change',calc,false);
+document.getElementById('secondNumber').addEventListener('change',calc,false);
+function calc() {
+    let firstNumber = +(document.getElementById('firstNumber').value);
+    let secondNumber = +(document.getElementById('secondNumber').value);
+    document.getElementById('result').value = firstNumber + secondNumber;
+    
+}
+calc(); */
+
+let  input1 = document.getElementById('firstNumber');
+let  input2 = document.getElementById('secondNumber');
+function calc() {
+    let result = document.getElementById('result');
+
+    result.value = (+input1.value) + (+input2.value)
+
+}
+input1.oninput = calc;
+input2.oninput = calc;
+
+
+
+/* sumNumbers(firstNumber,secondNumber); */