-
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 all commits
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,16 @@ | ||
| <!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="버튼" /> | ||
| <span id = "result-display"></span> | ||
| <script src="계산기.js"></script> | ||
| </body> | ||
| </html> | ||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,41 @@ | ||||||||
| const inbtn = document.getElementById("in-btn"); | ||||||||
| const intext1 = () =>document.getElementById("in-text").value; | ||||||||
| const intext = intext1; | ||||||||
|
Comment on lines
+2
to
+3
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
두개가 있을 필요는 없을것 같습니다.😅 추가적으로 위 코멘트에서 남긴 로워 카멜 케이스 적용해보세용 |
||||||||
| const display = document.getElementById("result-display"); | ||||||||
|
|
||||||||
|
|
||||||||
| const click = () => { | ||||||||
| const userInput = intext(); | ||||||||
| const result = calculate(userInput); | ||||||||
| if (result !== undefined) { | ||||||||
| print(result); | ||||||||
| }} | ||||||||
| const exit = () => alert("계산기를 종료합니다."); | ||||||||
|
|
||||||||
| const exitcheck = (exit) => (exit === "exit" ) ? true : false; | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
같은 구조가 있을때, 함수가 특정 작업을 하기 위해 부여받는 매개변수를 인자라고 합니다( 여기서는 매개변수의 역할을 추가적으로, 해당 값을 (이미 잘 하셨지만, 변수명에 대해서는, |
||||||||
|
|
||||||||
| const calculate = (userInput) => { | ||||||||
| if (exitcheck(userInput)) { | ||||||||
| exit(); | ||||||||
| return; | ||||||||
| } | ||||||||
|
|
||||||||
| try { | ||||||||
| const allFunction = new Function("return " + userInput); | ||||||||
| const result = allFunction(); | ||||||||
| return result; | ||||||||
| } | ||||||||
| catch (err) { | ||||||||
| return "Error"; | ||||||||
| } | ||||||||
| } | ||||||||
|
|
||||||||
| inbtn.onclick = click; | ||||||||
|
|
||||||||
| const A4 = () => document.getElementById("result-display"); | ||||||||
|
|
||||||||
| const print = (intext) => { | ||||||||
| intext === "Error" ? alert("0으로 나눌 수 없습니다") : | ||||||||
| A4().innerText = Number(intext).toFixed(2); | ||||||||
|
|
||||||||
| } | ||||||||
Uh oh!
There was an error while loading. Please reload this page.
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.
in-text, in-btn, result-display 등 케밥 케이스로 요소들의
id를 작성해주셨는데요, js 파일을 작성하시면서 문득getElementById라는 메서드를 보신 적 있을거에요.저희는 주로 로워 카멜 케이스(Lower Camel Case)로 변수명과 함수명을 작성하고 있는데요, 거기에 맞춰 따른다면,
inText,inBtn,resultDisplay등의 이름을 지어줄 수 있겠습니다.타 11기 인원분들 진행하실때에도 같은 코멘트를 남겼었는데, 해당 내용 간단히 살펴보시면 좋을 것 같아요.
#13 (comment)