Trying to add an inventory system to my CYOA game

comments within the JS code highlight where I’ve messed with code/tried to locate problems/solutions.

My apologies in advance, only coding for 3 days, definitely into a project that I don’t have the requisite knowledge for.

Trying to display contents of an Inventory array (myInventory variable) inside of a const textObject set up that holds informaton about the current image/audio/story text and options the player can choose.

Thank you in advance for any help you can offer!

Wow! This is really good for you only coding for three days!

If you want to add an item to an inventory variable, try doing something like
inventory.push(new_item) where ‘inventory’ is the array variable and ‘new_item’ is the value that you will add.

if you want to display the inventory variable in HTML, do something like
[element].innerHTML = inventory. the [element] can be a document.querySelector, document.getElementById, document.getElementByClassName, etc.

Hope that helped!

Thank you so much!

I started watching a 3hr JavaScript crash course last night and realized I was all over the place with what I was trying to do / asking. I appreciate your help.

Most of the JavaScript was copied from a YouTube video. I’ve been really trying to break it and fix it and was able to implement the sound and images into an existing function so that was neat.

I’ll clean it up and make another attempt!

Take care

1 Like