Browse Source

Merge branch 'master' of http://gitlab.a-level.com.ua/VadymShakhmatenko/homework

Vadym Shakhmatenko 1 year ago
parent
commit
71ec653f13

BIN
.DS_Store


+ 254 - 0
Homework OOP/index.html

@@ -0,0 +1,254 @@
+<!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>
+//Password
+        // function Password(parent, open){
+        //     //const value = ''
+        //     const pass = document.createElement('input')
+        //     const check = document.createElement('input')
+        //     check.type = 'checkbox'
+        //     parent.append(pass , check)
+
+        //     check.onchange = () => {
+        //         this.setOpen(check.checked)
+        //     }
+
+        //     pass.oninput = () => {
+        //         this.value = pass.value;
+        //         if(typeof this.onchange === 'function'){
+        //             this.onchange(this.value)
+        //         }
+        //     }
+
+        //     this.getValue = function () {
+        //         return this.value
+        //     }
+
+        //     this.setValue = function(value){
+        //         this.value = value;
+        //         pass.value = this.value
+        //     }
+            
+        //     this.setOpen = function (newOpen) {
+        //         open = newOpen
+        //         pass.type = open ? 'text' : 'password'
+        //         check.checked = open
+
+        //         if(typeof this.onOpenChange === 'function') {
+        //         this.onOpenChange(open)
+        //         }
+        //     }
+
+        //     this.getOpen = function () {
+        //         return open 
+        //     }
+
+        //     this.setOpen(open)
+
+        // }
+
+        // let p = new Password(document.body, false)
+
+        // p.onChange = data => console.log(data)
+        // p.onOpenChange = open => console.log(open)
+
+        // p.setValue('qwerty')
+        // console.log(p.getValue())
+
+        // // p.setOpen(false)
+        // console.log(p.getOpen())
+
+
+//LoginForm
+    //    function LoginForm(parent, open){
+    //         const formBody = document.createElement('div')
+    //         const pass = document.createElement('input')
+    //         const login = document.createElement('input')
+    //         const check = document.createElement('input')
+    //         const btn = document.createElement('button')
+
+    //         check.type = 'checkbox'
+    //         login.type = 'text'
+    //         btn.innerHTML = 'submit'
+    //         parent.append(formBody)
+    //         formBody.append(login , pass , check , btn)
+
+    //         check.onchange = () => {
+    //             this.setOpen(check.checked)
+    //         }
+
+    //         pass.oninput = () => {
+    //             this.value = pass.value;
+    //             btn.disabled = checkInputs();
+    //             if(typeof this.onchange === 'function'){
+    //                 this.onchange(this.value)
+    //             }
+    //         }
+    //         this.setLoginValue = (value) => {
+    //             this.loginValue = value
+    //             login.value = this.loginValue
+    //         }
+    //         this.getLoginValue = () => {
+    //             return this.loginValue
+    //         }
+
+    //         const checkInputs = () => {
+    //             if(login.value.length === 0 ||  this.value.length === 0 ) {
+    //                 return true;
+    //             }
+    //             return false;
+    //         }
+
+    //         this.getValue = function () {
+    //             return this.value
+    //         }
+
+    //         this.setValue = function(value){
+    //             this.value = value;
+    //             pass.value = this.value
+    //         }
+            
+    //         this.setOpen = function (newOpen) {
+    //             open = newOpen
+    //             pass.type = open ? 'text' : 'password'
+    //             check.checked = open
+
+    //             if(typeof this.onOpenChange === 'function') {
+    //             this.onOpenChange(open)
+    //             }
+    //         }
+
+    //         this.getOpen = function () {
+    //             return open 
+    //         }
+
+    //         this.setOpen(open)
+
+    //         btn.disabled = checkInputs();
+    //     }
+
+    //     let lf = new LoginForm(document.body, false)
+
+    //     lf.onChange = data => console.log(data)
+    //     lf.onOpenChange = open => console.log(open)
+
+    //     lf.setValue('qwerty')
+    //     console.log(lf.getValue())
+
+    //     lf.setLoginValue('qwerty')
+    //     console.log(lf.getLoginValue())
+
+    //     // lf.setOpen(false)
+    //     console.log(lf.getOpen())
+
+
+//Password Verify
+       function PasswordCheck(parent, open){
+            const formBody = document.createElement('div')
+            const pass1 = document.createElement('input')
+            const pass2 = document.createElement('input')
+            const check = document.createElement('input')
+            const btn = document.createElement('button')
+
+            check.type = 'checkbox'
+            
+            btn.innerHTML = 'пароли совпадают'
+            parent.append(formBody)
+            formBody.append(pass2 , pass1 , check , btn)
+
+            check.onchange = () => {
+                this.setOpen(check.checked)
+            }
+
+            pass1.oninput = () => {
+                this.value = pass1.value;
+                btn.disabled = !validator();
+                if(typeof this.onchange === 'function'){
+                    this.onchange(this.value)
+                }
+            }
+
+            pass2.type = 'password'
+            pass2.style.display = !open ? 'inline' : 'none';
+            pass2.oninput = () => {
+                this.value2 = pass2.value
+                btn.disabled = !validator();
+            }
+
+            const validator = () => {
+                if (open === true) {
+                        return false;
+                    }
+                    if (this.value === this.value2 && pass1.value !== "" && this.value2) {
+                        console.log('correct password')
+                        return  true;
+                    }
+                    return false;
+                };
+
+            this.setValue = function(value){
+                this.value = value;
+                pass1.value = this.value
+                btn.disabled = !validator();
+            }
+
+            this.setPass2Value = (value) => {
+                this.pass2 = value
+                pass2.value = this.pass2
+                btn.disabled = !validator();
+            }
+
+            this.getValue = () => {
+                return this.value
+            }
+
+            this.getPass2Value = () => {
+                return this.pass2
+            }
+
+            this.setOpen = function (newOpen) {
+                open = newOpen
+                pass1.type = open ? 'text' : 'password'
+                pass2.style.display = !open ? "inline" : "none";
+                 btn.disabled = !validator();
+                check.checked = open
+                if(typeof this.onOpenChange === 'function') {
+                this.onOpenChange(open)
+                }
+            }
+
+            this.getOpen = function () {
+                return open 
+            }
+
+            this.setOpen(open)
+
+            btn.disabled = validator();
+        }
+
+        let pc = new PasswordCheck(document.body, false)
+        
+        pc.onOpenChange = open => console.log(open);
+
+        pc.setValue('')
+        // console.log(pc.getValue())
+
+        pc.setPass2Value('')
+        // console.log(pc.getPass2Value())
+
+        // pc.setOpen(false)
+        // console.log(pc.getOpen())
+  
+    </script>
+    
+</body>
+</html>

