-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
74 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |