I get the wrong calculation, and the function does not return 3 values from the elements .investment, so that I can calculate them and output them to the elements .payout. What am I doing wrong here?
function investmentArray() {
$('.investment').each(function() {
var text = $(this).text().slice(0, -2);
text = parseFloat(text.replace(/,/g, ''));
text = Number(text);
return text;
});
};
function payoutCalc() {
var i = investmentArray();
return i * 1.8;
}
var payoutArray = function() {
var el = $('.payout');
el.each(function() {
var result = Number(payoutCalc()).toFixed(2);
$(this).html(result + " $");
});
}
payoutArray();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<table>
<tr>
<th>Investment</th>
<th>Payout</th>
</tr>
<tr>
<td class="investment">1,937.00 $</td>
<td class="investment">285.00 $</td>
<td class="investment">1,926.00 $</td>
</tr>
<tr>
<td class="payout"></td>
<td class="payout"></td>
<td class="payout"></td>
</tr>
</table>
Run code
Randy source
share