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
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?
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!
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now