Functional calulator using JavaScript and stylish usng CSS



Working Model:Please enter any value



This calculator can perform addition, substraction , division and multiplication.The languages used to create this calculator is CSS, JavaScript and HTML.

All of the beginers are trying to create static webpages. Try dinamic functional websites too.
This is a calculator aimed for beginers in css cnd javascript. The function eval()  isused to calculate all the values that we entered in the calculator which is displayed in the input box.
The colour and styles are created using the CSS language which is placed in the head section.



Preview:



The source code of the program is given below in the box. I did not creative any other files which points to CSS or JavaScript.all of the language the place in the head section using style tag and script tag.


Code:



<html>
<head>

<title>Simple calculator for beginers | cspsyco</title><style>


.total
{
display:block;
background:black;
width:200px;
height:360px;
border-radius:10px;
}
#btn
{
width:50px;
height:50px;
border-radius:120px;
background-color:orange;
border-color:black;
font-size:15px;
}
input
{
border:3px solid orange;
border-radius:5px;
width:170px;
height:50px;
font-size:30px;
}
</style>


<script>
function calculate(val)
{
document.getElementById("input").value+=val;
}
function solve()
{
let x=document.getElementById("input").value;
let y=eval(x);
document.getElementById("input").value=y;
}
</script>
</head>
<body><center><br><br><br>
<div class=total>
<div><br>
<input type=text classs=input id=input>
</div>
<br>
<div>
<button value=1 id=btn onclick="calculate('1')">1</button>
<button value=2 id=btn onclick="calculate('2')">2</button>
<button value=3 id=btn onclick="calculate('3')">3</button>
</div>
<div>
<button value=4 id=btn onclick="calculate('4')">4</button>
<button value=5 id=btn onclick="calculate('5')">5</button>
<button value=6 id=btn onclick="calculate('6')">6</button>
</div>
<div>
<button value=7 id=btn onclick="calculate('7')">7</button>
<button value=8 id=btn onclick="calculate('8')">8</button>
<button value=9 id=btn onclick="calculate('9')">9</button>
</div>
<div>
<button value=0 id=btn onclick="calculate('0')">0</button>
<button value=* id=btn onclick="calculate('*')">*</button>
<button value=/ id=btn onclick="calculate('/')">/</button>
</div>
<div>
<button value=0 id=btn onclick="calculate('-')">-</button>
<button onclick="calculate('+')" id=btn>+</button>
<button id=btn onclick="solve()">=</button>
</div>
</div>
</center>
</body>
</html>

Comments

Popular posts from this blog

Node.js Cheat Sheet

Codeigniter ! Simple But Powerful

Introducing Cloudflare Pages ⚡