Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3693022
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:19:46+00:00 2026-05-19T04:19:46+00:00

I am trying to learn how to create and use javascript properties and methods

  • 0

I am trying to learn how to create and use javascript properties and methods using javascript prototypes and am having a bit of difficulty.

In the following code I am trying to create a simple object called ‘radius’ that has a radius of 4 and has a method called ‘getCircumference’ which produces the circumference using the object radius’ value.

function radius()
{
    this = 4;
}

function getCircumference()
{
    var pi = 3.141592;
    var circumference = this.value * 2 * pi;
    document.write(circumference);
}

radius.prototype.circumference = getCircumference;
radius.circumference();

If someone can show me how to make this code work, and better yet, how to make this code allow the input of any radius and return the circumference each time the new method is called upon. thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T04:19:46+00:00Added an answer on May 19, 2026 at 4:19 am

    There are a couple of problems with your code, both technically and conceptually.

    On the technical side, you can’t assign to this. Change that line to this.value = 4 and combine it with pst’s suggestion (change the last line to (new radius()).curcumference()) and I believe your code will work as-is.

    Conceptually, it’s probably more useful to think of a circle as an object and as having a radius rather than thinking of the radius itself as an object. Try this:

    // traditionally, class name are TitleCased
    function Circle(radius) {
        this.radius = radius;
    }
    
    Circle.prototype = {
        circumference: function() {
            return this.radius * 2 * Math.PI;
        }
    };
    
    var circle = new Circle(4);
    document.write(circle.circumference());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In trying to learn how to create objects in ActionScript, I have had no
I am trying to learn & create Visual Studio templates and as per this
I'm trying to learn bash string handling. How do I create a bash script
Trying to learn a bit of CSS and I want a horizontal navbar and
I have been trying to learn how to add testing to existing code --
I am trying to create a personal home page for myself to learn more
I am a beginning javascript programmer. I am trying to create something similar to
I'm trying to learn about Expression trees, and I've created a method that takes
I'm trying to learn C. As a C# developer, my IDE is Visual Studio.
I am trying to learn the keyboard shortcuts in Visual Studio in order to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.