• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Objects and Adding Methods

 
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Alright so this one is a lot, and I apologize in advance because I just looked at this today so it might very rough. So I am asking the user for their name, age, and gender. This is put into the Person object, and in it I have my method which is suppose to calculate life expectancy. I then have the myPerson variable of the Person object, which is suppose to take what the user entered and displayed it. Again I just looked at this not to long ago, and gave it my best shot.

Also I have never really understood what this. does, I just used it because thats the way the book has it set up. So if someone can explain that to me I would appreciate it.

Here is what I came up with

 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
First things first. What's the deal with lines 15 though 19? They have nothing to do with the rest of the code of the problem you say you are trying to solve.

Then, please fix your indentation. Indentation is an important and not optional aspect of programming. The current poor indentation hides the structure of the program and makes it hard to follow.
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Lines 15-19 are just me experimenting with the stuff in the book. It gave the whole list of navigator methods, so I just wanted to try a few.

hopefully this looks better
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So I have made changes to the code, but still need help with the output. My new person is suppose to take ehat the user entered, and display that. For my last line I give them how long they have left or can expect, so do I have to pass those variables to my new person? Or shouldn't I be able to just to use them?  Or does the "this." come into play when trying to get the values of the varaibles? Again im not entirely sure what the .this does I just followed the book

my new code
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After looking at more samples, and looking closer at the book im certain my output should look like below, but nothing prints out? The myPerson has all the properties of the Person object so there would be no need to try, and pass them. I tried just doing document.write(myPerson.fullName); to see if it prints out, but nothing. So my fullName is not getting a value?
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Cody Biggs wrote:Lines 15-19 are just me experimenting with the stuff in the book. It gave the whole list of navigator methods, so I just wanted to try a few.


But it has nothing to do with this question and just muddies the waters. it should not be included in your post.

Cody Biggs wrote:I tried just doing document.write(myPerson.fullName);


No, you didn't. Look at the code again.
 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
...I know its not in my code I was just saying that I tried it. I wanted to see if it gave me anything, and after it did not I changed it back
 
Ranch Hand
Posts: 437
Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Cody,

document.write("Gender: " + Myperson.gender);



There is a typo. It should be myPerson instead of Myperson.

 
Cody Biggs
Ranch Hand
Posts: 335
3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I caught that, but still doesn't give any output. The prompts run, but my document.writes still don't show anything.
 
Chinmaya Chowdary
Ranch Hand
Posts: 437
Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Add end script tag </script> at the end of code.
 
Bear Bibeault
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Do you have the JavaScript console open to show you your syntax errors? If not, then you are wasting your time and ours.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic