๐จ JavaScript
[์ฝ๋ฉ์ ํ] ์คํฌ๋กค ์ด๋ฒคํธ
์คํฌ๋กค๋ฐ ์์น ์ฐพ๊ธฐ : window.scrollY, window.scrollTop() window.addEventListener('scroll', function(){ console.log(window.scrollY); //window.pageYOffset๊ณผ ๋์ผํ ๊ธฐ๋ฅ(์ด์ชฝ์ด ํธํ์ฑ์ด ๋ ๋จ์ด์ง) }) //jquery๋ฒ์ $(window).on('scroll', function(){ $(window).scrollTop() //(100) ๊ดํธ์์ ์ซ์๋ฅผ ๋ฃ์ผ๋ฉด ํ์ฌ์คํฌ๋กค๋ฐ ์ด๋ }); ๋ ์์๊ฐ๊ธฐ : scrollTop์ ํ์ฌ ์คํฌ๋กค๋ฐ ์ด๋ ๊ธฐ๋ฅ๋ ๊ฒธํ๋ค. ๊ฐ์ ๋ก ๋งจ ์์์๋ถํฐ ์คํฌ๋กคํ๊ธฐ : scrollTo(x,y) window.addEventListener('scroll', function(){ wind..
Level 2 : 1~5 (์์ ๋ฐ ๊นจ๋ฌ์ ์ )_if๋ฌธ
1. 2๋ ํ ๋ฐ์ ์ด์๊ธ์ก ๊ตฌํ๊ธฐ ์กฐ๊ฑด 50000์ ๋ฏธ๋ง: ์ฐ 15% / 50000์ ์ด์ : ์ฐ 20% function depositResult(amount) { const amountOver = amount * 1.2 * 1.2; const amountLess = amount * 1.15 * 1.15; if (amount >= 50000) { console.log(amountOver); } else { console.log(amountLess); } } 2. ์ปคํผ ์ด๋ฆฌํ์ก ๊ตฌํ๊ธฐ ์กฐ๊ฑด ์ปคํผ๋ ์ด 3๋ฒ ๋ฆฌํ๋๋ฉฐ, ์ง์ ๋ง์ ์ปคํผ์ 2/3๋ง ๋ฆฌํ๋๋ค. let first = 360; let total = 0; console.log(first + first * (2/3) + first * (2/3) * (..
Level 1 : 6~12 (์์ ๋ฐ ๊นจ๋ฌ์ ์ )
6. form๊ณผ input ๊ฐ์ด ๋น์์ ๋ ์ผ๋ฟ ๋์ฐ๊ณ submit๋ง๊ธฐ document.querySelector('form').addEventListener('submit', function(e){ if (document.querySelector('input[type=text]').value == '') { alert(`์์ด๋๋ฅผ ์ ๋ ฅํ์ธ์.`); e.preventDefault(); } else { document.querySelector('input[type=text]').submit; }; if (document.querySelector('input[type=password]').value == '') { alert(`๋น๋ฐ๋ฒํธ๋ฅผ ์ ๋ ฅํ์ธ์.`); e.preventDefault(); } else { do..
Level 1 : 1~5 (์์ ๋ฐ ๊นจ๋ฌ์ ์ )
1. ํฐํธ์ฌ์ด์ฆ ๋ณ๊ฒฝํ๊ธฐ document.getElementById('hello').style.fontSize = '16px 2. ์๋ฆผ์ฐฝ ์ด๊ธฐ/๋ซ๊ธฐ let alertBox = document.getElementsByClassName('alert-box'); let openBtn = document.getElementsByClassName('open'); let closeBtn = document.getElementsByClassName('close'); openBtn[0].addEventListener("click", function() { alertBox[0].style.display = "block"; }) closeBtn[0].addEventListener("click", function() { a..
[๋๋ฆผ์ฝ๋ฉ] ์ฝ๋ฐฑํจ์ (4) : ์ฝ๋ฐฑ์ง์ฅ ํ์ถ, Promise (callback hell ์ฝ๋๊ฐ์ ํ๊ธฐ)
Callback Hell ์์ ์ด์ ์๊ฐ์ ๋ง๋ค์๋ ์ฝ๋ฐฑ์ง์ฅ ์์๋ค. // ๊ธฐ๋ณธ์ธํ class UserStorage { loginUser(id, password, onSuccess, onError) { setTimeout(() => { if ( (id === 'master' && password === 'master00') || (id === 'submaster' && password === 'submaster00') ) { onSuccess(id); } else { onError(new Error('not found')); } }, 2000); } getRoles(user, onSuccess, onError) { setTimeout(() => { if (user === 'master') { onSucce..
[๋๋ฆผ์ฝ๋ฉ] ์ฝ๋ฐฑํจ์ (3) : promise๋ก Error Handlingํ๊ธฐ (reject, catch ํ์ฉ)
Error Handling const turnonLaptop = () => new Promise((resolve, reject) => { setTimeout(() => resolve(`๋ ธํธ๋ถ ์คํ.`), 1000); }); const loginBlog = blog => new Promise((resolve, reject) => { setTimeout(() => reject(new Error(`Error! ${blog} => ๋ธ๋ก๊ทธ ์ง์ .`)), 1000); }); const writePost = post => new Promise ((resolve, reject) => { setTimeout(() => resolve(`${post} => ๊ฒ์ ์๋ฃ.`), 1000); }); producer ์ฝ๋๋ฅผ ์์ฑํ..