let data =
[
{
principal: 2500,
time: 1.8
},
{
principal: 1000,
time: 5
},
{
principal: 3000,
time: 1
},
{
principal: 2000,
time: 3
}
]
console.log(data)
function interestCalculator() {
for (let i of data)
if (data[i].principal>=2500 && data[i].time>1 && data[i].time<3){
return "rate = 3"
} else if (data[i].principal>=2500 && data[i].time>=3){
return "rate = 4"
} else if (data[i].principal<2500 && data[i].time<=1 ){
return "rate = 2"
} else {
return "rate = 1"
}
}
I'm trying to write a function called "interestCalculator" that takes an array as a single argument and does the following:
Determine the rate applicable using the conditions:
If the principal is greater than or equal to 2500 and the time is greater than 1 and less than 3, then rate = 3
If the principal is greater than or equal to 2500 and the time is greater than or equal to 3, then rate = 4
If the principal is less than 2500 or the time is less than or equal to 1, then rate = 2
Otherwise, rate = 1;
But then I keep getting errors saying principal is undefined