Advertisement
redwoolwinterhat

2. Give Me a Hand 2.2 Scoring Hint for Q is Wrong Rafa

Mar 7th, 2013
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Card Constructor
  2. var Card = function(s, n) {
  3.     var suit = s;
  4.     var number = n;
  5.     this.getSuit = function() {
  6.         return suit;
  7.     };
  8.     this.getNumber = function() {
  9.         return number;
  10.     };
  11.     this.getValue = function(){
  12.         if(number > 10){
  13.             return 10; 
  14.         }else if(number == 1){
  15.             return 11;
  16.         }else{
  17.             return number;
  18.         }
  19.     };
  20. };
  21.  
  22. function Deal() {
  23.     var suit = Math.floor(Math.random() * 4 + 1);
  24.     var number = Math.floor(Math.random() * 13 + 1);
  25.     return new Card(suit, number);
  26. }
  27.  
  28. var Hand = function() {
  29.     var card1 = Deal();
  30.     var card2 = Deal();
  31.     var hand = [card1, card2];
  32.     this.getHand = function() {
  33.         return hand;
  34.     };
  35.     this.score = function() {
  36.         var sum = 0;
  37.         for(i=0;i<hand.length;i++) {
  38.             sum += hand[i].getValue();
  39.         }
  40.         return sum;
  41.     };
  42. };
  43.  
  44. var myHand = new Hand();
  45. console.log(myHand[1].getValue());
  46.  
  47. _______________
  48.  
  49. Output:
  50.  
  51. TypeError: Cannot call method 'getValue' of undefined
  52. That's correct! Next Exercise: Show Me What You Got
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement