Question

In: Computer Science

(Javascript) /* * USER HAS ALREADY BEEN IMPLEMENTED FOR YOU: * User has the following properties:...

(Javascript)

/*
* 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 16 2019 00: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 04 2019 00:00:00 GMT-0400 (Eastern Daylight Time)
console.log(chirpsByJohn[2].printPost());

// true
console.log(chirpsByJohn[0].wasBefore(johnsChirps[1]));

// false
console.log(chirpsByJohn[1].wasBefore(johnsChirps[0]));

Solutions

Expert Solution

/*
* 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 16 2019 00: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(author, message, date) {
    this.author = author;
    this.message = message;
    this.date = date;

    this.postLength = function () {
        return this.message.length;
    };

    this.printPost = function () {
        console.log(this.message);
        console.log("By " + this.author.name + " on " + this.date.toString());
    };

    this.wasBefore = function (chirp) {
        return this.date < chirp.date;
    }
}

// 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 04 2019 00:00:00 GMT-0400 (Eastern Daylight Time)
console.log(chirpsByJohn[2].printPost());

// true
console.log(chirpsByJohn[0].wasBefore(chirpsByJohn[1]));

// false
console.log(chirpsByJohn[1].wasBefore(chirpsByJohn[0]));

Related Solutions

The < and == operators for the class Record have already been implemented for you.
The < and == operators for the class Record have already been implemented for you. Write the code necessary to complete the >, <=,>= and != operators. (hint: you do not need to know anything about the Record class to complete)
Identify three conditions that would need to be implemented (or have already been implemented) in your...
Identify three conditions that would need to be implemented (or have already been implemented) in your organization to create a culture of innovation and change.
Identify three conditions that would need to be implemented (or have already been implemented) in your...
Identify three conditions that would need to be implemented (or have already been implemented) in your organization to create a culture of innovation and change.
Identify three conditions that would need to be implemented (or have already been implemented) in your organization to create a culture of innovation and change.
Identify three conditions that would need to be implemented (or have already been implemented) in your organization to create a culture of innovation and change.
Identify three conditions that would need to be implemented (or have already been implemented) in your Lululemon Athletica to create a culture of innovation and change.
Identify three conditions that would need to be implemented (or have already been implemented) in your Lululemon Athletica to create a culture of innovation and change.
Which of the following is/are true about JavaScript object properties? A. To use dot notation, a...
Which of the following is/are true about JavaScript object properties? A. To use dot notation, a property name must be a valid JavaScript identifier B. All properties are automatically locally scoped but may be accessed by using ‘prototype’ C. Variables declared with var inside constructor functions are locally scoped and cannot be directly accessed as properties D. Variables declared with var inside constructor functions are globally scoped E. Properties that contain boolean values may not be accessed with bracket notation...
Some database administrators assume their role managing existing databases have already been fully designed and implemented....
Some database administrators assume their role managing existing databases have already been fully designed and implemented. Throughout the career of a database administrator it is likely, however, that there will be need to design a new database for the organization. There are an array of factors that influence the approach a database administrator will take when designing a new database, including the objectives of the database, the data in which it will be stored, the location and activities of the...
How do you write this code in JavaScript inside the head? Prompt the user for their...
How do you write this code in JavaScript inside the head? Prompt the user for their first name. Remember you must save the value that the user enters so that you can use that value, therefore the prompt must be in an assignment statement. Prompt the user for their last name. Have an alert box pop up that contains the first name followed by a space and then the last name followed by a short message that you make up....
Java Implementation It uses adjacency list representation, and already has the loadAdjList() function implemented for reading...
Java Implementation It uses adjacency list representation, and already has the loadAdjList() function implemented for reading adjacency lists from standard input (make sure you understand the input format and how loadAdjList() works). You need to complete the function printAdjMatrix(). import java.util.LinkedList; import java.util.Scanner; import java.util.Iterator; class Graph { private int totalVertex; private LinkedList<LinkedList<Integer>> adjList; //adjacency list of edges public Graph() { totalVertex = 0; } public void loadAdjList() { Scanner in = new Scanner(System.in); totalVertex = in.nextInt(); adjList = new...
there are files called LinkedList.h, and Array.h and all the functionality you need has already been...
there are files called LinkedList.h, and Array.h and all the functionality you need has already been implemented. There is also a file called TimeSupport.h that allows you to measure the running time of code segments. There is also a file called RandomSupport.h, which you can use to generate good random numbers. In your app.cpp , create a demo illustrating a scenario where storing numbers in a linked list is more efficient than an array. Your demo should generate a sufficiently...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT