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 8820565
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:38:26+00:00 2026-06-14T05:38:26+00:00

basically I have created an object with a method which adds several attributes in

  • 0

basically I have created an object with a method which adds several attributes in the object together. But when I try and call the method to the console log it fires out the code (which is a if statement) to me instead of the value which I was hoping it would return, so I am confused!
Why is this happening ?
Code Below:

var Granite = function(ty, gr, th, wi, le, ed, ad){
    this.type = ty;
    this.group = gr;
    this.thickness = th;
    this.width = wi;
    this.length = le;
    this.edgeProfile = ed;
    this.addOns = ad;
    this.groupPrice = function(){
        if (thickness === 20){
            switch(group)
            {
            case 1:
              return 160;
              break;
            case 2:
              return 194;
              break;
            case 3:
              return 244;
              break;
            case 4:
              return 288;
              break;
            case 5:
              return 336;
              break;
            case 6:
              return 380;
              break;
            default:
              return 380;
            }
        }else{
            switch(group)
            {
            case 1:
              return 200;
              break;
            case 2:
              return 242;
              break;
            case 3:
              return 305;
              break;
            case 4:
              return 360;
              break;
            case 5:
              return 420;
              break;
            case 6:
              return 475;
              break;
            default:
              return 475;
            }
        }   
    }
    this.price = function(){
        if(length <= 2000 && length > 1000){
            return ((edgeProfile + groupPrice)*2) - addOns;
        }else if(length <= 3000 && length > 2000){
            return ((edgeProfile + groupPrice)*3) - addOns;         
        }else if(length <= 4000 && length > 3000){
            return ((edgeProfile + groupPrice)*4) - addOns;         
        }else if(length <= 5000 && length > 4000){
            return ((edgeProfile + groupPrice)*5) - addOns;         
        }
    }
}

var granite1 = new Granite("Rosa Porrino", 1, 30, 400, 3200, 30.05, 86.18);

console.log(granite1.groupPrice);

It returns the full if statement within the groupPrice method to me

  • 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-06-14T05:38:27+00:00Added an answer on June 14, 2026 at 5:38 am

    You are not calling the method but providing reference of function to console,log(). In JavaScript you need use ‘()’ to call a function.

    this will surely work console.log(granite1.groupPrice());

    In side this.price

    use this.groupPrice(). instead of groupPrice

    Modified this,price Method

     this.price = function(){
            if(length <= 2000 && length > 1000){
                return ((this.edgeProfile + this.groupPrice())*2) - addOns;
            }else if(length <= 3000 && length > 2000){
                return ((this.edgeProfile + this.groupPrice())*3) - addOns;         
            }else if(length <= 4000 && length > 3000){
                return ((this.edgeProfile + this.groupPrice())*4) - addOns;         
            }else if(length <= 5000 && length > 4000){
                return ((this.edgeProfile + this.groupPrice())*5) - addOns;         
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created an application which inserts data into a SQL database. Basically, from
I have created an abstract base class Animal which has public virtual abstract method
So basically I have an object that takes instances and adds them to a
I'm trying to create an as.data.frame.by method which basically melts the N-dimensional by object
I have a vote model, which has a class method called score . Basically,
I have created following thing in android using android compatibility support package Basically i
Basically, I have created a custom control that uses an UpdatePanel, and as I
Basically, I am using Wireshark looking at captures that have been created previously. How
Basically, I have a model where I've created a superclass that many other classes
I have a page which basically allows an admin user to create manager user

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.