false
로 큰 따옴표이고, true
로 바꾸면 작은 따옴표를 쓸 수 있다.현재 폴더에 .prettierrc 파일 만들기
객체 작성하기
{
"singleQuote": true,
}
const calcAge = (birthYear) => 2037 - birthYear;
// 위와 같은 JS 파일이 있을때, .prettierrc 파일 안에 아래와 같이 넣으면
// .prettierrc 파일
{
"singleQuote": true,
"arrowParens": "avoid"
}
// 저장하면 괄호가 사라진다.
const calcAge = birthYear => 2037 - birthYear;
snippet은 작은 조각이라는 뜻으로,
코드 스니펫(Code Snippet)은 '코드 조각', 즉 재사용 가능한 소스 코드, 기계어, 텍스트의 작은 부분을 의미한다.
코드를 재사용할 수 있게 해줌으로써 반복 타이핑을 회피할 수 있게 도와준다.
{
// Place your global snippets here. Each snippet is defined under a snippet name and has a scope, prefix, body and
// description. Add comma separated ids of the languages where the snippet is applicable in the scope field. If scope
// is left empty or omitted, the snippet gets applied to all languages. The prefix is what is
// used to trigger the snippet and the body will be expanded and inserted. Possible variables are:
// $1, $2 for tab stops, $0 for the final cursor position, and ${1:label}, ${2:another} for placeholders.
// Placeholders with the same ids are connected.
// Example:
"Print to console": {
"scope": "javascript,typescript",
"prefix": "cl",
"body": ["console.log($1);"],
"description": "Log output to console"
}
}
→ 자바스크립트, 타입스크립트에서 사용된다.
→ cl을 쓰고 엔터를 누르면 console.log()가 생성된다.
→ 커서가 console.log()에서 괄호 안에 들어간다. ( $1을 빼면 맨 끝으로 커서가 지정된다.)
node.js 설치
VSC 터미널에서 live server를 설치한다.
(터미널은 기본적으로 컴퓨터에 지시를 내리는 방식이다.)
VSC 터미널에서 liver server를 실행한다.
- 처음 여정을 시작할 때 명확한 목표가 없다.
→ 구체적이고 측정 가능하며 현실적이며 시간 내에 달성할 수 있는 목표를 설정하세요.
→ 왜 코딩을 배우려고 하는지 정확히 알아보세요: 직업 전환? 더 나은 직장 찾기?
→ 스스로가 만들고 싶은 큰 프로젝트를 상상해 보세요!
→ 필요한 기술을 연구하고 그런 다음 그것들을 배우세요.
- 강의를 시청하고 튜토리얼을 읽기 시작했지만, 코드를 어떻게 작동하는지 신경쓰지 않고 그냥 복사/붙여넣기 한다.
→ 공부하고 있는 코드를 이해하세요.
→ 코드를 직접 입력하고 복사 붙여넣기를 하지 마세요!
- 작은 챌린지들을 통해 배우는 내용을 보강하지 않고, 필기도 하지 않는다.
→ 새로운 기능이나 개념을 배운 후에는 즉시 사용해 보세요.
→ 필기하세요.
→ 스스로 도전하고 작은 코딩 연습과 도전 과제를 통해 연습하세요.
→ 강좌를 빠르게 완료하려고 급하게 하지 마세요!
- 코딩 연습을 하지 않으며, 자신의 프로젝트 아이디어를 떠올리지 않는다.
→ 스스로 연습하는 것이 가장 중요합니다.
→ 이것은 선택사항이 아닙니다! 강좌 이외의 연습 없이는 어떤 발전도 이루지 못할 것입니다!
→ 자체 프로젝트 아이디어를 생각하거나 인기 있는 사이트나 애플리케이션을 모방하거나, 처음에는 그들의 일부분만 복사하세요.
→ "튜토리얼 지옥"에 갇히지 마세요.
- 코드가 완벽하게 깔끔하거나 효율적이지 않을 때 빠르게 좌절감을 느낀다.
→ 완벽한 코드를 작성하려고 노력하다가 갇히지 마세요!
→ 단순히 많은 코드를 작성하세요. 품질은 중요하지 않습니다!
→ 깨끗하고 효율적인 코드는 시간이 지나면서 나타날 것입니다.
→ 코드를 언제든지 리팩토링할 수 있습니다.
- 모든 것을 알 수 없다는 생각에 동기 부여를 잃는다.
→ 결코 모든 것을 알 수 없을 것임을 받아들이세요.
→ 목표를 달성하기 위해 필요한 것에만 집중하세요!
- 고립된 환경에서 혼자 학습한다.
→ 다른 사람에게 새로운 개념을 설명하세요. 설명할 수 있다면, 정말로 이해한 것입니다!
→ 목표를 공유하여 자신에게 책임을 부여하세요.
→ 웹 개발 커뮤니티와 학습 진행 상황을 공유하세요. (#100DaysOfCode, #CodeNewbie, #webdev 등)
- 몇 개의 강의를 마친 후에도 스스로 앱을 만들지 못한다.
→ 사람들이 가지는 가장 큰 오해!
→ 강좌는 놀라운 시작점이지만 여정의 시작에 불과합니다!
의사 코드 (pseudo code). 코드 제작에 정해진 규칙은 없다.
(+ ChatGPT)
우리는 스마트홈 온도계를 제작하고 있다.
하루 동안 주어진 온도들의 배열이 주어졌을 때, temperature amplitude를 계산하라.
단, 종종 센서에 에러가 있다는 것을 염두해야 한다.
const temperatures = [3, -2, -6, -1, 'error', 9, 13, 17, 15, 14, 9, 5];
구글 검색: javascript get max value in array
const calcTempAmplitude = function (temps) {
let max = temps[0];
for(let i=0 ; i<temps.length ; i++){
if(temps[i]>max) max = temps[i];
}
console.log(max);
};
calcTempAmplitude([3,7,5]);
const calcTempAmplitude = function (temps) {
let max = temps[0];
let min = temps[0];
for(let i=0 ; i<temps.length ; i++){
const curTemp = temps[i];
if(curTemp>max) max = curTemp;
if(curTemp<min) min = curTemp;
}
};
const calcTempAmplitude = function (temps) {
let max = temps[0];
let min = temps[0];
for(let i=0 ; i<temps.length ; i++){
const curTemp = temps[i];
if(curTemp>max) max = curTemp;
if(curTemp<min) min = curTemp;
}
console.log(max-min);
};
calcTempAmplitude([3,7,4,1,8]);
const calcTempAmplitude = function (temps) {
let max = temps[0];
let min = temps[0];
for(let i=0 ; i<temps.length ; i++){
const curTemp = temps[i];
if(typeof curTemp !== 'number') continue;
if(curTemp>max) max = curTemp;
if(curTemp<min) min = curTemp;
}
console.log(max-min);
};
calcTempAmplitude([3,7,4,1,8]);
calcTempAmplitude(temperatures);
이제는 온도들의 배열이 2개 주어진다.
const temperatures = [3, -2, -6, -1, 'error', 9, 13, 17, 15, 14, 9, 5];
구글 검색: javascript merge two arrays
const calcTempAmplitude = function (temps1, temps2) {
const temps = temps1.concat(temps2);
let max = temps[0];
let min = temps[0];
for(let i=0 ; i<temps.length ; i++){
const curTemp = temps[i];
if(typeof curTemp !== 'number') continue;
if(curTemp>max) max = curTemp;
if(curTemp<min) min = curTemp;
}
console.log(max-min);
};
calcTempAmplitude([3,7,5],[4,18,2,'error',1]);
const measureKelvin = function(){
const measurement = {
type: 'temp',
unit: 'celsius',
value: prompt('Degrees celcius:'),
};
const kelvin = measurement.value + 273;
return kelvin;
};
console.log(measureKelvin());
console.log(measurement);
console.table(measurement);
console.log(measurement.value);
console.warn(measurement.value);
console.error(measurement.value);
Find
value에 들어있는 값이 문자열임을 알았다.
Fix
value: Number(prompt('Degrees celcius:')) // Number() 사용해서 숫자형으로 바꿔주기
console.log()를 일일히 찍지 않아도 되는 장점이 있다.
단계 - F9를 누르면 한 줄씩 코드가 진행된다.
const calcTempAmplitude = function (temps1, temps2) {
const temps = temps1.concat(temps2);
let max = temps[0];
let min = temps[0];
for (let i = 0; i < temps.length; i++) {
const curTemp = temps[i];
if (typeof curTemp !== 'number') continue;
debugger;
if (curTemp > max) max = curTemp;
if (curTemp < min) min = curTemp;
}
console.log(max - min);
};
calcTempAmplitude([3, 7, 5], [4, 18, 2, 'error', 1]);
좋은 글 감사합니다. 자주 올게요 :)