Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Part1.Start with this Squirrel program. Modify so that all Squirrels have a jump() method. Add all of your Squirrels to a list. Iterate over the

Part1.Start with this Squirrel program.

Modify so that all Squirrels have a jump() method.

Add all of your Squirrels to a list. Iterate over the list using a for loop. Print each squirrel's name, and called the .jump() method for each squirrel.

//Acts as our class definition - define a constructor

var Squirrel = function(n) {

this.name = n;

this.nuts = 0;

};

//Add a method to the Squirrel class

Squirrel.prototype.sayHello = function() {

console.log("Hello!");

};

//Add another method

Squirrel.prototype.faveFood = function(){

console.log(this.name + " likes nuts");

};

//And another method

Squirrel.prototype.addNutsToStore = function(newNuts) {

this.nuts += newNuts;

};

var fluffy = new Squirrel("Fluffy");

//Call some squirrel methods for fluffy

fluffy.sayHello();

fluffy.addNutsToStore(10);

fluffy.faveFood();

fluffy.addNutsToStore(15);

console.log(fluffy.nuts);

var squeaky = new Squirrel("Squeaky");

squeaky.faveFood();

squeaky.sayHello();

//Can you call addNutsToStore for this Squirrel?

//Adding properties to one Squirrel only

squeaky.tree = "Oak Tree";

console.log("Squeaky's tree is : "+ squeaky.tree); // "Oak Tree"

//Fluffy doesn't have a tree

console.log("Fluffy's tree is : "+ fluffy.tree); // "undefined"

//Add a jump method only for fluffy

fluffy.jump = function() {

console.log(this.name + " is jumping!");

};

fluffy.jump(); //This works

// squeaky.jump(); //Calling this results in an error - squeaky doesn't have a jump method

Part2.

Use the setInterval method to draw a circle moving across your canvas. You'll need to clear the canvas with clearRect(), and draw the circle in a new position every interval. (Here's an example of setInterval updating a canvas

Part3.

Create a page for a very simple drawing program. When you move the mouse over the canvas, mousemove events are generated. For every mousemove event, draw a small circle under the mouse pointer. So, the user will be able to use the mouse to draw.

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

Learning MySQL Get A Handle On Your Data

Authors: Seyed M M Tahaghoghi

1st Edition

0596529465, 9780596529468

More Books

Students also viewed these Databases questions

Question

How is IMC involved in creating social meaning for a brand?

Answered: 1 week ago

Question

What would your clients like you to do more of/less of?

Answered: 1 week ago

Question

Identification of key stakeholders and decision makers

Answered: 1 week ago