I'm working on this snippet that calculates the cost of buying multiple items at a time. Every time the user buys 1 item, the price increases by 15%.
I'm getting this error: Uncaught ReferenceError: cannot assign to function call when trying to display the total to the document.
Is it where I have converted the .toFixed() value to a number (function) so the sum is equal to a function value? How could I get around this?
function displayStore() {
// Testing on 1 item
const items = ['paw'];
// If not buying 1
if (game.storeMultiple !== 1) {
for (let item in items) {
// set p to initial price
let p = storeItems[items[item]].cost;
let sum = p;
for (let n = 1; n < game.storeMultiple; n++) {
// set p to new price
p = Number((p * 1.15).toFixed(1));
// add to sum
sum += p;
}
console.log(`${items[item]}-cost`); // logs 'paw-cost'
console.log(sum); // logs 203
document.getElementById(`${items[item]}-cost`) = sum; // Uncaught ReferenceError: cannot assign to function call
}
}
Replace
with
You cannot assign something to what a function call returns; you can only assign to variables and object properties.
Not related, but also wrong:
Replace
which is meant to be used to iterate over own properties of an object, with
which is meant to iterate over an array (which is what you are trying).