0

[Please Help, I'm Begging You] How do you set up a dictionary or index for values in JS, or, what is the proper term of what I a

I'm pretty sure that I don't know how to word this whenever I try googling it or looking in forums (here & elsewhere). I'm trying to figure out how to set up a dictionary for values, I'll try my best to explain it with the true question at the bottom: For example: Right now I am making a code for testing a deck of playing cards, here's a link: https://code.sololearn.com/WBwCY57kEnLX/#html It is nothing major at ALL since this is my first actual attempt at making some type of code, right now it's just a few arrays and a simple little function to combine a random value from each array together and display it. My end goal with it is to make it possible to play a game of Blackjack, if you don't know already, blackjack works by each card being valued based on the value or rank (2 = 2 points, 3 = 3 points, ...., face cards = 10 points, Ace = either 1 point or 11 points depending on your current hand value). MY PROBLEM/QUESTION: I want my code to understand that if the user draws a FACE card it will be valued at 10, and if it draws an ACE it will be either 1 or 11, and so on for other values. I can sort of guess how to make the code determine if it would need to use the Ace as 1 point or 11 points with an if-else statement, but my real issue is how do I get JS to actually recognize that a face card (J, Q, K) or Ace would have those specific values? This way if the code I currently have displays something like "King of Spades" then it would recognize that the card has a value of 10 points. I feel like this is super simple but no matter what I google and no matter how many walkthroughs I look up of how to make a card deck in JS I can't seem to figure out how something like this works.

2nd Aug 2018, 6:42 PM
Soup Master
Soup Master - avatar
5 Antworten
+ 9
You mean: var dict = {key1: val1, key2:val2...}; //?
2nd Aug 2018, 6:48 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 10
Yes.
2nd Aug 2018, 6:54 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 2
Valen.H. ~ Borislav Kalinski Thank you both so much. I don't know why I've had so much trouble finding this!!!!
2nd Aug 2018, 6:55 PM
Soup Master
Soup Master - avatar
+ 1
Try something like this var card = { points : 10, face : "ace" }; then if you want to use face card.face; if you want to use points card.points;
2nd Aug 2018, 6:52 PM
B K
+ 1
Valen.H. ~ Omg I think that's exactly what it is.... I must have not understood that lesson when it came up. So in my code, I have "var cards" as my array and then within it I have "cards.numbers" to establish the list of values. So in this case I would make the dictionary variable and put something like "cards.numbers.2: 2" as a "key: value" pair right?
2nd Aug 2018, 6:53 PM
Soup Master
Soup Master - avatar