I have an Excel sheet calculation I'm trying to convert to a Javascript with web output. I'm rather new to Javascript but Im having some trouble with a function of the sheet I'm trying to implement.
The sheet is a Helium volume calculator that will take a given balloon type, multiply by a quantity then suggest the best value for which helium tanks are required to fill the given volume.
Here's the spreadsheet for reference:
Here's my JSFiddle attempt at a short and simple web app:
var $ = document.getElementById.bind(document);
$('btn').addEventListener('click', function() {
var
tanks = {
0: {
name: 'HEL550',
volume: 292
},
1: {
name: 'HEL450',
volume: 225
},
2: {
name: 'HEL250',
volume: 125
},
3: {
name: 'HEL160',
volume: 125
},
4: {
name: 'HEL110',
volume: 55
},
5: {
name: 'HEL50',
volume: 27.5
},
6: {
name: 'BT 326502',
volume: 14.9
},
7: {
name: 'BT 306472',
volume: 8.9
}
},
balloonModel = $('balloon_model').value,
qantity = $('qty').value,
finalResult = balloonModel * qantity,
finalResultRounded = finalResult.toFixed(2),
tankCalc = tanks[7].name;
$('result').value = finalResultRounded;
$('tankyouneed').value = tankCalc;
}, false);
Basic volume calculation is easy enough and working. But I can't get my head around trying to use an array and loop to do the other stuff.
In the spreadsheet all the balloon types are listed but I really only need to chose a single one at a time, hence the dropdown. I don't need the tank calculations displayed, just which tank to chose as suggested by the spreadsheet result. To the right are 3 tank suggestions: actual tank(s) needed, maximum transportability or one-time use for those who don't want to ever buy again.
Can anyone help? Thanks!
Aucun commentaire:
Enregistrer un commentaire