markvs Posted October 9, 2012 Report Posted October 9, 2012 (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 October 10, 2012 by markvs Quote
falkencreative Posted October 9, 2012 Report Posted October 9, 2012 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? Quote
markvs Posted October 10, 2012 Author Report Posted October 10, 2012 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! Quote
Recommended Posts
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.