From 6b5d42d8a568fff3e00acb1958c5eea354e03f7a Mon Sep 17 00:00:00 2001
From: cozy-angel <72742868+cozy-angel@users.noreply.github.com>
Date: Wed, 17 Nov 2021 21:17:03 +0800
Subject: [PATCH 1/2] =?UTF-8?q?practice2:=20=E7=8E=8B=E5=AE=B6=E6=97=8B-20?=
=?UTF-8?q?20302880?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
Calculator/calculator.css | 64 ++++++++++++++++
Calculator/calculator.html | 72 ++++++++++++++++++
Calculator/calculator.js | 122 +++++++++++++++++++++++++++++++
Calculator/delete/iconfont.css | 19 +++++
Calculator/delete/iconfont.js | 1 +
Calculator/delete/iconfont.json | 16 ++++
Calculator/delete/iconfont.ttf | Bin 0 -> 1672 bytes
Calculator/delete/iconfont.woff | Bin 0 -> 1068 bytes
Calculator/delete/iconfont.woff2 | Bin 0 -> 720 bytes
9 files changed, 294 insertions(+)
create mode 100644 Calculator/calculator.css
create mode 100644 Calculator/calculator.html
create mode 100644 Calculator/calculator.js
create mode 100644 Calculator/delete/iconfont.css
create mode 100644 Calculator/delete/iconfont.js
create mode 100644 Calculator/delete/iconfont.json
create mode 100644 Calculator/delete/iconfont.ttf
create mode 100644 Calculator/delete/iconfont.woff
create mode 100644 Calculator/delete/iconfont.woff2
diff --git a/Calculator/calculator.css b/Calculator/calculator.css
new file mode 100644
index 0000000..35f8933
--- /dev/null
+++ b/Calculator/calculator.css
@@ -0,0 +1,64 @@
+.calculator {
+ display: block;
+ width: 290px;
+ height: 400px;
+ margin: auto;
+}
+
+.screen {
+ background-color: rgb(245, 245, 245);
+ height: 150px;
+ width: 100%;
+ font-size: 30px;
+ text-align: right;
+}
+
+.screen .prev {
+ height: 75px;
+ width: 100%;
+}
+
+.screen .current {
+ height: 75px;
+ width: 100%;
+}
+
+.buttons {
+ margin: auto;
+ width: 100%;
+}
+
+.buttons button {
+ width: 50px;
+ height: 50px;
+ margin: 9px 2px 0 1px;
+ font-size: 20px;
+ color: rgb(113, 113, 113);
+ border-radius: 10px;
+ border: none;
+ background-color: rgb(245, 245, 245);
+}
+
+.buttons .num {
+ color: black;
+}
+
+.buttons .fuction {
+ background-color: rgb(233, 240, 255);
+ color: rgb(105, 139, 242);
+}
+
+.buttons .equal {
+ float: top;
+ width: 50px;
+ height: 110px;
+ position: relative;
+ color: white;
+ background-color: rgb(59, 131, 119);
+}
+
+.buttons .short {
+ width: 230px;
+ position: relative;
+ float: left;
+}
\ No newline at end of file
diff --git a/Calculator/calculator.html b/Calculator/calculator.html
new file mode 100644
index 0000000..aa13d05
--- /dev/null
+++ b/Calculator/calculator.html
@@ -0,0 +1,72 @@
+
+
+
+
+
+
+
+ 计算器
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Calculator/calculator.js b/Calculator/calculator.js
new file mode 100644
index 0000000..557181a
--- /dev/null
+++ b/Calculator/calculator.js
@@ -0,0 +1,122 @@
+const buttonContainer = document.querySelector('.buttons');
+const prevElement = document.querySelector('.prev');
+const currentElement = document.querySelector('.current');
+var currentNumber = '',
+ prevNumber = '',
+ sign = '';
+buttonContainer.addEventListener('click', function (e) {
+ //console.log(e.target);
+ const type = e.target.dataset.type;
+ const text = e.target.textContent;
+ if (type == 'equal') {
+ calculate();
+ } else if (type == 'operate') {
+ operate(text);
+ } else if (type == 'delete') {
+ deletenum();
+ } else if (type == 'clear') {
+ clear();
+ } else {
+ pushNumber(text);
+ }
+ updateScreen();
+});
+
+function pushNumber(num) {
+ if (num == 'e') num = Math.E;
+ if (num == 'Π') num = Math.PI;
+ currentNumber = currentNumber + num;
+}
+
+function clear() {
+ currentNumber = '';
+ prevNumber = '';
+ sign = '';
+}
+
+function deletenum() {
+ if (!currentNumber.toString().length) {
+ return currentNumber = currentNumber.toString().slice(0, -1);
+ }
+}
+
+function operate(text) {
+ var result = 0;
+ if (currentNumber == '') return;
+ //如果用户未输入数字,就输入操作符,直接return
+ sign = text;
+ prevNumber = currentNumber;
+ const prev = Number(prevNumber);
+ currentNumber = '';
+ switch (sign) {
+ case 'ln':
+ result = Math.log(prev);
+ break;
+ case 'lg':
+ result = Math.log10(prev);
+ break;
+ case 'tan':
+ result = Math.tan(prev);
+ break;
+ case 'cos':
+ result = Math.cos(prev);
+ break;
+ case 'sin':
+ result = Math.sin(prev);
+ break;
+ case '√x':
+ result = Math.sqrt(prev);
+ break;
+ case 'x^2':
+ result = Math.pow(prev, 2);
+ break;
+ case '%':
+ result = prev / 100;
+ break;
+ default:
+ return;
+ }
+ currentNumber = result.toFixed(6);
+ sign = '';
+}
+
+function calculate() {
+ var result = 0;
+ const prev = Number(prevNumber);
+ const current = Number(currentNumber);
+ switch (sign) {
+ case '+':
+ result = prev + current;
+ break;
+ case '-':
+ result = prev - current;
+ break;
+ case '×':
+ result = prev * current;
+ break;
+ case '÷':
+ result = prev / current;
+ break;
+ case 'x^y':
+ result = Math.pow(prev, current);
+ break;
+ default:
+ return;
+ }
+ if (result % 1 == 0) {
+ currentNumber = result;
+ } else {
+ currentNumber = result.toFixed(6);
+ }
+ sign = '';
+}
+
+function updateScreen() {
+ currentElement.textContent = currentNumber;
+ //如果用户输入了操作符,那么prevNumber一定有值;
+ if (sign) {
+ prevElement.textContent = `${prevNumber} ${sign}`;
+ } else {
+ prevElement.textContent = '';
+ }
+}
\ No newline at end of file
diff --git a/Calculator/delete/iconfont.css b/Calculator/delete/iconfont.css
new file mode 100644
index 0000000..e58baa2
--- /dev/null
+++ b/Calculator/delete/iconfont.css
@@ -0,0 +1,19 @@
+@font-face {
+ font-family: "iconfont"; /* Project id 2921783 */
+ src: url('iconfont.woff2?t=1636343299487') format('woff2'),
+ url('iconfont.woff?t=1636343299487') format('woff'),
+ url('iconfont.ttf?t=1636343299487') format('truetype');
+}
+
+.iconfont {
+ font-family: "iconfont" !important;
+ font-size: 16px;
+ font-style: normal;
+ -webkit-font-smoothing: antialiased;
+ -moz-osx-font-smoothing: grayscale;
+}
+
+.icon-shanchu:before {
+ content: "\e620";
+}
+
diff --git a/Calculator/delete/iconfont.js b/Calculator/delete/iconfont.js
new file mode 100644
index 0000000..3097778
--- /dev/null
+++ b/Calculator/delete/iconfont.js
@@ -0,0 +1 @@
+!function(e){var t,n,o,i,c,d='',a=(a=document.getElementsByTagName("script"))[a.length-1].getAttribute("data-injectcss"),l=function(e,t){t.parentNode.insertBefore(e,t)};if(a&&!e.__iconfont__svg__cssinject__){e.__iconfont__svg__cssinject__=!0;try{document.write("")}catch(e){console&&console.log(e)}}function s(){c||(c=!0,o())}function r(){try{i.documentElement.doScroll("left")}catch(e){return void setTimeout(r,50)}s()}t=function(){var e,t;(t=document.createElement("div")).innerHTML=d,d=null,(e=t.getElementsByTagName("svg")[0])&&(e.setAttribute("aria-hidden","true"),e.style.position="absolute",e.style.width=0,e.style.height=0,e.style.overflow="hidden",t=e,(e=document.body).firstChild?l(t,e.firstChild):e.appendChild(t))},document.addEventListener?~["complete","loaded","interactive"].indexOf(document.readyState)?setTimeout(t,0):(n=function(){document.removeEventListener("DOMContentLoaded",n,!1),t()},document.addEventListener("DOMContentLoaded",n,!1)):document.attachEvent&&(o=t,i=e.document,c=!1,r(),i.onreadystatechange=function(){"complete"==i.readyState&&(i.onreadystatechange=null,s())})}(window);
\ No newline at end of file
diff --git a/Calculator/delete/iconfont.json b/Calculator/delete/iconfont.json
new file mode 100644
index 0000000..f9dc26b
--- /dev/null
+++ b/Calculator/delete/iconfont.json
@@ -0,0 +1,16 @@
+{
+ "id": "2921783",
+ "name": "no name",
+ "font_family": "iconfont",
+ "css_prefix_text": "icon-",
+ "description": "",
+ "glyphs": [
+ {
+ "icon_id": "7434461",
+ "name": "删除",
+ "font_class": "shanchu",
+ "unicode": "e620",
+ "unicode_decimal": 58912
+ }
+ ]
+}
diff --git a/Calculator/delete/iconfont.ttf b/Calculator/delete/iconfont.ttf
new file mode 100644
index 0000000000000000000000000000000000000000..48b4536aa1393b39d638b37ae6fd79847b50f3c6
GIT binary patch
literal 1672
zcmd^9&u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-;M9QwS5B6+H8w7kcQW3WW{~uRq04B4k#PbmW9B+d9`<>fHo*ybKkgqmaG<80
z(Zk4Kkwy{|L*_xA1t2pL5>kPfElE}(Eioa1Cov&~fzf_}hH}K5nT^~!=MF7k2|LUr
zRKM)QfBPPmPmu>yn3bguYdm0_Y!o18u|{D=qaZ`M7UxT#*ML4_VE)B)n?Z;{oI#pF
zo`FGCkxfmVQO(4h(M(*?NK8~vgiTdZP?3?9QJj(4oROXR%HJX`LDqk-xw#pocm$bx
z1Vlyu7BFT0o%HWJqZ{Ks?SGD1T8#U(^clIi7*%-Gco;Q#nIwe%t`d^4VKVyn@(klX
zt$&U{1^=A1p<&68#O^qG<;Oo}@sc|tB^(~Sv)Z4QGOM-mrP+i>2?#0rwh1S1f(|CI~;_c$rb$
zFd&hyr1yg@b-r!#+wr*kPyn?yE
zRu?eqR|w~AN|7*VA8=;EAI2M#^TR=Lk<`GT$M&Y7b7JSjnT>lblnwPQ7f)$qWDp5w
GW(NRFf@x#`
literal 0
HcmV?d00001
diff --git a/Calculator/delete/iconfont.woff2 b/Calculator/delete/iconfont.woff2
new file mode 100644
index 0000000000000000000000000000000000000000..4ae652acc9bf4112ed2cf193119b21a238f7a167
GIT binary patch
literal 720
zcmV;>0x$h{Pew8T0RR9100Phe3jhEB00xKv00Myk0RR9100000000000000000000
z0000SR0d!Gf^Z6f0D%MnHUcCA2nz-P1Rw>3X9qDG!3D^!uqng62$bf`F*bl+UzZsM
z@IVAlYp?V6_I@q|s1ui1KpPj;vM{w(M8Z`_R;snE3I2C3{}|NN-&plf4Ot=N(xmMb
zUz!`CLMs-NvM^E
z2Nn;|1Ev>CD8K>AL?FgdP_Okh02%R!K!Y{SlDE4DMKJqHeWTuz+*zik
zuI1l9@8PHSYG(@eucY3%yi`!;t3+#3r&?HJQ)}Spc7xK&o0*&bx`(K+r+BQm=Qtzm
zWcKWQ{_M@0`KKpuUO&}Je^&fTmxN%gJ$iChu=%wz72w^yy~xZk52*I)3Vx9?0}`|0
zB^{?tAQ{UQNN8}P{Ac?*e2>*TZzUHhoj2sEGnk=JnV>SafKsCk)Ks?6U{TlpMx8t<
zB4+_J_6S0oDH`7Z^b&=-
zHgpgeLSj@XW(6`(E(Z_DviN;N7)^qO5Fj;{5_|@=k3tkdfa;MQXy{I!@h#GXNfL)R
z!DU0;dKzP~xRBR8Esmiig+3zTsTXia9F>*zRr}M9K?B=J;Y>_{y6ZY|sGa}-0001(
C*gE
Date: Thu, 18 Nov 2021 17:06:51 +0800
Subject: [PATCH 2/2] practice2: wangjiaxuan-2020302880
---
{Calculator => src}/calculator.css | 0
{Calculator => src}/calculator.html | 0
{Calculator => src}/calculator.js | 5 ++++-
{Calculator => src}/delete/iconfont.css | 0
{Calculator => src}/delete/iconfont.js | 0
{Calculator => src}/delete/iconfont.json | 0
{Calculator => src}/delete/iconfont.ttf | Bin
{Calculator => src}/delete/iconfont.woff | Bin
{Calculator => src}/delete/iconfont.woff2 | Bin
9 files changed, 4 insertions(+), 1 deletion(-)
rename {Calculator => src}/calculator.css (100%)
rename {Calculator => src}/calculator.html (100%)
rename {Calculator => src}/calculator.js (95%)
rename {Calculator => src}/delete/iconfont.css (100%)
rename {Calculator => src}/delete/iconfont.js (100%)
rename {Calculator => src}/delete/iconfont.json (100%)
rename {Calculator => src}/delete/iconfont.ttf (100%)
rename {Calculator => src}/delete/iconfont.woff (100%)
rename {Calculator => src}/delete/iconfont.woff2 (100%)
diff --git a/Calculator/calculator.css b/src/calculator.css
similarity index 100%
rename from Calculator/calculator.css
rename to src/calculator.css
diff --git a/Calculator/calculator.html b/src/calculator.html
similarity index 100%
rename from Calculator/calculator.html
rename to src/calculator.html
diff --git a/Calculator/calculator.js b/src/calculator.js
similarity index 95%
rename from Calculator/calculator.js
rename to src/calculator.js
index 557181a..dbc143a 100644
--- a/Calculator/calculator.js
+++ b/src/calculator.js
@@ -13,6 +13,7 @@ buttonContainer.addEventListener('click', function (e) {
} else if (type == 'operate') {
operate(text);
} else if (type == 'delete') {
+ //console.log("进入判断");
deletenum();
} else if (type == 'clear') {
clear();
@@ -35,7 +36,8 @@ function clear() {
}
function deletenum() {
- if (!currentNumber.toString().length) {
+ // console.log("运行函数");
+ if (currentNumber.toString().length) {
return currentNumber = currentNumber.toString().slice(0, -1);
}
}
@@ -98,6 +100,7 @@ function calculate() {
result = prev / current;
break;
case 'x^y':
+ sign = '^';
result = Math.pow(prev, current);
break;
default:
diff --git a/Calculator/delete/iconfont.css b/src/delete/iconfont.css
similarity index 100%
rename from Calculator/delete/iconfont.css
rename to src/delete/iconfont.css
diff --git a/Calculator/delete/iconfont.js b/src/delete/iconfont.js
similarity index 100%
rename from Calculator/delete/iconfont.js
rename to src/delete/iconfont.js
diff --git a/Calculator/delete/iconfont.json b/src/delete/iconfont.json
similarity index 100%
rename from Calculator/delete/iconfont.json
rename to src/delete/iconfont.json
diff --git a/Calculator/delete/iconfont.ttf b/src/delete/iconfont.ttf
similarity index 100%
rename from Calculator/delete/iconfont.ttf
rename to src/delete/iconfont.ttf
diff --git a/Calculator/delete/iconfont.woff b/src/delete/iconfont.woff
similarity index 100%
rename from Calculator/delete/iconfont.woff
rename to src/delete/iconfont.woff
diff --git a/Calculator/delete/iconfont.woff2 b/src/delete/iconfont.woff2
similarity index 100%
rename from Calculator/delete/iconfont.woff2
rename to src/delete/iconfont.woff2
--
Gitee