diff --git a/assets/Calculator.png b/assets/Calculator.png new file mode 100644 index 0000000..bcf7550 Binary files /dev/null and b/assets/Calculator.png differ diff --git a/demos/basic-calculator/index.html b/demos/basic-calculator/index.html new file mode 100644 index 0000000..425fb01 --- /dev/null +++ b/demos/basic-calculator/index.html @@ -0,0 +1,40 @@ + + + + + + Basic Calculator + + + +
+ +
+ + + + + + + + + + + + + + + + + + + + + +
+
+ + + + + diff --git a/demos/basic-calculator/script.js b/demos/basic-calculator/script.js new file mode 100644 index 0000000..c9afdc0 --- /dev/null +++ b/demos/basic-calculator/script.js @@ -0,0 +1,44 @@ +const display = document.getElementById('display'); + +let buffer = ''; + +function append(k){ + buffer += k; + display.value = buffer; +} + +function clearAll(){ + buffer = ''; + display.value = ''; +} + +function evaluateExpr(){ + if(!buffer) return; + try{ + // Safe eval: allow digits, operators, dot and spaces only + if(!/^[-+*/().\d\s]+$/.test(buffer)) throw new Error('invalid'); + const result = Function(`"use strict";return (${buffer})`)(); + buffer = String(result); + display.value = buffer; + }catch{ + display.value = 'Error'; + buffer = ''; + } +} + +document.querySelectorAll('[data-k]').forEach(btn=>{ + btn.addEventListener('click',()=>append(btn.dataset.k)); +}); +document.getElementById('clear').addEventListener('click',clearAll); +document.getElementById('equals').addEventListener('click',evaluateExpr); + +// Keyboard support +window.addEventListener('keydown',(e)=>{ + const k = e.key; + if(/[0-9.+\-*/()]/.test(k)) append(k); + else if(k==='Enter') evaluateExpr(); + else if(k==='Escape') clearAll(); + else if(k==='Backspace'){ buffer = buffer.slice(0,-1); display.value = buffer; } +}); + + diff --git a/demos/basic-calculator/style.css b/demos/basic-calculator/style.css new file mode 100644 index 0000000..6901fd7 --- /dev/null +++ b/demos/basic-calculator/style.css @@ -0,0 +1,10 @@ +*{box-sizing:border-box}body{margin:0;font-family:system-ui,-apple-system,Segoe UI,Roboto,Ubuntu,Cantarell,Noto Sans,sans-serif;background:#0e0e1a;color:#fff;display:grid;place-items:center;min-height:100vh} +.calc{background:#151528;border:1px solid #2a2a42;border-radius:16px;padding:16px;box-shadow:0 10px 30px rgba(0,0,0,.3);width:min(360px,92vw)} +.display{width:100%;height:64px;border-radius:12px;border:1px solid #2a2a42;background:#0a0a14;color:#7dd3fc;font-size:28px;padding:12px 14px;margin-bottom:12px;text-align:right} +.keys{display:grid;grid-template-columns:repeat(4,1fr);gap:10px} +button{appearance:none;border:none;border-radius:12px;padding:14px;font-size:18px;background:#1e1e35;color:#e5e7eb;cursor:pointer;transition:.15s ease;box-shadow:0 2px 0 #0a0a14} +button:hover{filter:brightness(1.05)}button:active{transform:translateY(1px);box-shadow:0 1px 0 #0a0a14} +.op{background:#23234a;color:#a5b4fc}.muted{background:#23233a;color:#94a3b8} +.primary{grid-column:span 4;background:#6d28d9;color:#fff;font-weight:700} + + diff --git a/index.html b/index.html index 8c5ff97..5b3af7d 100644 --- a/index.html +++ b/index.html @@ -45,7 +45,7 @@
-

Showcase Your Front-End Creations

+

Showcase Your Front-End Creations

Discover, share, and get inspired by amazing front-end projects from developers around the world. Join the community and showcase your creativity!

Explore Projects @@ -245,37 +245,55 @@

-