last day (15 days later) » 

11:16 PM
@Elton Let me know if you're still confused after reading this.
 
Hey 200
I would love to skype would that be possible? that way I could share screen?
 
I'll just type things out here, if you don't mind.
 
Ok thats fine.
Im confused as to what should happen in my code once my card has been picked.
 
Let me see if I can explain better.
 
I have edited my question and left a comment with your name in my code, to show where I am confused...
 
11:27 PM
var john = { name: "John" };
john.talk = function() { console.log("Hi, my name is " + this.name); };
john.talk();
What happens there?
 
it will run the talk method and print out Hi, my name is John
 
var pierre = { name: "Pierre" };
pierre.talk = function() { console.log("Bonjour, je m'appelle " + this.name); };
pierre.talk();
What happens?
 
The same ? Hang on no, you have never defined talk()
No you did sorry.
Bonjour, je m'appele Pierre
 
Good so far.
Now, suppose we have var people = [john, pierre];.
What happens with people[0].talk()?
How about people[1].talk()?
 
nothing because property talk does not exist?
and it is an array
 
11:31 PM
people.talk() would be an error.
But people[0] is just another way to refer to john.
Feel free to take a few minutes to try it out.
 
Ok
Ok I played with it. people.talk() returned an error wheras people[0].talk() treated it as though i typed john.talk().
 
Good. So do both people[0].talk() and people[1].talk() perform as you expect?
 
yes
 
So, imagine that the people are Monopoly cards…
 
Ok
 
11:41 PM
and there's an act() instead of talk().
 
ok
 
You see how the action can be embedded in the card, and you can just tell any card in the array to act() and it could do the "right thing"?
 
yes but in the talk() example i know which person to let talk
 
OK, let's take a smaller leap then.
 
how do i know the john or the piere in my picked card ?
 
11:44 PM
How about people[Math.random() < 0.5 ? 0 : 1].talk()?
You wouldn't know which person you picked, but whoever gets picked will greet you in his respective language.
 
It picked a random, in my case it just picked Pierre...
card[?].act, but the thing is in your answer you don't have 1 array holding all the cards, but instead two arrays, chest and chance...?
 
If you don't mind, let's ignore that there are two decks for now.
 
Ok
 
Are you sufficiently convinced of people[rand].talk()? Would you like more time to think it over? Should I back up a bit and clarify anything?
 
No that did make sense, I understood it.
 
11:51 PM
How would you add support to the people array example for a third person, e.g. a French speaker named Mireille?
 
var people = [john, pierre, mirelle];
 
How would you define mireille?
 
var mireille = { name: "Mireille" };
mireille.talk = function() { console.log("Bonjour, je m'appelle " + this.name); };
 
OK. But as you probably realize, you're repeating yourself.
 
Yes correct.
 
11:54 PM
How might you avoid such repetition?
 
you need function talk(pass relevant line)...
 
OK…
How about
mireille.talk = pierre.talk;
Would that work?
 
No because pierre.talk uses this.name which is "pierre", assuming that "this" points to the pierre object?
 
Take a moment to try it all out, then.
 
Ok
mireille.talk = pierre.talk; worked correct? how so? it got her name right?
 

  last day (15 days later) »