Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Calculator added #40

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions HTML-CSS-JAVASCRIPT Projects/Calculator/calculator.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
body {
background-color: rgb(27, 17, 17);
}
h1 {
color: aliceblue;
font-size: 48px;
font-family: Georgia, 'Times New Roman', Times, serif;
}
.container {
text-align: center;
margin-top: 23px;
}
table {
margin: auto;
}
input {
background-color: antiquewhite;
border-radius: 9px;
height: 65px;
width: 456px;
font-size: 34px;
}
button {
border-radius: 20px;
font-size: 34px;
width: 102px;
height: 47px;
margin: 6px;
}
.calculator{
display: inline-block;
border: 3px solid rgb(233, 223, 205);
}
54 changes: 54 additions & 0 deletions HTML-CSS-JAVASCRIPT Projects/Calculator/calculator.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<!DOCTYPE html>
<html lang="en">

<head>
<link rel="stylesheet" href="calculator.css">
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Calculator</title>
</head>

<body>
<div class="container">
<h1>CALCULATOR</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>
36 changes: 36 additions & 0 deletions HTML-CSS-JAVASCRIPT Projects/Calculator/calculator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
console.log("hello");
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("button is", 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);
}
else{
screenValue += buttonText;
screen.value=screenValue;
}

});
}





2 changes: 1 addition & 1 deletion contributors.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
- [Dhruv Gupta](https://github.com/MR-DHRUV)
- [Bagusin](https://github.com/Bagusin)
- [Palak Khandelwal](https://github.com/palaksv)

- [Ankit Goyal](https://github.com/Ankit9126)



Expand Down