So I made this formula for my input button
function addTip() {
let tip = document.querySelectorAll("input[type=button]");
tip.forEach((item) => {
item.addEventListener("click", (event) => {
console.log(item.value);
});
});
}
HTML
<input type="button" value="3" onClick="addTip()">
<input type="button" value="5" onClick="addTip()">
<input type="button" value="7" onClick="addTip()">
My problem is whenever I click on a button once, nothing happens, then I click it again and it shows in the console the value but also shows (3) because it goes through all the buttons
like this
How do I make it to where if I click on one button it will show value 3, but then if I click on the next button it will change the value to show 5 only.
Basically making a tip button option and want people to choose their tip