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

added back button so as to make calculator more productive #4

Open
wants to merge 1 commit into
base: main
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
18 changes: 14 additions & 4 deletions app.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
(function(){

let screen = document.querySelector('.screen');
let screen = document.querySelector('.screen');
let buttons = document.querySelectorAll('.btn');
let clear = document.querySelector('.btn-clear');
let clear = document.querySelector('.btn-clear');
let equal = document.querySelector('.btn-equal');

//retrieve data from numbers that are clicked
Expand All @@ -13,7 +13,7 @@
})
});

equal.addEventListener('click', function(e){
equal.addEventListener('click', function(e){
if(screen.value === ''){
screen.value = 'Please Enter a Value';
} else {
Expand All @@ -22,8 +22,18 @@
}
})

clear.addEventListener('click', function(e){
clear.addEventListener('click', function(e){
screen.value = '';
})
back.addEventListener('click', function(e){
console.log(screen.value)
if(screen.value)
{
let o = screen.value;
let d = (eval(o)/10);
o=Math.floor(d);
screen.value = o;
}
})

})();
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
<button type="button" class="btn btn-grey" data-num="0">0</button>
<button type="button" class="btn-equal btn-grey">=</button>
<button type="button" class="btn-clear btn-grey">C</button>
<button type="button" id="back" class="btn-clear btn-grey"> <- </button>
</div>


Expand Down