简体   繁体   中英

what is the javascript equivalent to .get()?

I'm trying to make a go fish game in javascript. I already made it in java however I want to transfer it to javascript for a project. This is my code for java.

while (getTopCard() <= 27){ //adds the first 28 cards to everyone so they have 7 cards to start the game
  if (getTopCard() <= 6) players[0].setStartHand (myDeck.getDeck().get(topCard));
  else if (getTopCard() >= 7 && topCard <= 13) players[1].setStartHand (myDeck.getDeck().get(getTopCard()));
  else if (getTopCard() >= 14 && topCard <= 20) players[2].setStartHand (myDeck.getDeck().get(getTopCard()));
  else if (getTopCard() >= 21 && topCard <= 27) players[3].setStartHand (myDeck.getDeck().get(getTopCard()));
  topCard++;
}

This is a function in my game that is supposed to deal out 7 cards to each player. I want copied this into my js file however it throws an error because .get is not a function. What would I use as an alternative while still accomplishing the same task?

if I suppose that GetDeck() return an array or a list, getDeck()[topCard] should do the job. (and if I clearly understand your code, feel comfortable to tell me if it's not)

Also, if you want to be a real JS guy don't forget to use the convention and use camelCase to name your functions ;p

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM