-
Notifications
You must be signed in to change notification settings - Fork 0
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
[수연] #8
base: main
Are you sure you want to change the base?
[수연] #8
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,34 @@ | ||
var $ = function (selector) { return document.querySelector(selector); }; | ||
var $$ = function (selector) { return document.querySelectorAll(selector); }; | ||
var num1 = $('#num1'); | ||
; | ||
var num2 = $('#num2'); | ||
; | ||
var cal = $('select[name="calculate"]'); | ||
var resultTag = $('h3'); | ||
var btn = $('button'); | ||
; | ||
var calculate = function () { | ||
var preNum = parseFloat(num1.value); | ||
var postNum = parseFloat(num2.value); | ||
var result; | ||
switch (cal.value) { | ||
case 'sum': | ||
result = preNum + postNum; | ||
break; | ||
case 'sub': | ||
result = preNum - postNum; | ||
break; | ||
case 'mul': | ||
result = preNum * postNum; | ||
break; | ||
case 'divide': | ||
result = preNum / postNum; | ||
break; | ||
default: | ||
result = ""; | ||
break; | ||
} | ||
resultTag.textContent = result.toString(); | ||
}; | ||
btn.addEventListener('click', calculate); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
|
||
const $ = (selector:string) => document.querySelector(selector) as HTMLElement; | ||
|
||
const num1 = $('#num1') as HTMLInputElement;; | ||
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. 먁 오타생긴 거 같아ㅠㅠ 에러 뜰 거 같은ㄷㅔ! |
||
const num2 = $('#num2') as HTMLInputElement;; | ||
const cal=$('select[name="calculate"]') as HTMLSelectElement; | ||
const resultTag=$('h3') as HTMLElement; | ||
const btn = $('button') as HTMLButtonElement;; | ||
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. 요기도!! |
||
|
||
const calculate =()=>{ | ||
let preNum = parseFloat(num1.value); | ||
let postNum = parseFloat(num2.value); | ||
|
||
let result:number|string; | ||
|
||
switch (cal.value) { | ||
case 'sum': | ||
result = preNum+postNum; | ||
break; | ||
case 'sub': | ||
result = preNum-postNum; | ||
break; | ||
case 'mul': | ||
result = preNum*postNum; | ||
break; | ||
case 'divide': | ||
result = preNum/postNum; | ||
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. postNum이 0인 예외으 경우도 빼주면 좋을 것 같아요! |
||
break; | ||
default: | ||
result=""; | ||
break; | ||
} | ||
Comment on lines
+16
to
+32
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. 코드 리뷰하다가 생각해본건데, switch문 말고, 객체 매핑 방식은 어떤가요 ~??
이런식으로요! 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. 옴마나,,,, 진ㅉㅏ 갓갓!! 대신에 타스니까 또 여기에 타입 넣는 거를 잊지 않아야 해용! let result: number | string; if (cal.value in operations) { |
||
|
||
|
||
resultTag.textContent=result.toString(); | ||
|
||
} | ||
btn.addEventListener('click',calculate); |
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.
오옷!! 혹시 이 파일은 미리 js로 작성해보다가 남겨진 파일인가요 ~??
현재 html에서 js 파일을 로드 하고 있어서 ts로 짠 코드가 작동이 안 되는 거 같아요 ㅠ.ㅠ
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.
앗 혹시 컴파일한건가요?? 이거 vite라 그냥 했어도 됐는데!