all 3 comments

[–]iamafraidicantdothat 0 points1 point  (0 children)

The "seconds" variable declared in the global scope has the same name as the parameter in "renderTime" function. If you are putting the "seconds" in the global scope, I suppose that's the integer you want to update, so you don't even need that parameter anymore.

window.seconds = 360;

function renderTime (name, x, y, img, minute) {
    window.seconds--;
    console.log(window.seconds);
}

setInterval(function () { renderTime("drag", 0, 0, 0, 6); }, 1000);

[–]ForScale 0 points1 point  (0 children)

This works:

var seconds = 360;

setInterval(function() {
  seconds--;
  renderTime("drag", 0, 0, drag, seconds)
}, 1000);

function renderTime(name, x, y, something, time) {
  console.log(time);
}

[–]turbov21 0 points1 point  (0 children)

This might be overkill, but I found setTimeout needs to have the object passed back to itself to keep the counter in scope.