Count to target with JavaScript
function count(from, to, targetElem) {
    targetElem.innerHTML = 'Total wordcount: ' + from;

    if (from == to) return;

    from &lt; to ? from++ : from--; 

    var changeTime = Math.max(20, 1000 - Math.abs(from - to)) / 2;

    setTimeout(function() {count(from, to, target);}, changeTime);
}

count(50, 0, document.getElementById("t"));


A few notes:


avoid global variables to conserve state - use function arguments instead
always use var to declare variables. Otherwise they are in the global scope and you don't want this
added error checking (i.e. whether values are numeric and target is valid) might not be a bad idea, I left it out for clarity here
return early on known conditions, this reduces complexity in the function body 
the ternary operator condition ? ifTrue : ifFalse can be used in other ways than assigning a value