Skip to content

Commit

Permalink
Fix delayed calculation
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexandruIstrate committed Jan 23, 2024
1 parent a993d35 commit 0b7e0c3
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions salary-calc/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ function App() {
}, {});

// Log the processed data
console.log("PPP Data:", processed);
// console.log("PPP Data:", processed);

// Store the PPP data
setPPPData(processed);
Expand All @@ -196,7 +196,7 @@ function App() {
setSalary(newValue);

// Recalculate the new salary
calculateSalary();
calculateSalary(newValue);
}

function handleChangeSource(e) {
Expand All @@ -205,7 +205,7 @@ function App() {
setSourceCountry(newValue);

// Recalculate the new salary
calculateSalary();
calculateSalary(salary);
}

function handleChangeDestination(e) {
Expand All @@ -214,23 +214,21 @@ function App() {
setDestinationCountry(newValue);

// Recalculate the new salary
calculateSalary();
calculateSalary(salary);
}

// Utility functions

function calculateSalary() {
function calculateSalary(salary) {
// Get PPP data for the selected countries
const sourcePPP = pppData[sourceCountry].ppp;
const destPPP = pppData[destinationCountry].ppp;

// Calculate the target amount
const targetAmount = salary / sourcePPP * destPPP;
const targetAmount = parseInt(salary) / sourcePPP * destPPP;

// Set the value of the resulting amount
setResult(targetAmount);

console.log(typeof salary);
}

return (
Expand Down

0 comments on commit 0b7e0c3

Please sign in to comment.