Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
Chafikbz4 authored Sep 21, 2024
0 parents commit 40a142b
Show file tree
Hide file tree
Showing 3 changed files with 173 additions and 0 deletions.
104 changes: 104 additions & 0 deletions index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/* index.css */

body {
margin: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #282c34;
font-family: Arial, sans-serif;
}

.content {
display: flex;
flex-direction: column;
align-items: center;
padding: 20px;
background-color: #1c1c1c;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}

textarea {
width: 100%;
height: 50px;
margin-bottom: 20px;
padding: 10px;
font-size: 1.2em;
color: #fff;
background-color: #333;
border: none;
border-radius: 5px;
resize: none;
text-align: right;
}

button {
width: 60px;
height: 60px;
margin: 5px;
font-size: 1.5em;
color: #fff;
background-color: #444;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s;
}

button:hover {
background-color: #555;
}

button:active {
background-color: #666;
}

.Ac {
background-color: #f44336;
width: 140px;
}

.divide,.multiply{
margin-left: 1.5px;
}
.Ac:hover {
background-color: #e53935;
}

.Ac:active {
background-color: #d32f2f;
}

.operator {
background-color: #ff9800;
}

.operator:hover {
background-color: #fb8c00;
}

.operator:active {
background-color: #f57c00;
}

.zero {
width: 140px;
}

.equale {
background-color: #4caf50;

}

.equale:hover {
background-color: #43a047;
}

.equale:active {
background-color: #388e3c;
}
#output{
font-size: 22px;
}
42 changes: 42 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Calculator</title>
<link rel="stylesheet" href="index.css">
</head>
<body>
<div class="content">
<textarea name="txt" id="output" readonly></textarea>
<div>
<button class="Ac">AC</button>
<button class="btn operator divide" value="/">/</button>
<button class="btn operator multiply" value="*">X</button>
</div>
<div>
<button class="btn" value="7">7</button>
<button class="btn" value="8">8</button>
<button class="btn" value="9">9</button>
<button class="btn operator minase" value="-">-</button>
</div>
<div>
<button class="btn" value="4">4</button>
<button class="btn" value="5">5</button>
<button class="btn" value="6">6</button>
<button class="btn operator plus" value="+">+</button>
</div>
<div>
<button class="btn" value="1">1</button>
<button class="btn" value="2">2</button>
<button class="btn" value="3">3</button>
<button class="operator equale" value="=">=</button>
</div>
<div>
<button class="btn zero" value="0">0</button>
<button class="btn point" value=".">.</button>
</div>
</div>
<script src="index.js"></script>
</body>
</html>
27 changes: 27 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
let btn = document.querySelectorAll('.btn');
let expretion = document.querySelector('#output');
let result = document.querySelector('.equale');
let clear = document.querySelector('.Ac');

for (let i = 0; i < btn.length; i++) {
btn[i].addEventListener('click', function () {
expretion.value = expretion.value + btn[i].value;
});
}

result.addEventListener('click', function () {
try {
let evaluationResult = eval(expretion.value);
if (!isFinite(evaluationResult) || isNaN(evaluationResult)) {
expretion.value = "Error";
} else {
expretion.value = evaluationResult;
}
} catch (e) {
expretion.value = "Error";
}
});

clear.addEventListener('click', function () {
expretion.value = "";
});

0 comments on commit 40a142b

Please sign in to comment.