ga-wdi-exercises / project1

[project] GA- Project 1
3 stars 75 forks source link

Help me! #244

Closed zanehmw closed 8 years ago

zanehmw commented 8 years ago

For my deck of cards I have created multiple objects within an array (displayed below). I would like to create a function of some sorts to display some of the information within the arrays on my page. However , I cannot access the information within the object. How can I zero in on one property within these objects? Or is there an easier way to set up my deck?

var deck = [
  { cardPosition: "1",
    eWord: "Hello",
    kWord: "안녕하세요",
    answered: false,
   correct: false,
},
  {
    cardPosition: "2",
    eWord: "excited",
    kWord: "신났다",
    answered: false,
    correct: false,
},
  {
    cardPosition: "3",
    eWord: "What is your name?",
    kWord: "이름이 뭐예요?",
    answered: false,
    correct: false,
  },
];
andrewsunglaekim commented 8 years ago

if i wanted to get the second objects eword i could do something like this:

deck[1].eWord
=> "excited"
andrewsunglaekim commented 8 years ago

I could also do something like this:

deck.forEach(function(card){
  div = document.createElement("div")
  div.innerHTML = card.eWord
  document.body.append(div)
})

The above would generate the following html:

<body>
  <div>Hello</div>
  <div>excited</div>
  <div>What is your name?</div>
</body>
zanehmw commented 8 years ago

Thanks so much!