Skip to content

How to keep track of a purchase total based on number of clicks

I am trying to keep track of a running total based on number of clicks on the buttons on the site. There are 8 buttons, all of which should add $123.45 to the total when clicked, as well as alert the total.

Some of my HTML

<article class="dog-card">
  <img src="images/murphy-card.jpg" alt="a brown and white dog with a questioning look on his face" onclick="dogInfo('Murphy', 'Mix', '$123.45')">
  <p><strong>Cost to Adopt:</strong> $123.45</p>
  <p>Corrum volorit iandae nimaxim cum restia volor reicid ut et etur sunt arum rendae pla endis re ea erum, qui doluptae</p>
  <p class="adopt" onclick="addFee()">Adopt</p>

And my JS so far

function addFee() {
  let x = 123.45;
  let total = ('Your total is $' + x);


I know this JS isn’t what I need, but I just wanted to put something in so I could verify the button was working.

Any advice is much appreciated, thanks!



let LastTotal = 0;

function addFee() {
  lastTotal = lastTotal + 123.45;
  alert("Your total is $" + lastTotal);