Spaces:
Running
Running
Create script.js
Browse files
script.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const stateTaxRates = {
|
| 2 |
+
"AL": 0.04, "AK": 0.00, "AZ": 0.056, "AR": 0.065, "CA": 0.0725,
|
| 3 |
+
"CO": 0.029, "CT": 0.0635, "DE": 0.00, "FL": 0.06, "GA": 0.04,
|
| 4 |
+
"HI": 0.04, "ID": 0.06, "IL": 0.0625, "IN": 0.07, "IA": 0.06,
|
| 5 |
+
"KS": 0.065, "KY": 0.06, "LA": 0.0445, "ME": 0.055, "MD": 0.06,
|
| 6 |
+
"MA": 0.0625, "MI": 0.06, "MN": 0.06875, "MS": 0.07, "MO": 0.04225,
|
| 7 |
+
"MT": 0.00, "NE": 0.055, "NV": 0.0685, "NH": 0.00, "NJ": 0.06625,
|
| 8 |
+
"NM": 0.05125, "NY": 0.04, "NC": 0.0475, "ND": 0.05, "OH": 0.0575,
|
| 9 |
+
"OK": 0.045, "OR": 0.00, "PA": 0.06, "RI": 0.07, "SC": 0.06,
|
| 10 |
+
"SD": 0.045, "TN": 0.07, "TX": 0.0625, "UT": 0.0485, "VT": 0.06,
|
| 11 |
+
"VA": 0.043, "WA": 0.065, "WV": 0.06, "WI": 0.05, "WY": 0.04,
|
| 12 |
+
"DC": 0.06
|
| 13 |
+
};
|
| 14 |
+
|
| 15 |
+
window.onload = () => {
|
| 16 |
+
const stateSelect = document.getElementById("state");
|
| 17 |
+
for (const state in stateTaxRates) {
|
| 18 |
+
const option = document.createElement("option");
|
| 19 |
+
option.value = state;
|
| 20 |
+
option.textContent = state;
|
| 21 |
+
stateSelect.appendChild(option);
|
| 22 |
+
}
|
| 23 |
+
};
|
| 24 |
+
|
| 25 |
+
function calculateTax() {
|
| 26 |
+
const state = document.getElementById("state").value;
|
| 27 |
+
const price = parseFloat(document.getElementById("price").value);
|
| 28 |
+
const resultDiv = document.getElementById("result");
|
| 29 |
+
|
| 30 |
+
if (!state || isNaN(price)) {
|
| 31 |
+
resultDiv.textContent = "Please select a state and enter a valid price.";
|
| 32 |
+
return;
|
| 33 |
+
}
|
| 34 |
+
|
| 35 |
+
const taxRate = stateTaxRates[state];
|
| 36 |
+
const finalPrice = price * (1 + taxRate);
|
| 37 |
+
resultDiv.textContent = `Final price in ${state}: $${finalPrice.toFixed(2)}`;
|
| 38 |
+
}
|