Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var textBox = document.getElementById("textBox");
- var memory = 0;
- if(typeof(Storage) != "undefined") {
- localStorage.setItem("number", memory);
- }
- else {
- alert("No 'localStorage' support");
- }
- function numButton(num) {
- if(typeof(textBox.value) != "string")
- {
- emptyBox();
- }
- textBox.value += num;
- }
- function emptyBox() {
- textBox.value = "";
- }
- function mathStuff(operator) {
- emptyBox();
- switch(operator) {
- case 'plus':
- memory = memory + Number(textBox.value);
- emptyBox();
- break;
- case 'minus':
- memory = memory - Number(textBox.value);
- emptyBox();
- break;
- case 'multiply':
- if(textBox.value === 0) {
- memory = Number(textBox.value) * 1;
- }
- else {
- memory = Number(textBox.value) * memory;
- }
- emptyBox();
- break;
- case 'divide':
- if(textBox.value === 0) {
- sysError('CAN NOT DIVIDE BY ZERO');
- }
- else {
- memory = Number(textBox.value) / memory;
- emptyBox();
- }
- break;
- case 'equal':
- textBox.value = memory;
- break;
- default:
- sysError('UNKNOWN ERROR');
- break;
- }
- }
- function otherButtons(task) {
- switch(task) {
- case 'ce':
- memory = 0;
- break;
- case 'c':
- textBox.value = "";
- break;
- default:
- sysError('UNKNOWN ERROR');
- break;
- }
- }
- function sysError(message) {
- // Add message to text box
- emptyBox();
- textBox.value += message;
- }
- document.getElementById("test").innerText += localStorage.getItem("number");
- if(parseInt(memory) === 0 && memory > 0) {
- for(var i = 0; i < memory.length+1; i++) {
- if(i === 0) {
- // Remove 0 from the number
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement