목록공부/JavaScript (40)
컴퓨터는 잘못이 없다..
[논리연산자] >>논리연산을 왜 쓸까? 아래와 같은 예시를 보자. [아침에 눈을 떴다. 기상할 것인가?] 1. 일어날 시간인지? 2. 화장실이 급하다? 기상여부 --> 두가지 중 한가지가 true이면 일어나야 한다면? 일어날 시간이 true이고 화장실이 급하면(true) 일어나야함 일어날 시간이 false이고 화장실이 급하면(true) 일어나야함 일어날 시간이 true이고 화장실이 급하지 않으면(false) 일어나야함 일어날 시간이 false이고 화장실이 급하지 않으면(false) 안일어나도 된다. [ 점심을 먹어야 한다. ] 1. 점심 시간인지? 2. 배가 고픈지? 기상여부 --> 둘다 true여야 먹는다. 위와 같은 상황을 코딩하기 위해 논리 연산을 사용한다! >>논리연산자 종류 [&&연산자] a &..
[만들 그림판] [그림판 예제 코드] 그림판 1 2 3 4 5 6 7 8 9 10 배경색 지우개 기능 [참고] 1. 여기서 등장하는 x축과 y축 2.casvas영역? 3.rgb
[예제코드] [실행결과] [알아둬야할점!] 1. object 형을 참조하려면 변수가 들어있는 변수명.키값으로 .(dot)으로 참조 가능하다. 반대로 생각해서 .(dot)으로 참조한다면 이건 object type 이다! 라고도 생각할 수 있어야함! 2.object형에 함수가 들어있다면? 변수명.키값 까지만 쓰면 참조 변수명.키값() 까지 쓰면 함수 실행 3. object형에 배열이 들어있다면? 변수명.키값 까지만 쓰면 배열 전체 참조 변수명.키값[인덱스] 까지 쓰면 배열 index별 요소를 참조할 수 있다!
[QUIZ] 아래 20칸의 box를 클릭했을 때 clicked가 나오도록 구현하시오! [hint] 1. for과 foreach 둘다 구현해보기! 2. document.querySelectorAll("div")[i].addEventListener(); 사용하기! 3. this.innerText [정답 코드] EventListener 퀴즈 [코드 해설] 정답1,4 와 정답2,3의 차이? 정답2,3은 외부에서 변수,함수에 접근 가능하다. 정답1,4는 즉시실행함수로 감싸주어 내부 변수,함수에 접근하지 못한다. 실제로 f12를 통해 divs를 눌러봐도 보지 못함!