Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
clintaire authored Jan 14, 2024
1 parent 46c3db7 commit 4ee2a06
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
15 changes: 15 additions & 0 deletions calculator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
function appendCharacter(char) {
document.getElementById('display').value += char;
}

function clearDisplay() {
document.getElementById('display').value = '';
}

function calculate() {
try {
document.getElementById('display').value = eval(document.getElementById('display').value);
} catch (error) {
document.getElementById('display').value = 'Error';
}
}
41 changes: 41 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Math Calculator</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>

<h2>Math Calculator</h2>

<input type="text" id="display" disabled>
<br>

<button onclick="appendCharacter('1')">1</button>
<button onclick="appendCharacter('2')">2</button>
<button onclick="appendCharacter('3')">3</button>
<button onclick="appendCharacter('+')">+</button>
<br>

<button onclick="appendCharacter('4')">4</button>
<button onclick="appendCharacter('5')">5</button>
<button onclick="appendCharacter('6')">6</button>
<button onclick="appendCharacter('-')">-</button>
<br>

<button onclick="appendCharacter('7')">7</button>
<button onclick="appendCharacter('8')">8</button>
<button onclick="appendCharacter('9')">9</button>
<button onclick="appendCharacter('*')">*</button>
<br>

<button onclick="appendCharacter('0')">0</button>
<button onclick="clearDisplay()">C</button>
<button onclick="calculate()">=</button>
<button onclick="appendCharacter('/')">/</button>

<script src="calculator.js"></script>
</body>
</html>
18 changes: 18 additions & 0 deletions styles.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
body {
font-family: Arial, sans-serif;
text-align: center;
margin: 50px;
}

input {
width: 50px;
padding: 10px;
margin: 5px;
font-size: 16px;
}

button {
padding: 10px;
font-size: 16px;
cursor: pointer;
}

0 comments on commit 4ee2a06

Please sign in to comment.