Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Modify the attached JavaScript file to implement a function constructor for Chirp. Your implementation should include all of the properties and methods described. At the

Modify the attached JavaScript file to implement a function constructor for Chirp. Your implementation should include all of the properties and methods described. At the bottom of the file are sample inputs and outputs to test your implementation. /*
* USER HAS ALREADY BEEN IMPLEMENTED FOR YOU:
* User has the following properties:
* name: string
* birthday: Date
*
* User has the following method:
* getDayBorn: Returns the day of the week that the user was born
* example: Wednesday
*/
function User(name, birthday){
this.name = name;
this.birthday = birthday;
this.getDayBorn = function(){
var days =[`Sunday`,`Monday`,`Tuesday`,
`Wednesday`,`Thursday`,`Friday`,`Saturday`];
return days[this.birthday.getDay()];
}
}
/*
* YOUR TASK IS TO IMPLEMENT CHIRP:
* Chirp has the following properties:
* author: User
* message: string
* date: Date
*
* Chirp has the following methods:
* postLength: Returns the length of the message, a number
* example: 155
*
* printPost: Uses console.log to print the message, author name, and date
* example:
* Hello World
* By John Doe on Sat Feb 16201900:00:00 GMT-0500(Eastern Standard Time)
*
* wasBefore: Accepts a chirp and returns true if the current chirp was posted
* before the provided chirp, else false
*/
function Chirp(){
}
// SAMPLE INPUT AND OUTPUT TO VALIDATE YOUR IMPLEMENTATION:
var john = new User(`John Doe`, new Date(`01-30-2000`));
var chirpsByJohn =[
new Chirp(john,`Hello world!`, new Date(`02-16-2019`)),
new Chirp(john,`First day of spring!`, new Date(`03-20-2019`)),
new Chirp(john,`Happy 4th!`, new Date(`07-04-2019`))
];
//12
console.log(chirpsByJohn[0].postLength());
// Happy 4th!
// By John Doe on Thu Jul 04201900:00:00 GMT-0400(Eastern Daylight Time)
chirpsByJohn[2].printPost();
// true
console.log(chirpsByJohn[0].wasBefore(chirpsByJohn[1]));
// false
console.log(chirpsByJohn[1].wasBefore(chirpsByJohn[0]));

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

Graph Databases In Action

Authors: Dave Bechberger, Josh Perryman

1st Edition

1617296376, 978-1617296376

More Books

Students also viewed these Databases questions

Question

Give the date of the Partnership Act.

Answered: 1 week ago