I'm fairly new to JavaScript and jQuery so any other advice you might have please leave in a comment below. I am making a card game to be played on a single screen in javascript.
Inside the div for id playerHand, I use a javascript function to output the hand of the current player's turn. Whenever I output the current player's hand, I get an output in that div like so:
undefined/ 6H / AD / 7H / 5H / 6S / KC / 8C / 10H / AC / 2H / 8S / 2D / 3S
The hand is made of 13 cards(denoted by numbers 2-10 and J, Q, K, A with a letter for hearts, spades, clubs and diamonds). All 13 cards print out to the div correctly but this random undefined thing is unexpected. The JavaScript function used to output this information is below.
JavaScript jQuery function:
function addHand() {
var htmlString;
for(i = 0; i < hands[currentPlayersTurn].handArray.length; i++) {
htmlString += "/ "+ hands[currentPlayersTurn].handArray[i].name +" ";
}
$("#playerHand").html(htmlString);
}