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
JavaScript
x
8
1
<article class="dog-card">
2
<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')">
3
<h3>Murphy</h3>
4
<p><strong>Cost to Adopt:</strong> $123.45</p>
5
<p>Corrum volorit iandae nimaxim cum restia volor reicid ut et etur sunt arum rendae pla endis re ea erum, qui doluptae</p>
6
<p class="adopt" onclick="addFee()">Adopt</p>
7
</article>
8
And my JS so far
JavaScript
1
7
1
function addFee() {
2
let x = 123.45;
3
let total = ('Your total is $' + x);
4
5
alert(total);
6
}
7
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
JavaScript
1
6
1
let LastTotal = 0;
2
3
function addFee() {
4
lastTotal = lastTotal + 123.45;
5
alert("Your total is $" + lastTotal);
6
}