JSFiddle - React, Tailwind, and code Playground
by lavisha99
JavaScript
let NzCollege = {
address: '1 Queen St., Auckland',
assets: [{
id: 345,
description: 'Furniture stock',
value: 50000.00
},
{
id: 346,
description: 'Company vehicles',
value: 150000.00
},
{
id: 347,
description: 'Accounts Receivable',
value: 250000.00
},
{
id: 348,
description: 'Land',
value: 1550000.00
},
{
id: 355,
description: 'Investments',
value: 50000.00
}
]
}
var company = [{name:'uoa', amount:3000000},{name:'aut', amount:600000}];
/*for(var i in NzCollege){*/
for (var j in NzCollege.assets) {
console.log(NzCollege.assets[j].value)
let randomPercent;
randomPercent = Math.floor(Math.random() * 10)
console.log('randompercent is', randomPercent);
for (let i = 0; i < company.length; i++) {
let companyAmount = company[i].amount;
console.log(' company amount', companyAmount)
let winner;
let finalPercentUoa = Math.random() < 0.5 ? -randomPercent : randomPercent;
let valueUoa = finalPercentUoa / 100 * NzCollege.assets[j].value;
let finalPercentAut = Math.random() < 0.5 ? -randomPercent : randomPercent;
let valueAut = finalPercentAut / 100 * NzCollege.assets[j].value;
while (company[i].amount > 0)
if (valueUoa > valueAut) {
winner = company[0];
winner.amount -= valueUoa;
}
else {
winner = company[1];
winner.amount -= valueAut;
}
console.log('winner is', winner.name, 'who won' , winner.amount);
return winner;
}
}
//{for (let j=0; j<nzCollege[i].assets; j++)
//{}}