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')">
<h3>Murphy</h3>
<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>
</article>
And my JS so far
function addFee() {
let x = 123.45;
let total = ('Your total is $' + x);
alert(total);
}
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!
Advertisement
Answer
let LastTotal = 0;
function addFee() {
lastTotal = lastTotal + 123.45;
alert("Your total is $" + lastTotal);
}