Javascript Coin System Problem

So I had this problem recently with my Javascript code where I added a button and it’s supposed to make it so then it adds up coins for everytime you click on it. However, on the coinamt variable, which tracks how much coins you have, it doesn’t count up for every click you do.

var coins = 0

//shows how much coins you have
let coinamt = document.createElement('h1')
coinamt.textContent = coins
document.body.appendChild(coinamt)

//Coin generator
let coin1 = document.createElement('button')
coin1.textContent = '+1'
coin1.addEventListener('click', () => {
coins + 1
})
document.body.appendChild(coin1)

you have no code to change coins variable, nor any code to update the text with the new value

As ieahleen as said, you need a function that will increment the coins and one
that will change the textContent. You are close to making it work, though. Just a little tweak.

You could do something similar to this:

let coins = 0;

(() => {
let coinamt = document.createElement('h1')

coinamt.textContent = coins

document.body.appendChild(coinamt)

let coin1 = document.createElement('button')

coin1.textContent = '+1'

coin1.addEventListener('click', () => { // handler that changes the coins and textContent
coins++
coinamt.textContent = coins;
})

document.body.appendChild(coin1)

	})() // gets called automatically

This worked really well thanks