-
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
[ 서진 ] #5
base: main
Are you sure you want to change the base?
[ 서진 ] #5
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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. 호오오옥시 이 파일의 정체가 왜 생겼는지 알 수 있을까? 내가 vite로 만든 ts라서 굳이 컴파일 과정같은게 필요없었을텐디! |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
var userInput1 = document.getElementById('userInput1'); | ||
var userInput2 = document.getElementById('userInput2'); | ||
var operationType = document.getElementById('operationType'); | ||
var answer = document.getElementById('answer'); | ||
var resultBtn = document.getElementById('resultBtn'); | ||
function getResult() { | ||
var firstInput = Number(userInput1.value); | ||
var secondInput = Number(userInput2.value); | ||
var operator = operationType.value; | ||
var result = calculate(firstInput, secondInput, operator); | ||
answer.innerText = result.toString(); | ||
} | ||
function calculate(firstInput, secondInput, operator) { | ||
var result = 0; | ||
switch (operator) { | ||
case "sum": | ||
result = firstInput + secondInput; | ||
break; | ||
case "sub": | ||
result = firstInput - secondInput; | ||
break; | ||
case "mul": | ||
result = firstInput * secondInput; | ||
break; | ||
case "divide": | ||
if (secondInput !== 0) { | ||
result = firstInput / secondInput; | ||
} | ||
else { | ||
throw new Error('0으로 나눌 수 없습니다 ^0^'); | ||
} | ||
break; | ||
} | ||
return result; | ||
} | ||
resultBtn.addEventListener("click", getResult); |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,39 @@ | ||||||
const userInput1: HTMLInputElement = document.getElementById('userInput1') as HTMLInputElement; | ||||||
const userInput2: HTMLInputElement = document.getElementById('userInput2') as HTMLInputElement; | ||||||
const operationType: HTMLSelectElement = document.getElementById('operationType') as HTMLSelectElement; | ||||||
const answer: HTMLElement = document.getElementById('answer')!; | ||||||
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. 요거 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. 허억 이렇게 연산자로 제한해서 이후에 null값이 들어오는 예외처리를 안해줘도 되겠구나! |
||||||
const resultBtn: HTMLButtonElement = document.getElementById('resultBtn') as HTMLButtonElement; | ||||||
|
||||||
function getResult():void { | ||||||
const firstInput: number = Number(userInput1.value); | ||||||
const secondInput:number = Number(userInput2.value); | ||||||
const operator:string = operationType.value; | ||||||
|
||||||
const result:number = calculate(firstInput, secondInput, operator); | ||||||
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. 굳굳!!! 하나하나 타입 넣어준 거 너무 죠아요!! |
||||||
answer.innerText = result.toString(); | ||||||
} | ||||||
|
||||||
function calculate(firstInput:number, secondInput:number, operator:string):number { | ||||||
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
|
||||||
let result:number = 0; | ||||||
switch(operator) { | ||||||
case "sum": | ||||||
result = firstInput + secondInput; | ||||||
break; | ||||||
case "sub": | ||||||
result = firstInput - secondInput; | ||||||
break; | ||||||
case "mul": | ||||||
result = firstInput * secondInput; | ||||||
break; | ||||||
case "divide": | ||||||
if (secondInput !== 0) { | ||||||
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. 예외처리 굳! |
||||||
result = firstInput / secondInput; | ||||||
} else { | ||||||
throw new Error('0으로 나눌 수 없습니다 ^0^'); | ||||||
} | ||||||
break; | ||||||
} | ||||||
return result; | ||||||
} | ||||||
|
||||||
resultBtn.addEventListener("click", getResult); |
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.
엇 혹시 main.js는 왜 생겼지? 혹시 compile한 건가용,,,??????????
그냥 yarn dev 실행하면 되었을텐디!! 어케된건지 궁금해!
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.
PR에 남겨두었는데 !
main.ts:1 Failed to load module script: Expected a JavaScript module script but the server responded with a MIME type of "video/mp2t". Strict MIME type checking is enforced for module scripts per HTML spec.
이 에러가 계속 떠서 대체 왜 ..... 이런건가 하고 찾아보다가 계속 구글링 하다가 main.ts를 연결할 때 에러가 발생하는 것이라 컴파일 완료된 main.js파일을 연결하면 에러가 발생하지 않는다는 글을 보고 .. 그렇게 해결했습니다만
지금 생각해보니 내가 CRA에 익숙해져 있어서 npm run start로 켰었나 ..? 그래서 저런 에러가 와장창 발생했던 건가란 합리적 의심중 ..