Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

JavaScript Problems #30 . Modify the Club function again: Add a property to this called add. The value of add will be a function. This

JavaScript Problems

#30 .

Modify the Club function again: Add a property to "this" called "add". The value of "add" will be a function. This function will take a name passed to it and add that name to the members list of the club. The function can't directly refer to whatever variable you store the new Club it must use this. The function should return the Club object when it is done. Finally, run this code to get the required output: var c = new Club("computer"); c.add("john"); c.add( "fred" ); console.log( c.members );

How do you assign a function to a variable? All functions are objects. You can refer to them by name, just don't put () on the right side of the name - because that will call the function. So you can copy function objects to anywhere you wish. You can also create a function without a name, called an anonymous function - in which case, you must assign it to a variable when you create it otherwise you'll never be able to use it (because it has no name to refer to.)

Club function - please use this and modify:

function Club(name) { this.name = name; this.members = []; }

var club = new Club('computer');

club.members.push('john'); club.members.push('fred');

console.log(club);

After Modify the Club function again, output:

image text in transcribed

#31.

If your add function / method works properly and returns it's object when done - you can now do something like this: console.log( (new Club("computer")).add("john").add("fred").members )

console.log) ["john", "fred

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Accounting And Auditing Research And Databases Practitioner's Desk Reference

Authors: Thomas R. Weirich, Natalie Tatiana Churyk, Thomas C. Pearson

1st Edition

1118334426, 978-1118334423

More Books

Students also viewed these Databases questions

Question

2. What are your challenges in the creative process?

Answered: 1 week ago

Question

Prepare a short profile of Lucy Clifford ?

Answered: 1 week ago

Question

Prepare a short profile of Rosa parks?

Answered: 1 week ago

Question

Prepare a short profile of victor marie hugo ?

Answered: 1 week ago

Question

How many Tables Will Base HCMSs typically have? Why?

Answered: 1 week ago

Question

What is the process of normalization?

Answered: 1 week ago