본문 바로가기

ONLINE COURSES/JavaScript13

Basics-1 0. Basics //log to console console.log('hello world '); console.log(123); console.log('true'); var greeting = 'hello'; console.log(greeting); console.log([1,2,3,4,5]); console.log({a:1, b:2}); console.table({a:1, b:2}); console.error('this is some error'); console.clear(); console.warn('this is a warning'); console.time('hello'); console.log('hello world '); console.log(123); console.log('true').. 2021. 6. 12.
Object 객체 { } 1. 객체 { }는 순서에 상관없이 저장되는 데이터들의 모음이다. * 기본형식* var 객체명 = { 'key1' : 'value1' , 'key2' : 'value2' , 'key3' : 'value3' }; : 을 기준으로 앞에 있는것은 "Key" / 뒤에오는 것은 "Value" 이다. 키-밸류의 구분은 ,(콤마)로 한다. // fruit라는 이름의 객체를 만든다. var fruit = { 'A':'apple', 'B':'banana', 'C':'croissant'}; 2. 만든 객체를 출력하기. document.write(객체명.지정된 key이름) ※ key이름에 따옴표 쓰지않음에 주의. var fruit = { 'A':'apple', 'B':'banana', 'C':'croissant'}; doc.. 2021. 5. 31.
Function / Parameter & Argument 1. function 함수명 ( ) {반복하고자 하는 코드} document.write('A'); document.write('B'); document.write('C'); document.write('A'); document.write('B'); // A와B 출력되는 코드를 반복하고자 한다. function AB() { document.write('A'); document.write('B'); } document.write('C'); AB(); // => function 으로 함수값을 지정해 함수명() 만으로 간단화할 수 있다. 2. Parameter : 매개변수 Argument : 인자 function sum(x,y) // 여기서 x,y 가 parameter(매개변수) { document.write(.. 2021. 5. 30.
조건문, 반복문while을 활용해 화면모드 바꾸기 1. night이 적힌 버튼을 생성한다. 클릭할 시 야간모드 화면이 된다. 2. 마찬가지로 주간모드 3. 조건문을 활용해 버튼 하나로 기능하게 만들 수 있다. # value 값이 night인 버튼을 클릭함 -> if value가 night 라면 -> 야간모드일때의 글자색과 배경화면을 지정하고, 버튼의 value는 day로 변경한다. -> else -> 그렇지 않다면 주간모드의 글자색과 배경화면을 지정하고 버튼의 value는 night로 바꾼다. ※value값과 주/야간 모드의 스타일은 반대여야 함에 주의. 4. 리팩토링 : 중복을 제거해 깔끔한 코드를 만든다. #document.querySelector('body') => bodytag라는 변수로 지정함. (편의를 위해 앞에 var을 써서 변수임을 나타낼.. 2021. 5. 29.