Calculator paid code for free ( HTML, CSS AND JavaScript)
Here is the free code
<!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">
<title>Calculator</title>
</head>
<style>
.container{
margin-left: auto;
margin-right: auto;
width: 500px;
height: 530px;
border-radius:40px ;
}
.center{
margin-left: auto;
margin-right: auto;
}
button{
font-size: 39px;
background-color: darkseagreen;
border-radius:13px ;
color: white;
border: 4px solid darkcyan;
width: 90px;
height: 80px;
}
input{
font-size: 30px;
height: 40px;
text-align: center;
border: 8px solid darkcyan;
border-radius: 24px;
}
.prob-me{
display: inline-block;
border: 6px solid rgb(0, 0, 0);
background-color: #4caf5075;
padding: 5px;
border-radius: 23px ;
}
</style>
<body>
<h1>
Calculator
</h1>
<div class="container">
<div class="prob-me">
<input type="text" name="screen" id="screen">
<table class="center">
<tr>
<td><button>(</button></td>
<td><button>)</button></td>
<td><button>%</button></td>
<td><button>AC</button></td>
</tr>
<tr>
<td><button>7</button></td>
<td><button>8</button></td>
<td><button>9</button></td>
<td><button>/</button></td>
</tr>
<tr>
<td><button>4</button></td>
<td><button>5</button></td>
<td><button>6</button></td>
<td><button>X</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>
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 text is ', buttonText);
if (buttonText == 'X') {
buttonText = '*';
screenValue += buttonText;
screen.value = screenValue;
}
else if (buttonText == 'AC') {
screenValue = "";
screen.value = screenValue;
}
else if (buttonText == '=') {
screen.value = eval(screenValue);
}
else {
screenValue += buttonText;
screen.value = screenValue;
}
})
}
</script>
</body>
</html>
Thanks for reading
ReplyDelete