Skip to content

[ 다현 ]#6

Open
moondda wants to merge 1 commit intomainfrom
dahyun
Open

[ 다현 ]#6
moondda wants to merge 1 commit intomainfrom
dahyun

Conversation

@moondda
Copy link
Copy Markdown

@moondda moondda commented Nov 8, 2023

  • 제목은 [ 이름 ] 으로 작성해주세요!

🌮 무엇을:

  • 무엇을 개발했는지 짧게 설명해주세요! (개발 완료된 부분까지 설명)

  • css은 딱히 안 건드렸고(시간 이슈..), 숫자를 입력하고 연산자를 선택하면 계산된 값이 alarm으로도 뜨고, 화면에도 반영되게 하였다.

🌮 어떻게:

  • 어떻게 개발을 했는지 구체적으로 적어주세요!

select value에 따라 case를 나눠서 switch 로 계산을 할 수 있게 만들었다.
입력값은 초기에는 string으로 설정되어있어서 parseFloat을 통해서 숫자로 바꿔서 연산이 가능하게 하였다.

🌮 얼마나:

  • 얼마나 걸렸나요?
    1시간...?
  • 어떤 부분이 어려웠나요?

const firstInput = document.querySelector(".first-input") as HTMLInputElement;

이렇게 선택하는 부분에서 뒤에 as를 안 붙이는 데에서 에러가 많이 났다. 그리고 속성 참조를 할 때도 옵셔널 체이닝 연산자를 써야하고 (null일 수도 있어서) 하여튼 상당히 정확한 무언가 를 요구하는 언어인것 같다..

🌮 구현 사항:

  • 필수 구현 사항이 완료된 부분의 영상을 첨부해주세요
Screen.Recording.2023-11-08.at.6.11.54.PM.mov

@moondda moondda self-assigned this Nov 8, 2023
@hoeun0723 hoeun0723 linked an issue Nov 13, 2023 that may be closed by this pull request
Copy link
Copy Markdown
Member

@hae2ni hae2ni 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 src/main.ts

const select = document.querySelector("select") as HTMLSelectElement;
let showresult = document.querySelector("h3") as HTMLHeadingElement;
const showResultButton = document.querySelector(".result");
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

요기에는 HTMLButtonElement를 넣을 수 있겠다!

Comment thread src/main.ts
let showresult = document.querySelector("h3") as HTMLHeadingElement;
const showResultButton = document.querySelector(".result");

showResultButton?.addEventListener("click", () => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

요거 as 넣으면 해결되지 않나요?? 아닌가!!!??

Comment thread src/main.ts
const showResultButton = document.querySelector(".result");

showResultButton?.addEventListener("click", () => {
const input1: number = parseFloat(firstInput.value);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

함수가 기니까 그냥 안에 화살표 함수를 두는 것보다,함수를 새로 명명하는 게 좋을 것 같아요!
기능을 최대한 덜어내는 게 최선!

Comment thread src/main.ts
case "mul":
result = input1 * input2;
break;
case "divide":
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

나누기에 input2가 0인 케이스도 있답니다!

Comment thread src/main.ts
return;
}
showresult.textContent = String(result);
alert(`계산 결과는 ${result}`);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

alert까지 좋아요!

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

계산기 프로젝트 구현 내용

2 participants