@ijklmopffs
Posted
Hey. The problem is state management and updating. I don't know how to do that in vanilla JavaScript. And by state management here I mean updating the tip amount as the bill amount is being typed.
@abdullahmuslim
Posted
@ijklmopffs To do that you need to hook an onChange event to your input and update the tip on every input.
//reference tip with class name *tip*
const tip = document.querySelector(".tip");
//define bill with class name *input-bill*
const bill = document.querySelector(".input-bill");
bill.addEventListener("change", updateTip);
function updateTip(e){
//update tip value or textContent depending on what element type tio is.
}
Use onInput event for input element, the behaviour is more effective. You can choose to use different class name for your tip and bill, the idea is to reference it somehow. Let me know if you need more clarification.
@ijklmopffs
Posted
@abdullahmuslim alright, will try it out and get back to you