+ 74 - 0
Homework-Redux/index.html

@@ -0,0 +1,74 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <meta charset="utf-8" />
+        <meta name="viewport" content="width=device-width" />
+        <title>Другой тайтл ПРИВЕТ 17й</title>
+    </head>
+    <style>
+        .wrapper{
+            display: flex;
+            justify-content: space-between;
+            background-color: silver;
+        }
+        .content{
+            display: flex;
+            flex-wrap: wrap;
+            justify-content: center;
+            margin-top: 50px;
+        }
+        #stock{
+            display: flex;
+            font-size: 20px;
+        }
+        #product{
+            margin: 0.2%;
+            padding: 50px;
+            font-size: 15px;
+        }
+        .text{
+            display: flex;
+        }
+
+        #product:last-child{
+            display: none;
+        }
+        #buy{
+            margin: 20px;
+            padding: 20px 50px;
+        }
+        #total{
+            width: 200px;
+            height: 50px;
+            font-size: 20px;
+            margin-top: 1%;
+            color: red;
+        }
+    </style>
+    <body> 
+        <div class="wrapper">
+            <h1>Laryok Keeper</h1>
+            <button id="total">КАСА</button>
+        </div>
+        
+        
+        <div class="content" id = 'content'>
+        </div>
+
+        <div class="text" id="text">
+
+        </div>
+
+        <h1>Наявність: </h1>
+        <div class="stock_box" id="stock"></div>
+
+        <div class="buy_content" id="buy_content">
+            
+            <button class="button" id="buy">СПЛАТИТИ</button>
+        </div>
+        
+        
+
+        <script src='index.js'></script>
+    </body>
+</html>

+ 140 - 0
Homework-Redux/index.js

