TIL

zumwholยท2021๋…„ 4์›” 13์ผ
0

โœ๐Ÿป๊ณ„์‚ฐ๊ธฐ ๋งŒ๋“ค๊ธฐ

๐Ÿฅฒ ์ฒซ๋ฒˆ์งธ ๋ฐฉ๋ฒ•
const display = document.querySelector(".calculator__display--for-advanced");
let firstNum, operatorForAdvanced, previousKey, previousNum, enteredNum;
let count = 0;
buttons.addEventListener("click", function (event) {
const target = event.target;
const action = target.classList[0];
const buttonContent = target.textContent;
if (target.matches("button")) {
if (action === "calculate") {
if (count === 0) {
firstNum = calculate(display.textContent,operatorForAdvanced,previousNum);
} else if (count !== 0) {
previousNum = calculate(display.textContent,operatorForAdvanced,previousNum);
}
count++;
}
}
});


๐Ÿ”ฅ๋‘๋ฒˆ์งธ ๋ฐฉ๋ฒ•
const display = document.querySelector(".calculator__display--for-advanced");
let firstNum, operatorForAdvanced, previousKey, previousNum;
buttons.addEventListener("click", function (event) {
const target = event.target;
const action = target.classList[0];
const buttonContent = target.textContent;
if (target.matches("button")) {
if (action === "calculate") {
if (display.textContent === "0") {
firstNum = calculate(
display.textContent,
operatorForAdvanced,
previousNum
);
} else if (firstNum !== "0") {
previousNum = display.textContent;
display.textContent = calculate(
firstNum,
operatorForAdvanced,
display.textContent
);
}
}
});


๐Ÿง˜ ์ฒซ๋ฒˆ์งธ ๋ฐฉ๋ฒ•์œผ๋กœ ์–ด๋–ป๊ฒŒ๋ผ๋„ ๊ปด๋งž์ถฐ์„œ ํ•ด๋ณด์•˜๋‹ค. ์›ํ•˜๋Š” ๊ธฐ๋Šฅ์ด ๋‚˜์™”์ง€๋งŒ ๋‹ค๋ฅธ ๊ณณ์—์„œ ๋ฌธ์ œ๊ฐ€ ์ƒ๊ฒผ๋‹ค. ๋‘๋ฒˆ์งธ ๋ฐฉ๋ฒ•์„ ๊ตฌํ˜„ํ•ด๋ณด์•˜๋Š”๋ฐ, ์†Œ์ˆ˜์ ์ด ๊ตฌํ˜„์ด ๋˜์ง€๋งŒ ์—”ํ„ฐ๊ธฐ๋Šฅ์ด ๋“ฌ์„ฑ๋“ฌ์„ฑ ํ•˜๋‚˜์‹ ์•ˆ ๋งž์•˜๋‹ค. ํ™•์‹คํžˆ ๋‚˜๋Š” ๋…ผ๋ฆฌ์ ์œผ๋กœ ๊ตฌํ˜„ํ•˜๋Š”๊ฒŒ ๋งŽ์ด ๋ถ€์กฑํ•œ ๊ฒƒ ๊ฐ™๋‹ค. ๋ชจ๋“  ๊ธฐ๋Šฅ์„ ํฌํ•จํ•˜๋Š” ๊ฒƒ์„ ์ƒ๊ฐํ•ด์•ผํ•˜๋Š”๋ฐ ํ•˜๋‚˜์”ฉ ๋งž์ถฐ๊ฐ€๋Š” ์‹์ด๋‹ค. ๊ทธ๋Ÿฌ๋‹ค๋ณด๋‹ˆ ํ•˜๋‚˜๊ฐ€ ๋งž์ถฐ์ง€๋ฉด ๋‹ค๋ฅธ ๊ณณ์—์„œ ๋ฌธ์ œ๊ฐ€ ์ƒ๊ธด๋‹ค. ์–ด์ฉŒ๊ฒ ์–ด. ๊ณ„์†ํ•ด์•ผ์ง€

๊ด€์‹ฌ ์žˆ์„ ๋งŒํ•œ ํฌ์ŠคํŠธ

0๊ฐœ์˜ ๋Œ“๊ธ€