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

Updated calculator #159

Open
wants to merge 5 commits into
base: master
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
71 changes: 71 additions & 0 deletions 64. Advance Calculator/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<!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="style.css">
<title>Calculator</title>
</head>
<body>
<div id="TopSection">
<p></p>
</div>
<div id="MainSection">
<div>
<p class="h1a">History</p>
<ul id="history">
</ul>
</div>
<div class="calculator" id="calc" value="light">


<input class="input" type="text">

<table>
<tr>
<td><button class="button">C</button></td>
<td><button class="button">DEL</button></td>
<td><button class="button" id="inv">INV</button></td>
<td><button class="button" id="angle">RAD</button></td>
<td><button class="button">.</button></td>
</tr>
<tr>
<td><button class="button">1</button></td>
<td><button class="button">2</button></td>
<td><button class="button">3</button></td>
<td><button class="button">+</button></td>
<td><button class="button">-</button></td>
</tr>
<tr>
<td><button class="button">4</button></td>
<td><button class="button">5</button></td>
<td><button class="button">6</button></td>
<td><button class="button">/</button></td>
<td><button class="button">*</button></td>
</tr>
<tr>
<td><button class="button">7</button></td>
<td><button class="button">8</button></td>
<td><button class="button">9</button></td>
<td><button class="button">0</button></td>
<td><button class="button">=</button></td>
</tr>
<tr>
<td><button class="button" id="sin">sin</button></td>
<td><button class="button" id="cos">cos</button></td>
<td><button class="button" id="tan">tan</button></td>
<td><button class="button">log</button></td>
<td><button class="button">ln</button></td>
</tr>
</table>
</div>
<div>
<button onclick="toggle()" class="switch">Switch Theme</button>
</div>
</div>
<script src="script.js"></script>


</body>
</html>
150 changes: 150 additions & 0 deletions 64. Advance Calculator/script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
let string = "";
let a=0;
function toggle()
{
var element = document.body;
element.classList.toggle("dark-mode");
let cal = document.getElementById("calc");
let button = document.getElementsByClassName("button");
if(cal.value == "light"){
cal.style.backgroundColor = "#99d5ff";
cal.value = "black";
cal.style.borderColor = "#13695d";

}
else{
cal.style.backgroundColor = "black";
cal.style.borderColor = "#b5d307";
cal.value = "light";
}
}



let buttons = document.querySelectorAll('.button');
Array.from(buttons).forEach((button)=>{
function createitem(name)
{
let li = document.createElement('li');
li.textContent = name;
return li;
}
const history = document.querySelector('#history');
button.addEventListener('click', (e)=>{
if(e.target.innerHTML == '='){
history.appendChild(createitem(string));
try {
string = eval(string);
document.querySelector('input').value = string;

}
catch(err) {
document.querySelector('input').value ='Recheck' ;

}
}
else if(e.target.innerHTML == 'C'){
string = ""
document.querySelector('input').value = string;
}
else if(e.target.innerHTML == 'sin')
{
if(a==1)
string=eval(string*Math.PI/180);
history.appendChild(createitem('sin('+string+')'));

string= Math.sin(string);
document.querySelector('input').value = string;

}
else if(e.target.innerHTML == 'cos')
{
if(a==1)
string=eval(string*Math.PI/180);
history.appendChild(createitem('cos('+string+')'));

string= string= Math.cos(string);

document.querySelector('input').value = string;
}
else if(e.target.innerHTML == 'tan')
{
if(a==1)
string=eval(string*Math.PI/180);
history.appendChild(createitem('tan('+string+')'));
string = Math.tan(string);
document.querySelector('input').value = string;
}
else if(e.target.innerHTML == 'log')
{
string = Math.log10(string);
document.querySelector('input').value = string;
}
else if(e.target.innerHTML == 'ln')
{
string = Math.log(string);
document.querySelector('input').value = string;
}
else if(e.target.innerHTML == 'DEL')
{
string= string.slice(0, string.length - 1);
document.querySelector('input').value = string;
}
else if(e.target.innerHTML == 'RAD')
{

document.getElementById("angle").innerHTML = "DEG";
a=1;

}
else if(e.target.innerHTML == 'DEG')
{
a=0;
document.getElementById("angle").innerHTML = "RAD";


}
else if(e.target.innerHTML == 'INV')
{
document.getElementById("inv").innerHTML = "NOR";
document.getElementById("sin").innerHTML = "asin";
document.getElementById("cos").innerHTML = "acos";
document.getElementById("tan").innerHTML = "atan";
}
else if(e.target.innerHTML == 'NOR')
{
document.getElementById("inv").innerHTML = "INV";
document.getElementById("sin").innerHTML = "sin";
document.getElementById("cos").innerHTML = "cos";
document.getElementById("tan").innerHTML = "tan";
}
else if(e.target.innerHTML == 'asin')
{
history.appendChild(createitem('asin('+string+')'));
string = Math.asin(string);

document.querySelector('input').value = string;

}
else if(e.target.innerHTML == 'acos')
{
history.appendChild(createitem('acos('+string+')'));
string = Math.acos(string);
document.querySelector('input').value = string;

}
else if(e.target.innerHTML == 'atan')
{
history.appendChild(createitem('atan('+string+')'));
string = Math.atan(string);
document.querySelector('input').value = string;

}
else{
console.log(e.target)
string = string + e.target.innerHTML;
document.querySelector('input').value = string;
}

})
})
105 changes: 105 additions & 0 deletions 64. Advance Calculator/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#MainSection{
text-align: center;
margin-top:23px;
display: flex;
}
body{
background-color: beige;
}

table{
margin: auto;
}

input{
border-radius: 21px;
border: 5px solid #244624;
font-size:34px;
height: 65px;
width: 456px;
}

.button{
border-radius: 20px;
font-size: 40px;
background: #978fa0;
width: 102px;
height: 90px;
margin: 6px;
}
.calculator{
margin-left: 20%;
border: 4px solid #13695d;
background-color: #99d5ff;
padding: 23px;
border-radius: 53px;
display: inline-block;

}
.dark-mode{
background-color: black;
color: #b5d307;
}
#history{
font-size: 40px;
font-family: 'Times New Roman', Times, serif;
font-weight: 700;

}
.switch{
border-radius: 8px;
font-size: 40px;
background: #978fa0;
width:fit-content;
height: 60px;
margin: 6px;
margin-left: 90%;

}
.h1a{

font-size: 40px;
margin-left: 20px;
font-family: Georgia, 'Times New Roman', Times, serif;
font-weight: 700;
}
.switch {
text-decoration: none;
border: none;
padding: 12px 40px;
font-size: 16px;
background-color: green;
color: #fff;
border-radius: 5px;
box-shadow: 7px 6px 28px 1px rgba(0, 0, 0, 0.24);
cursor: pointer;
outline: none;
transition: 0.2s all;
}


.switch:active {
transform: scale(0.98);

box-shadow: 3px 2px 22px 1px rgba(0, 0, 0, 0.24);

}
.button {
padding: 15px 25px;
font-size: 24px;
text-align: center;
cursor: pointer;
outline: none;
background-color: #aa6804;
border: none;
border-radius: 15px;
box-shadow: 0 9px #999;
}

.button:hover {background-color: #3e3e8e}

.button:active {
background-color: #3e3e8e;
box-shadow: 0 5px #666;
transform: translateY(4px);
}