@@ -0,0 +1,140 @@
+
+function reducer(state, {type, ШО, СКОКА }){ //объект action деструктуризируется на три переменных
+    if (!state){ //начальная уборка в ларьке:
+        return {
+            пиво: {storage : 100 , price: 65},
+            чипсы: {storage: 145 , price: 120},
+            сиги: {storage : 220 , price: 75.50},
+            горілка: {storage : 140 , price: 200.50},
+            корсары: {storage : 330 , price: 15.50},
+            чупа_чупс: {storage : 220 , price: 14.50},
+            вино_777: {storage : 220 , price: 14.50},
+            касса: 0
+        }
+        
+    }
+     
+    if(type === 'ВЫБОР'){
+        if(СКОКА <= 0 || СКОКА > state[ШО].storage){
+            return state;
+        }return{
+            ...state, 
+            касса: +state.касса + (СКОКА * state[ШО].price),
+        }
+    }
+    if (type === 'КУПИТЬ'){
+            if(state[ШО].storage >= СКОКА){
+                state[ШО].storage = state[ШО].storage - СКОКА
+            }return {
+                ...state 	 
+            }
+    } 
+    if(type === 'ТРАНЗАКЦИЯ'){
+        if(state.касса >= 0){
+            return{
+                ...state,
+                касса : state.касса * 0,
+            }
+        }
+    }
+   
+    return state //если мы не поняли, что от нас просят в `action` - оставляем все как есть
+}
+
+const store = createStore(reducer)
+console.log(store.getState())
+
+function createStore(reducer){
+    let state       = reducer(undefined, {}) //стартовая инициализация состояния, запуск редьюсера со state === undefined
+    let cbs         = []                     //массив подписчиков
+    
+    const getState  = () => state            //функция, возвращающая переменную из замыкания
+    const subscribe = cb => (cbs.push(cb), () => cbs = cbs.filter(c => c !== cb)) //возвращаем функцию unsubscribe, которая удаляет подписчика из списка
+                             
+    const dispatch  = action => { 
+        const newState = reducer(state, action) //пробуем запустить редьюсер
+        if (newState !== state){ //проверяем, смог ли редьюсер обработать action
+            state = newState //если смог, то обновляем state 
+            for (let cb of cbs)  cb() //и запускаем подписчиков
+        }
+    }
+    return {
+        getState, //добавление функции getState в результирующий объект
+        dispatch,
+        subscribe //добавление subscribe в объект
+    }
+}
+   
+for(let [key, value] of Object.entries(store.getState())){
+        let div = document.getElementById('content')
+        let btn = document.createElement('button')
+        var text = document.getElementById('text')
+        let stock = document.getElementById('stock')
+        let sklad = document.createElement('div')
+            sklad.style.backgroundColor = 'silver'
+            sklad.style.display = 'flex'
+        
+        let btn1 = document.createElement('div')
+        let buy = document.getElementById('buy')
+        stock.append(sklad)
+        // document.body.append(sklad)
+        text.append(btn1)
+        div.append(btn)
+
+
+    console.log(key,value)
+    btn.id = 'product'
+    
+    btn.innerHTML = `${key} (${value.price + "грн"})`
+
+    btn.onclick = () => {
+        store.dispatch({type: 'КУПИТЬ', ШО: key, СКОКА: 1})
+        store.dispatch({type: 'ВЫБОР' , ШО : key , СКОКА: 1})
+        console.log(store.getState())
+    }
+     
+    buy.onclick = () => {
+
+    let div = document.createElement('div')
+    let content = document.getElementById('buy_content')
+    
+    var allMoney = `${store.getState().касса}`
+    var result = Number(allMoney) 
+    moneyStorage.push(result)
+    arraySum(moneyStorage)
+    console.log(moneyStorage)
+
+    content.append(div)
+       div.innerHTML = `Транзакция ${Date()}: ${store.getState().касса} грн`
+    
+       store.dispatch({type: 'ТРАНЗАКЦИЯ', ШО: 'касса', СКОКА: 0})
+       store.dispatch({type: 'КАССА', ШО: 'касса', СКОКА: 0})
+        console.log(store.getState())
+    }
+
+   store.subscribe(()=> sklad.innerHTML = '/' + ` ${key} ${value.storage} шт.` + ' ' );
+
+    let moneyStorage = []
+
+    function arraySum(array){
+        var money = document.getElementById('total')
+
+        var sum = 0;
+        for(var i = 0; i < array.length; i++){
+            sum += array[i];
+            }
+            money.innerText = sum + " грн";
+        }
+}
+
+function casa(){
+    const h1 = document.createElement('h1');
+    h1.id = 'change'
+    h1.style.color = 'red'
+    text.append(h1);
+    store.subscribe(() => h1.innerText = `До сплати: ${store.getState().касса} грн`);
+    h1.innerText = `До сплати:${store.getState().касса}`;
+}
+casa();
+
+

BIN
Homework-rgb/1@3x.png


BIN
Homework-rgb/audio_file.mp3


+ 18 - 0
Homework-rgb/index.html

@@ -0,0 +1,18 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <meta charset="utf-8" />
+        <meta name="viewport" content="width=device-width" />
+        <title>Другой тайтл ПРИВЕТ 17й</title>
+        <style>
+            #container1 {
+                padding: 400px;
+            }
+        </style>
+    </head>
+    <body>
+        <div id='container1'></div>
+        <script src='index.js'></script>
+    </body>
+</html>
+

