Skip to content

이영률- 자판기 온보딩 프로젝트#2

Open
youngryul wants to merge 11 commits into
mainfrom
youngryul
Open

이영률- 자판기 온보딩 프로젝트#2
youngryul wants to merge 11 commits into
mainfrom
youngryul

Conversation

@youngryul
Copy link
Copy Markdown

@youngryul youngryul commented Nov 23, 2024

[자판기 온보딩 프로젝트]

📌일시 : 11/23 ~ 12/07
📌 vite로 생성

[1차 리뷰 후 리팩토링]

  • 전역 변수 없애기
  • 불필요하게 반복되는 코드 없애기 (클래스화)
  • 주석 최소화
  • 상품 리스트 객체로 변경
  • 변수 카멜표기법으로 변경
  • 상품 금액 표시하는 시간 변경
  • 로그 추가 후 스크롤 코드 재사용 가능하게
  • 버튼 탬플릿 태그로 구현

@youngryul youngryul added the WIP 아직 작업 중입니다 label Nov 23, 2024
@youngryul youngryul changed the title chore: vite 프로젝트 생성 이영률- 자판기 온보딩 프로젝트 Nov 23, 2024
@youngryul youngryul added Needs Review 리뷰받을 준비가 되면 추가해주세요 and removed WIP 아직 작업 중입니다 labels Nov 26, 2024
Copy link
Copy Markdown
Contributor

@taggon taggon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

전반적으로 테스트 가능성이나 재사용성을 고려하지 않고 작성된 것으로 보입니다.

미션을 추가로 드릴게요.

  • 우선은 전역 변수가 하나도 없도록 작성하시고,
  • 불필요하게 반복되는 코드가 없도록 작성해보세요.
  • 정확히 어떤 역할을 하는 코드인지 "주석을 읽지 않고도" 알 수 있도록 작성해주세요.

Comment thread main.js Outdated
Comment on lines +3 to +5
const products_list = [ "쿨라", "속이사이다", "판타지판타", "오뎅국물",
"부장라떼", "판타지판타", "레드뿔", "핫세븐", "커피우유"];
const prices_list = [1500, 1700, 1500, 1800, 800, 1500, 2500, 1900, 1400]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

상품명과 금액은 하나의 객체로 묶는 편이 데이터를 관리하기에 편하지 않을까요?
예를 들어 레드뿔의 가격을 2000원으로 바꿔달라는 요구사항이 발생하면, 수정할 곳을 한 눈에 파악하기 어려울 것 같습니다.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

변수 이름에 스네이크 케이스를 사용하는 이유가 있나요?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

회사에선 스네이크 케이스로 무분별하게 사용하고 있었는데 자바스크립트가 카멜케이스로 만들어졌다는 사실을 알고 통일성 있게 카멜케이스로 코드를 짜는 것이 좋다.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

상품 리스트를 배열로 변경하여 template 태그로 수정해 반복적으로 사용되는 코드를 수정하였습니다.

@taggon 아래처럼의 방식이 최선인지 더 좋은 방법이 있는지 궁금합니다.
const itemList = [ { name: "쿨라", price: 1500 }, { name: "속이사이다", price: 1700 }, { name: "판타지판타", price: 1500 }, { name: "오뎅국물", price: 1800 }, { name: "부장라떼", price: 800 }, { name: "판타지판타", price: 1500 }, { name: "레드뿔", price: 2500 }, { name: "핫세븐", price: 1900 }, { name: "커피우유", price: 1400 }, ];

Comment thread main.js Outdated
Comment on lines +43 to +49
setTimeout(function () {
logs.push(`돈이 부족합니다.`);
money_log.value = logs.join("\n");
money_log.scrollTop = money_log.scrollHeight;
screen.value = Number(money).toLocaleString();

},1000);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

상품 금액을 표시하는 시간은 누르고 있는 동안 입니다.

Comment thread main.js Outdated
Comment on lines +55 to +57
logs.push(`${product}을 구매했습니다.`);
money_log.value = logs.join("\n");
money_log.scrollTop = money_log.scrollHeight;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

로그를 추가하고 스크롤하는 코드가 계속 반복되는데 재사용 가능하게 바꿔야 하지 않을까요?

Copy link
Copy Markdown
Author

@youngryul youngryul Dec 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

function Log 로 변경하였습니다.

@taggon taggon added Reviewed 리뷰를 마친 상태입니다 and removed Needs Review 리뷰받을 준비가 되면 추가해주세요 labels Nov 27, 2024
@youngryul youngryul added WIP 아직 작업 중입니다 and removed Reviewed 리뷰를 마친 상태입니다 labels Nov 30, 2024
@youngryul youngryul added Needs Review 리뷰받을 준비가 되면 추가해주세요 and removed WIP 아직 작업 중입니다 labels Dec 2, 2024
@taggon taggon added Reviewed 리뷰를 마친 상태입니다 and removed Needs Review 리뷰받을 준비가 되면 추가해주세요 labels Dec 7, 2024
Comment thread main.js
Comment on lines +3 to +9
const screen = document.querySelector("#screen");
const inMoney = document.querySelector("#inMoney");

let money = 0;
let logs = [];
screen.value = 0;
inMoney.value = 0;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

제가 과제를 드렸었는데, 이런 전역 변수도 없도록 작성할 수 있을까요?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Reviewed 리뷰를 마친 상태입니다

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants