I am trying to get user input and store it on an array but I can't seem to get the correct output, when I console log the results I get different arrays with 0 length
Here's my code.
let bambooInputElement = document.querySelector('.bambooInputElement');
let bambooTotal = [];
function calculateBamboo() {
bambooInputElement = bambooInputElement.value;
if (bambooInputElement < 25) {
alert('Pledge must be at least $25.');
}else {
let amountDonated = 0;
for (let i = 0; i < bambooTotal.length; i++) {
bambooTotal.push(bambooInputElement);
amountDonated = amountDonated + bambooTotal[i];
}
}
}
bambooBtnElement.addEventListener('click', calculateBamboo);
bambooTotalis always zero and hence nothing is ever pushed into the list, bring thepushstatement outside of the for loop, and try to add clarifications to what you wanna do withamountDonatedtoo.bambooInputElement = bambooInputElement.value;is quite suspect. What isbambooInputElementto start with? Why are you replacing that initial value withbambooInputElement.value? The second time you callcalcualteBamboo,bambooInputElementwill be thebambooInputElement.valuefrom the previous call.bambooInputElementis the html input element hence I'm reassigning it,bambooInputElement = bambooInputElement.value;I want the value the user enters and push it on thebambooTotalarray when a button is clicked