Skip to content

Commit

Permalink
Adding Caret top key to calculator Axe-Pearl#67
Browse files Browse the repository at this point in the history
  • Loading branch information
Soudarjya committed May 9, 2024
1 parent 42ffbc4 commit 772060a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions Calculator/cal.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ <h1 id="val"> </h1>
<button onclick="adder('/')">/</button>
</div>
<button onclick="adder('.')">.</button>
<button onclick="adder('^')">^</button>
</div>
</div>
</div>
Expand Down
10 changes: 7 additions & 3 deletions Calculator/cal.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ function clearer(){
}
function adder(k){
valEl.innerText += k
if(k=='*' || k=='+' || k=='-' || k=='/'){
if(k=='*' || k=='+' || k=='-' || k=='/' ||k=='^'){
compute(0)
}
}
function compute(is){
let temp = valEl.innerText, i
let t = temp[temp.length-1];
for(i=0;i<temp.length-1;i++){
if((temp[i]=='*' || temp[i]=='+' || temp[i]=='-' || temp[i]=='/') && i!=0){
if((temp[i]=='*' || temp[i]=='+' || temp[i]=='-' || temp[i]=='/' ||temp[i]=='^') && i!=0){
break;
}
}
Expand All @@ -28,7 +28,11 @@ function compute(is){
resEl.innerText = (part1)-(part2);
}else if(k5=='*'){
resEl.innerText = (part1)*(part2);
}else{
}
else if(k5=='^'){
resEl.innerText=Math.pow(part1,part2);
}
else{
resEl.innerText = (part1)/(part2);
}
resEl.innerText = '= ' + resEl.innerText
Expand Down

0 comments on commit 772060a

Please # to comment.