Good day!
So, I was coding my app, and came across something interesting. If I make a function that asks to multiply two numbers:
function calculate() { var result = input1.value * input2.value / 100; tipAmt.value = “$” + result.toFixed(2);
}
This will produce a multiplied number. Now, if I use the + sign…it concatinates:
function calculate() { var result = input1.value + input2.value; tipAmt.value = “$” + result; }
So my first question is…how can I have two numbers added? And as a bonus question, once I have two numbers added, how can I have another number put in an input, that ADDS on to the previous total? Here’s the code I’m working with now:
var Observable = require(“FuseJS/Observable”); var addInput = Observable(0); var subInput = Observable(0); var calcSub = Observable(0); var totalOz = Observable(0); function addCalc() { var result = addInput.value + totalOz.value; totalOz.value = result; addInput.value = “”; } function clear() { addInput.value = “”; subInput.value = “”; totalOz.value = “”; } addCalc(); clear(); module.exports = { addCalc : addCalc, addInput : addInput, subInput : subInput, calcSub : calcSub, totalOz : totalOz, clear : clear, } + - Clear
Basically, the way this works, is you input a number at the top, it places it on the bottom (totalOz), and any additional number placed in the top field, will keep adding onto the bottom total. Here’s a working version @ codepen: http://codepen.io/0ktane/pen/NNdbOq?editors=0010
I hope this doesn’t sound like a tall order… Just need to know how to add two numbers, and keep that total to be added onto. Thanks for any assistance!