Idle Commander - The Dev
Coder
I have this code all the ids in HTML exist.
```
const materials = [
{
name: 'stone_box',
amount: stoneAmt
},
{
name: 'redMushSeeds',
amount: redMushSd
},
{
name: 'cop_box',
amount: copperAmt
},
{
name: 'iron_box',
amount: ironAmt
}
]
for (const material in materials) {
if (material.amount <= 0) {
material.amount = 0;
document.getElementById(material.name).style.display = "none";
} else {
document.getElementById(material.name).style.display = 'inline-block';
}
}
```
and it gives me an error
`script.js:1281 Uncaught TypeError: Cannot read properties of null (reading 'style')`
```
const materials = [
{
name: 'stone_box',
amount: stoneAmt
},
{
name: 'redMushSeeds',
amount: redMushSd
},
{
name: 'cop_box',
amount: copperAmt
},
{
name: 'iron_box',
amount: ironAmt
}
]
for (const material in materials) {
if (material.amount <= 0) {
material.amount = 0;
document.getElementById(material.name).style.display = "none";
} else {
document.getElementById(material.name).style.display = 'inline-block';
}
}
```
and it gives me an error
`script.js:1281 Uncaught TypeError: Cannot read properties of null (reading 'style')`