-
Notifications
You must be signed in to change notification settings - Fork 1
15일차 과제 #43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
15일차 과제 #43
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,81 @@ | ||||||||||||||||
| <!DOCTYPE html> | ||||||||||||||||
| <html lang="ko"> | ||||||||||||||||
| <head> | ||||||||||||||||
| <meta charset="UTF-8"> | ||||||||||||||||
| <title>계산기</title> | ||||||||||||||||
| </head> | ||||||||||||||||
| <body> | ||||||||||||||||
| <h2>Soongu Calculator</h2> | ||||||||||||||||
| <div><h3>계산식을 입력해 주십시오(예시 : 1+2 | 종료 : exit).</h3></div> | ||||||||||||||||
| <div><ul><li>소수점 둘째자리 까지 계산됩니다.</li></ul></div> | ||||||||||||||||
| <input type = "text" id = "in-text" /> | ||||||||||||||||
| <input type="button" id="in-btn" value="버튼" /> | ||||||||||||||||
|
|
||||||||||||||||
| <script> | ||||||||||||||||
| function getElement(id){ | ||||||||||||||||
| return document.getElementById(id); | ||||||||||||||||
| } | ||||||||||||||||
| const inbtn = getElement("in-btn"); | ||||||||||||||||
| const intext = () => getElement("in-text").value; | ||||||||||||||||
|
||||||||||||||||
| function getElement(id){ | |
| return document.getElementById(id); | |
| } | |
| const inbtn = getElement("in-btn"); | |
| const intext = () => getElement("in-text").value; | |
| const inbtn = document.getElementById("in-btn"); | |
| const intext = document.getElementById("in-text").value; |
처럼 작성해봐도 좋지 않을까요? 이미 만들어진 메서드(getElementById())를 함수로 한번 더 감싸서 사용할 필요는 없는것 같아요.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2+2/4 등의 수식 결과가 왜 4.00으로 출력될까요? 한번 소스코드를 보며 고민해봅시다.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
실제로 계산이 끝난 값이 출력이 되고는 있습니다. 그러나 사용자가 수식을 입력한 input창 내부의 text를 변경하는 것이 아니라, input창 외부에 배치한 다른 text가 없는 빈 태그(span, p 등)에 값을 전달해서 표현해주는 방식이 과제 풀이 방식입니다.
크게 어렵지 않습니다만, 다른 요소의 value를 바꾸는 식으로 작성해보는 것을 도전해보셔도 좋을것 같아요.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
script를 html 파일과 분리하여 작성해주시면 좋을 것 같아요~
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
띄어쓰기 및 공백은 일관되게 작성해주세요!