+ 115 - 0
Homework-rgb/index.js

@@ -0,0 +1,115 @@
+function Control(
+    el,
+    {   value = 0, 
+        min = 0,
+        max = 100,
+        minAngle = 0, 
+        maxAngle = 360, 
+        wheelSpeed = 0.05, 
+        step = 1 
+    } = {}
+) {
+    const img = document.createElement("img");
+    img.src = "1@3x.png";
+    el.append(img);
+
+    const ratio = (maxAngle - minAngle) / (max - min);
+    const getAngle = () => (value - min) * ratio + minAngle;
+
+    this.setValue = (newValue) => {
+        if (newValue > max) newValue = max;
+        if (newValue < min) newValue = min;
+
+        if (typeof this.onchange === "function" && newValue !== value) this.onchange(newValue);
+
+        value = newValue;
+
+        img.style.transform = `rotate(${getAngle()}deg)`;
+    };
+
+    img.onmousewheel = (e) => {
+        const { deltaY } = e;
+        //console.log(deltaY)
+        this.setValue(value + deltaY * wheelSpeed);
+        e.preventDefault();
+    };
+
+    img.onclick = (e) => {
+        const { layerX } = e;
+        if (layerX < img.width / 2) this.setValue(value - step);
+        else this.setValue(value + step);
+        e.preventDefault();
+    };
+
+    const e2deg = (e) => {
+        const { layerX, layerY } = e;
+        const { width, height } = img;
+        const x = layerX - width / 2;
+        const y = height / 2 - layerY;
+
+        //console.log(x, y, width, height)
+
+        return ((Math.atan2(y, x) / (2 * Math.PI)) * 360 + 360) % 360;
+    };
+
+    let prevAngle = null;
+
+    img.onmousedown = (e) => {
+        prevAngle = e2deg(e);
+    };
+
+    img.onmousemove = (e) => {
+        if (prevAngle === null) return;
+
+        const currentAngle = e2deg(e);
+        const deltaValue = (prevAngle - currentAngle) / ratio;
+        //console.log(prevAngle - currentAngle, deltaValue)
+        this.setValue(value + deltaValue);
+        prevAngle = currentAngle;
+        e.preventDefault();
+    };
+
+    img.onmouseup = (e) => {
+        prevAngle = null;
+    };
+    img.onmouseleave = (e) => {
+        prevAngle = null;
+    };
+
+    this.setValue(value);
+    this.getValue = () => value;
+}
+
+function setRGB() {
+    document.body.style.backgroundColor = `rgba(${red.getValue()},${green.getValue()},${blue.getValue()},1)`;
+}
+
+const red = new Control(container1, { min: 0, max: 255 });
+red.onchange = setRGB;
+const green = new Control(container1, { min: 0, max: 255 });
+green.onchange = setRGB;
+const blue = new Control(container1, { min: 0, max: 255 });
+blue.onchange = setRGB;
+
+const audio = document.createElement("audio");
+audio.id = "audio1";
+audio.src = "audio_file.mp3";
+audio.controls = true;
+container1.append(audio);
+
+const volumeControl = new Control(container1, {
+    value: 0.1,
+    min: 0,
+    max: 1,
+    step: 0.02,
+    wheelSpeed: 0.0002,
+});
+volumeControl.onchange = () => {
+    audio.volume = volumeControl.getValue();
+    console.log(volumeControl.getValue());
+};
+audio.volume = volumeControl.getValue();
+console.log(volumeControl.getValue());
+
+
+

+ 8 - 0
Homework-rgb/workspace.code-workspace

@@ -0,0 +1,8 @@
+{
+	"folders": [
+		{
+			"path": ".."
+		}
+	],
+	"settings": {}
+}

+ 4 - 4
Homework9/index.html

@@ -20,7 +20,7 @@
                 }
                 return adder
             }
-            // console.log(timer())
+            console.log(timer())
 
 
 
@@ -40,9 +40,9 @@
 
         let namePrompt = prompt.bind(window, 'Как тебя зовут?')
         let nameSaver = makeSaver(namePrompt)
-        // alert(`Привет! Prompt еще не было!`)
-        // alert(`Привет ${nameSaver()}. Только что запустился prompt, первый и последний раз`)
-        // alert(`Слушай, ${nameSaver()}, го пить пиво. Ведь prompt был только один раз`)
+        alert(`Привет! Prompt еще не было!`)
+        alert(`Привет ${nameSaver()}. Только что запустился prompt, первый и последний раз`)
+        alert(`Слушай, ${nameSaver()}, го пить пиво. Ведь prompt был только один раз`)
 
         function makeSaver(x){
                 let count = 0;