Skip to content

Commit

Permalink
Improved parentheses functions
Browse files Browse the repository at this point in the history
  • Loading branch information
rizalfahlevi8 committed Jun 10, 2024
1 parent 77a548d commit 20463e1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
11 changes: 9 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<title>Scientific Calculator</title>
<link rel="stylesheet" href="style.css">
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-KK94CHFLLe+nY2dmCWGMq91rCGa5gtU4mk92HdvYe+M/SXH301p5ILy+dN9+nJOZ" crossorigin="anonymous">
Expand All @@ -23,11 +23,18 @@ <h1 class="text-center mt-3">Scientific Calculator</h1>
</div>
<div class="input p-3">
<div class="row justify-content-center">
<button class="btn col-2 mx-md-2 mx-1 mb-2" onclick="percentage()">e</button>
<button class="btn col-2 mx-md-2 mx-1 mb-2" onclick="factorial()">sin</button>
<button class="btn col-2 mx-md-2 mx-1 mb-2" onclick="parenthesesOpen()">cos</button>
<button class="btn col-2 mx-md-2 mx-1 mb-2" onclick="parenthesesClose()">tan</button>
<button class="btn col-2 mx-md-2 mx-1 mb-2" onclick="clearData()">AC</button>
</div>
<div class="row justify-content-center">
<button class="btn col-2 mx-md-2 mx-1 mb-2" >π</button>
<button class="btn col-2 mx-md-2 mx-1 mb-2" onclick="factorial()">x!</button>
<button class="btn col-2 mx-md-2 mx-1 mb-2" onclick="parenthesesOpen()">(</button>
<button class="btn col-2 mx-md-2 mx-1 mb-2" onclick="parenthesesClose()">)</button>
<button class="btn col-2 mx-md-2 mx-1 mb-2" onclick="percentage()">%</button>
<button class="btn col-2 mx-md-2 mx-1 mb-2" onclick="clearData()">AC</button>
</div>
<div class="row justify-content-center">
<button class="btn col-2 mx-md-2 mx-1 mb-2" onclick="logNatural()">ln</button>
Expand Down
9 changes: 7 additions & 2 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ function clearData() {

//------------------ NUMBER --------------------------
function number(value) {
data.staging = [];
data.staging.push(value);
result.value = data.staging.join('');
console.log(data);
Expand Down Expand Up @@ -305,12 +304,18 @@ function parenthesesOpen() {
data.staging = [];
operation.value = data.formats.join('');
result.value = data.result;
} else if (data.staging.length === 0 && isNaN(parseFloat(data.operations[data.operations.length - 1]))) {
} else if (data.staging.length === 0 && isNaN(parseFloat(data.operations[data.operations.length - 1])) && data.operations[data.operations.length - 1] !== ")") {
data.operations.push('(');
data.formats.push('(');
data.staging = [];
operation.value = data.formats.join('');
result.value = data.result;
}else if (data.staging.length === 0 && data.operations[data.operations.length - 1] === ")"){
data.operations.push('*', '(');
data.formats.push('×', '(');
data.staging = [];
operation.value = data.formats.join('');
result.value = data.result;
}
console.log(data);
}
Expand Down

0 comments on commit 20463e1

Please sign in to comment.