Hey guys! I've got a problem.
I've created a simple function that reads the price of an item and adds it to the "total price" section. The problem is that it reads the price of only one item. How can I modify it so it will read the price of all of the items (when the button has been clicked it reads the price of nearby div, not the first one).
Here is the example: https://codepen.io/tomaff/pen/oQQego
I want it to add 9.90 when clicked inside the div with 9.90, 15.30 when clicked inside the div with 15.30 and so on.
let data = {
breakLength: 0,
sessionLength: 0,
sessionTimer: 0,
incrementTimer: () => {
console.log(data.sessionTimer = data.sessionTimer + 1);
data.sessionTimer >= 60 ? data.sessionTimer = 0 : data.sessionTimer;
},
activateTimer: () => {
let startTimer = setInterval(data.incrementTimer, 1000);
startTimer;
},
resetTimer: () => {
clearInterval(data.activateTimer);
data.sessionTimer = 0;
}
};
document.querySelector('.start').addEventListener('click', function (e) {
data.activateTimer();
})
document.querySelector('.stop').addEventListener('click', function () {
clearInterval(data.activateTimer);
})
document.querySelector('.reset').addEventListener('click', function () {
data.resetTimer();
})
let data = {
breakLength: 0,
sessionLength: 0,
sessionTimer: 0,
timerId: null, // declare the timer id here
incrementTimer: () => {
console.log(data.sessionTimer = data.sessionTimer + 1);
data.sessionTimer >= 60 ? data.sessionTimer = 0 : data.sessionTimer;
},
activateTimer: () => {
data.timerId = setInterval(data.incrementTimer, 1000); // save the timer id
},
resetTimer: () => {
clearInterval(data.activateTimer);
data.sessionTimer = 0;
}
};
document.querySelector('.start').addEventListener('click', function (e) {
data.activateTimer();
})
document.querySelector('.stop').addEventListener('click', function () {
clearInterval(data.timerId); // clear interval using timer id
})
document.querySelector('.reset').addEventListener('click', function () {
data.resetTimer();
})
forEach
loop from an array which is present in state
but html
view only get updated when i switch to another route
and come back to same route
. i want view to get updated without changing route. Anyone know solution?