Reputation: 60
The priceCur needs to update to a new value every time a random num is generated at 9 or 10. This seems not to be happening, and I don't see why.
var companyOne = {
industry:"tech",
cName:"",
totalShares:100000,
priceStart:10,
priceCur:10
};
var randomGenerated = Math.floor((Math.random() * 11) + 0); // 0 - 10
console.log(randomGenerated);
if(randomGenerated >= 9){
companyOne.priceCur = companyOne.priceCur * (1 + 0.050); //5% increase
console.log('current_share', companyOne.priceCur)
}
Upvotes: 0
Views: 45
Reputation:
At the moment it only runs once, because you are only assigning and logging a value once. In order for it to change multiple times, you'll need to add a conditional statement or an event listener etc so that it runs multiple times. Here is an example (an infinite loop):
while (true) {
var companyOne = {
industry:"tech",
cName:"",
totalShares:100000,
priceStart:10,
priceCur:10
};
var randomGenerated = Math.floor((Math.random() * 11) + 0); // 0 - 10
console.log(randomGenerated);
if(randomGenerated >= 9) {
companyOne.priceCur = companyOne.priceCur * (1 + 0.050); //5% increase
console.log('current_share', companyOne.priceCur)
}
}
Upvotes: 1