WHAT WORKS
Upon entering the 'monetary' value and clicking the 'calculate my taxes' button, you will receive the correct values.
WHAT DOESN'T WORK
An Issue to Address
The total tax amount is influenced by the duties category you choose.
1. By default, 'Electronics' is chosen and upon calculating the tax, the accurate value is displayed.
2. If you attempt to select a different duty category while using the same 'total amount', the tax amount shown does not change.
3. Even after refreshing and selecting an option other than electronics, the payment amount remains consistent for all 3 options (depending on the total amount entered.)
I extend my gratitude for your assistance in advance.
Here's the link to the repl: https://repl.it/@argo92/CUSTOMS-CALCULATOR
//Percentages based on duties category
const TAX_ELECTRONICS = 0.31 //31%
const TAX_AUTOMOBILES = 0.33 //33%
const TAX_PERISHABLES = 0.12 //12%
// Exhibit 1: Acquire and store value from select option
var selObj = document.getElementById("dutiesCategory");
var selValue = selObj.options[selObj.selectedIndex].value;
// Check Option Value click handler
function getOption() {
selectElement = document.querySelector('#dutiesCategory');
output = selectElement.value;
document.querySelector('.output').textContent = output;
}
var e = getOption();
// Exhibit 2: Test to confirm if an option value is still retrieved
function tester() {
var f = $("#dutiesCategory").change(function() {
var g = $(this).find("option:selected").val();
console.log(g);
});
}
tester();
// An Important Note: I am seeking a method to extract values from the select input and integrate them with the calculateTax function.
function calcDutiesCatTax(val) {
if (selValue) {
return TAX_ELECTRONICS;
} else if (selValue) {
return TAX_PERISHABLES;
} else {
return TAX_AUTOMOBILES;
}
};
// function calcDutiesCatTax(val) {
// var result = "";
// switch (selValue === val) {
// case 'Electronics':
// result = TAX_ELECTRONICS;
// break;
// case 'Automobile':
// result = TAX_AUTOMOBILES;
// break;
// case 'Food':
// result = TAX_PERISHABLES;
// break;
// }
// return result;
// }
// Tax calculation function
function calculateTax() {
//TEST Government Compound taxes base num = 350
var x = document.getElementById("totalAmount").value;
var ITEM_COST = parseInt(x);
var TAX_10 = ITEM_COST * 0.10; // 35
var TAX_5 = ITEM_COST * 0.05; // 17.5
var TAX_2 = ITEM_COST * 0.02; // 7
var TAX_8 = ITEM_COST * 0.08; // 28
var totalCompoundTax = TAX_10 + TAX_5 + TAX_2 + TAX_8;
// Calculate tax based on category
var feesFromDutiesCat = calcDutiesCatTax(e) * ITEM_COST;
console.log(feesFromDutiesCat);
// Total amount to be paid (Inclusive of all taxes)
var totalAmountToBePaidInEc = feesFromDutiesCat + totalCompoundTax * (2.68);
var totalAmountToBePaidInUsd = feesFromDutiesCat + totalCompoundTax;
document.getElementById("totaltaxesXCD").innerHTML = totalAmountToBePaidInEc.toFixed(2) + ' XCD';
document.getElementById("totaltaxesUSD").innerHTML = '$' + totalAmountToBePaidInUsd.toFixed(2);
}
// console.log(selValue);
// var calcDutiesCat = function (value) {
// var result = "";
// switch (value) {
// case 'electronics':
// result = TAX_ELECTRONICS;
// break;
// case 'Automobile':
// result = TAX_AUTOMOBILES;
// break;
// case 'Food':
// result = TAX_PERISHABLES;
// break;
// }
// return result;
// }
// function calcDutiesCatTax(val) {
// if (val === selValue) {
// return TAX_ELECTRONICS;
// } else if (val === selValue) {
// return TAX_PERISHABLES;
// } else {
// return TAX_AUTOMOBILES;
// }
// }