diff --git "a/KDG/Day15/\352\263\204\354\202\260\352\270\260.html" "b/KDG/Day15/\352\263\204\354\202\260\352\270\260.html" new file mode 100644 index 0000000..8a33806 --- /dev/null +++ "b/KDG/Day15/\352\263\204\354\202\260\352\270\260.html" @@ -0,0 +1,16 @@ + + + + + 계산기 + + +

Soongu Calculator

+

계산식을 입력해 주십시오(예시 : 1+2 | 종료 : exit).

+
+ + + + + + \ No newline at end of file diff --git "a/KDG/Day15/\352\263\204\354\202\260\352\270\260.js" "b/KDG/Day15/\352\263\204\354\202\260\352\270\260.js" new file mode 100644 index 0000000..c5c605a --- /dev/null +++ "b/KDG/Day15/\352\263\204\354\202\260\352\270\260.js" @@ -0,0 +1,41 @@ +const inbtn = document.getElementById("in-btn"); +const intext1 = () =>document.getElementById("in-text").value; +const intext = intext1; +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; + +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); + +} \ No newline at end of file