Sunday, December 1, 2013

Cast a string to an array of characters in JavaScript by splitting on nothing.

function updateScore(increment) {
   game.score = game.score + increment;
   var numberArray = (game.score + "").split("");
   var htmlForScore = "";
   numberArray.forEach(function (number) {
      htmlForScore = htmlForScore + "<li style=\"background-image: url('score_" +
            number + ".png');\"></li>";
   });
   $('#whatever ul').html(htmlForScore);
}

No comments:

Post a Comment