Knappster
Knappster

Reputation: 33

Javascript - Unexpected token if

I'm getting an 'Unexpected token if' in the code below. I can't figure out why, the code looks legitimate to me.

var count = 30;
var counter = count;
var testinterval;

testinterval = setInterval(function() {
  $('.counter').text(counter.'s');
  if (counter == 0) {
    testFunction();
    counter = count;
  } else {
    counter--;
  }
}, 1000);

I've searched hi and low for an answer, maybe I'm just being blind.

Upvotes: 0

Views: 1904

Answers (1)

VisioN
VisioN

Reputation: 145428

Opposite to PHP, in JavaScript string concatenation should be done with +:

$('.counter').text(counter + 's');

Upvotes: 4

Related Questions