Update # 2: Updated scripts.
goal
a) The user selects a button. The value of the last button pressed + .current__amount = new__amount
b) There is no current total amount. When you press the same button again, cancel the selection, and then subtract this value from .new__amount , then change the placeholder text using .html()
Problem
That's right, now for some reason, clicking on a button does not add or remove its value from .new__amount .
I am console.log(buttons[i].value) and console.log(buttons[i].class) and I see that the for loop prints the class and value of these six buttons that represent the bid at a quiet auction of $10, 25, 50 and stored in an array called var buttons = [] as I want.
scripts.js (updated)
Almost there. You just need to make sure that you can select only one button at a time.
/*------------------------------------- STEP ONE: PLACE BID --------------------------------------*/ $.ajax({ url: "https://sheetsu.com/apis/4a8eceba", method: "GET", dataType: "json" }).then(function(spreadsheet) { // Print current bid var currentBid = spreadsheet.result.pop().Bids; $(".current__amount").html("$" +currentBid); $('.button__form').on('click', function() { var value = $(this).val(); if($(this).hasClass('is-selected')) { $(this).removeClass('is-selected'); $(".check--one").css("color", "#ccc"); currentBid = parseInt(currentBid) - parseInt(value); } else { $(this).addClass('is-selected'); $(".check--one").css("color", "#ffdc00"); currentBid = parseInt(currentBid) + parseInt(value); } $('.total__amount').html("$" + currentBid); }); });
source share