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

  • SEARCH
  • Home
  • 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 8553199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:35:51+00:00 2026-06-11T14:35:51+00:00

I try to send a name and a color to the constructor function below.

  • 0

I try to send a name and a color to the constructor function below. The method this.whatAreYou() should to retrieve these strings when called.

I want to display this on the screen.

I have the following code:

function Gadget(name, color) {
    this.name = name;
    this.color = color;
    this.whatAreYou = function() {
        return 'I am a ' + this.name+ ' ' + this.color;
    };
}

string = Gadget(grass, green);
alert(string);​

however the alert is not functioning. How can I achieve my desired behaviour?

  • 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-11T14:35:52+00:00Added an answer on June 11, 2026 at 2:35 pm

    Your Gadget isn’t a string. It just holds a function returning a string.

    As you seem to try to create an instance of the Gadget class, you need to use the new operator.

    If grass and green aren’t predefined variables but strings, you need to put them between quotes.

    Try

    var g = new Gadget('grass', 'green');
    alert(g.whatAreYou());​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am receiving a null exception every time I try to send the HttpContext.Current.User.Identity.Name
i receive this error when i try to send a form link(rel='stylesheet',href='/stylesheets/home/profile/home_menu.css') script(type='text/javascript',src='/javascripts/perfil_editar.js') #logo_usuario
When i try to send email using PHPMailer class I get this error :
i try to send private message to followers of a user who is already
I try to send an email, but I have a problem, however, I found
I try to send gps longitude and latitude to the android emulator with eclipse,
I try to send a request to my server via GET, but qooxdoo sends
i try to send some data to my php file from ajax , but
i try to send data to my php scripts but i think i miss
i try to send my datas to php with ajax but there's strange mistake.

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.