[Vanilla JS]노마드 코더 #1 Theory에서 배운 것

2021. 1. 8. 16:58Vanilla JAVA SCRIPT

1. CSS

(1) 파일 만들기: index.css(index는 임의의 이름)

 

 

 

 

(2) html 파일에 배경색을 꾸미는 css 파일 적용시키기

<head>

  <link rel = "stylesheet" href = "index.css"/>

</head>

 

index.css에 작성한 코드가 해당 html 파일에 적용된다.

 

 

 

 

(3) index.css에서 웹페이지 배경색 지정하기

body {

  background-color = peru;    //갈색

}

 

 

 

 

(4) 글씨 색깔 지정하기

예시

웹페이지에서 위의 "This works!"의 글자 색을 변경해보자(index.css)

h1 {

  color: white;    //흰색

}

 

 

 

 

(5) 적용된 웹페이지

 

 

 

 

2. Array 생성

문법 예시

const daysOfWeeks = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];

 

인덱스 번호가장 왼쪽부터 0에서 시작하여 1씩 증가된다.

daysOfWeeks[2] = Wed

 

 

 

 

3. Object 생성

문법 예시

const nicoInfo = {

  name: "Nico",

  age: 33,

  gender: "Male"

  isHandsome: true,

  favMocies: ["Along the gods", "LOTR", "Oldboy"],

  //Object 안에 array가 오는 것이 가능하다.

  favFood: [{name: "Kimchi", fatty: false}, {name: "Cheese burger", fatty: true}]

  //Object 안에 array가 오고, 그 요소로 다시 Object가 오는 것도 가능하다.

}

 

 

Object는 내용을 호출하는 방법이 array와는 다르다.

예시

console.log(nicoInfo.name);    //Nico

console.log.(nicoInfo.favMovies[2]);    //Oldboy

console.log.(nicoInfo.favFood[0].name);    //Kimchi