Skip to content

Commit

Permalink
Merge pull request #33 from DilpatRai/main
Browse files Browse the repository at this point in the history
event handling concept using JavaScript
  • Loading branch information
iamzaidsoomro authored Oct 21, 2021
2 parents d024e65 + 6857409 commit 2e6cc16
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 0 deletions.
38 changes: 38 additions & 0 deletions Calculator.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@

.container {
margin-top: 0px;
text-align: center;
}
h1{
text-align: center;
font-size: 28px;
}
input {
width: 230px;
height: 40px;
border:5px solid #244624;
border-radius: 21px;
font-size: 34px;
}
button{
margin: 5px;
border-radius: 20px;
font-size: 30px;
background: #978fa0;
text-align: center;
width: 50px;
height: 50px;
}
.calculator {
border: 4px solid #13695d;
background-color: #ff99f7;
padding: 8px;
border-radius: 53px;
display: inline-block;
}
span {
color: rgb(26, 197, 209);
font-size: larger;
}


59 changes: 59 additions & 0 deletions Calculator.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="Calculator.css">
<title>Caculator</title>

</head>
<body>
<div class="container">
<h1>Caculator by <span>Dilpat Rai</span></h1>
<div class="calculator">
<input type="text"name="screen" id="screen">
<table>
<tr>
<td><button>(</button></td>
<td><button>)</button></td>
<td><button>C</button></td>
<td><button>%</button></td>

</tr>
<tr>
<td><button>7</button></td>
<td><button>8</button></td>
<td><button>9</button></td>
<td><button>X</button></td>

</tr>
<tr>
<td><button>4</button></td>
<td><button>5</button></td>
<td><button>6</button></td>
<td><button>-</button></td>

</tr>
<tr>
<td><button>1</button></td>
<td><button>2</button></td>
<td><button>3</button></td>
<td><button>+</button></td>

</tr>
<tr>
<td><button>0</button></td>
<td><button>.</button></td>
<td><button>/</button></td>
<td><button>=</button></td>

</tr>

</table>
</div>
</div>
<script src="Calculator.js"></script>

</body>
</html>
26 changes: 26 additions & 0 deletions Calculator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
let screen = document.getElementById('screen');
buttons = document.querySelectorAll('button');
let screenValue = "";
for(item of buttons){
item.addEventListener('click', (e) => {
buttonText = e.target.innerText;
console.log(buttonText);
if(buttonText == 'X') {
buttonText = '*';
screenValue+=buttonText;
screen.value = screenValue;
}
else if(buttonText == 'C'){
screenValue = "";
screen.value = screenValue;
}
else if(buttonText == '='){
screen.value = eval(screenValue);
screenValue = "";
}
else {
screenValue+= buttonText;
screen.value = screenValue;
}
})
}

0 comments on commit 2e6cc16

Please sign in to comment.