Jump to content

Recommended Posts

Posted (edited)

Why does this code display the code for the getValue function and not the return value?

 

// Card constructor, using private variables.
var Card = function(s,n) {
'use strict';
var suit = s;
var number = n;
this.getSuit = function(){ return suit; };
       this.getNumber = function(){ return number; };
       this.getValue = function () {
   	if (number>= 10 && number <=13){ return 10; }
   	else if ( number>=2 && number<=9) { return number; }
   	else if (number === 1) { return 11; }
   	else {return "what the heck";}
};
};

var card1 = new Card(2, 11);
var card2 = new Card(10, 13);

alert(card1.getValue);
alert(card2.getValue);

Edited by markvs
Posted

I'm not completely sure what you are asking... but since you are supposedly calling a function within your alerts(), I would expect that you would need to call card1.getValue() and card2.getValue() (note the parenthesis).

 

Does that help?

Posted

I'm not completely sure what you are asking... but since you are supposedly calling a function within your alerts(), I would expect that you would need to call card1.getValue() and card2.getValue() (note the parenthesis).

 

Does that help?

 

Yes Ben, that did the trick. I had left off the parenthesis.

Thanks!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...