User prompt
add Palestine
User prompt
on the screen
User prompt
add United Kingdom, Singapore, North Korea and South Korea
User prompt
delete =
User prompt
make the calculator bigger and the only button there should be is 1 2 3 4 5 6 7 8 9 0 . c enter cent
User prompt
delete division and all the else
Code edit (1 edits merged)
Please save this source code
User prompt
Currency Calculator
Initial prompt
a normal calculator. money. a calculator. so you have USA as the main money but at the bottom there's other currencies
/****
* Classes
****/
var CalculatorButton = Container.expand(function (label, type, callback) {
var self = Container.call(this);
var buttonType = type || 'number';
var buttonShape;
if (buttonType === 'operator') {
buttonShape = self.attachAsset('operatorButton', {
anchorX: 0.5,
anchorY: 0.5
});
} else if (buttonType === 'equals') {
buttonShape = self.attachAsset('equalsButton', {
anchorX: 0.5,
anchorY: 0.5
});
} else if (buttonType === 'clear') {
buttonShape = self.attachAsset('clearButton', {
anchorX: 0.5,
anchorY: 0.5
});
} else {
buttonShape = self.attachAsset('calculatorButton', {
anchorX: 0.5,
anchorY: 0.5
});
}
var buttonText = new Text2(label, {
size: 60,
fill: buttonType === 'number' ? "#000000" : "#ffffff"
});
buttonText.anchor.set(0.5, 0.5);
self.addChild(buttonText);
self.callback = callback;
self.down = function (x, y, obj) {
buttonShape.alpha = 0.7;
if (self.callback) {
self.callback();
}
};
self.up = function (x, y, obj) {
buttonShape.alpha = 1.0;
};
return self;
});
var CurrencyDisplay = Container.expand(function (currencyCode, rate) {
var self = Container.call(this);
self.currencyCode = currencyCode;
self.rate = rate;
self.currencyLabel = new Text2(currencyCode + ':', {
size: 40,
fill: 0xFFFFFF
});
self.currencyLabel.anchor.set(0, 0.5);
self.addChild(self.currencyLabel);
self.valueText = new Text2('0.00', {
size: 40,
fill: 0xFFFFFF
});
self.valueText.anchor.set(1, 0.5);
self.valueText.x = 300;
self.addChild(self.valueText);
self.updateValue = function (usdAmount) {
var convertedAmount = usdAmount * self.rate;
if (self.currencyCode === 'JPY') {
self.valueText.setText(Math.round(convertedAmount).toString());
} else {
self.valueText.setText(convertedAmount.toFixed(2));
}
};
return self;
});
/****
* Initialize Game
****/
var game = new LK.Game({
backgroundColor: 0x2c3e50
});
/****
* Game Code
****/
// Calculator state
var currentDisplay = '0';
var previousValue = 0;
var currentOperation = null;
var waitingForNewInput = false;
// Currency exchange rates (mock data - in real app would fetch from API)
var exchangeRates = {
'EUR': 0.85,
'GBP': 0.73,
'JPY': 110.25,
'CAD': 1.25,
'AUD': 1.35,
'CHF': 0.92
};
// Display background
var displayBg = game.addChild(LK.getAsset('displayBackground', {
anchorX: 0.5,
anchorY: 0
}));
displayBg.x = 1024;
displayBg.y = 200;
// Main display text
var displayText = new Text2(currentDisplay, {
size: 80,
fill: 0xFFFFFF
});
displayText.anchor.set(1, 0.5);
displayText.x = 1900;
displayText.y = 300;
game.addChild(displayText);
// USD label
var usdLabel = new Text2('USD', {
size: 50,
fill: 0xFFFFFF
});
usdLabel.anchor.set(0, 0.5);
usdLabel.x = 200;
usdLabel.y = 300;
game.addChild(usdLabel);
// Currency conversion background
var currencyBg = game.addChild(LK.getAsset('currencyBackground', {
anchorX: 0.5,
anchorY: 1
}));
currencyBg.x = 1024;
currencyBg.y = 2732;
// Currency displays
var currencyDisplays = [];
var currencies = Object.keys(exchangeRates);
for (var i = 0; i < currencies.length; i++) {
var currency = currencies[i];
var display = new CurrencyDisplay(currency, exchangeRates[currency]);
display.x = 200 + i % 3 * 600;
display.y = 2732 - 350 + Math.floor(i / 3) * 80;
currencyDisplays.push(display);
game.addChild(display);
}
// Calculator functions
function updateDisplay() {
displayText.setText(currentDisplay);
var numericValue = parseFloat(currentDisplay) || 0;
for (var i = 0; i < currencyDisplays.length; i++) {
currencyDisplays[i].updateValue(numericValue);
}
}
function inputNumber(num) {
if (waitingForNewInput) {
currentDisplay = num;
waitingForNewInput = false;
} else {
if (currentDisplay === '0') {
currentDisplay = num;
} else {
currentDisplay += num;
}
}
updateDisplay();
}
function inputDecimal() {
if (waitingForNewInput) {
currentDisplay = '0.';
waitingForNewInput = false;
} else if (currentDisplay.indexOf('.') === -1) {
currentDisplay += '.';
}
updateDisplay();
}
function inputOperation(op) {
if (currentOperation !== null && !waitingForNewInput) {
calculate();
}
previousValue = parseFloat(currentDisplay);
currentOperation = op;
waitingForNewInput = true;
}
function calculate() {
var current = parseFloat(currentDisplay);
var result = previousValue;
switch (currentOperation) {
case '+':
result = previousValue + current;
break;
case '-':
result = previousValue - current;
break;
case '×':
result = previousValue * current;
break;
}
currentDisplay = result.toString();
if (currentDisplay.length > 12) {
currentDisplay = result.toExponential(6);
}
currentOperation = null;
waitingForNewInput = true;
updateDisplay();
}
function clearAll() {
currentDisplay = '0';
previousValue = 0;
currentOperation = null;
waitingForNewInput = false;
updateDisplay();
}
// Create calculator buttons
var buttons = [];
// Number buttons (0-9)
var numberLayout = [['7', '8', '9'], ['4', '5', '6'], ['1', '2', '3'], ['0', '.', '=']];
for (var row = 0; row < numberLayout.length; row++) {
for (var col = 0; col < numberLayout[row].length; col++) {
var buttonLabel = numberLayout[row][col];
var buttonType = 'number';
var callback;
if (buttonLabel === '=') {
buttonType = 'equals';
callback = calculate;
} else if (buttonLabel === '.') {
callback = inputDecimal;
} else {
callback = function (num) {
return function () {
inputNumber(num);
};
}(buttonLabel);
}
var button = new CalculatorButton(buttonLabel, buttonType, callback);
button.x = 300 + col * 200;
button.y = 500 + row * 140;
buttons.push(button);
game.addChild(button);
}
}
// Operation buttons
var operations = [{
label: '×',
op: '×'
}, {
label: '-',
op: '-'
}, {
label: '+',
op: '+'
}];
for (var i = 0; i < operations.length; i++) {
var op = operations[i];
var opButton = new CalculatorButton(op.label, 'operator', function (operation) {
return function () {
inputOperation(operation);
};
}(op.op));
opButton.x = 900;
opButton.y = 500 + i * 140;
buttons.push(opButton);
game.addChild(opButton);
}
// Clear button
var clearBtn = new CalculatorButton('C', 'clear', clearAll);
clearBtn.x = 1200;
clearBtn.y = 500;
buttons.push(clearBtn);
game.addChild(clearBtn);
// Initialize display
updateDisplay(); ===================================================================
--- original.js
+++ change.js
@@ -189,13 +189,8 @@
break;
case '×':
result = previousValue * current;
break;
- case '÷':
- if (current !== 0) {
- result = previousValue / current;
- }
- break;
}
currentDisplay = result.toString();
if (currentDisplay.length > 12) {
currentDisplay = result.toExponential(6);
@@ -240,11 +235,8 @@
}
}
// Operation buttons
var operations = [{
- label: '÷',
- op: '÷'
-}, {
label: '×',
op: '×'
}, {
label: '-',