Challenge: Builder Pattern

In this challenge, you have to implement the builder pattern to solve the given problem.

Problem statement

In this challenge, you have to complete the implementation of the code after studying the partial code.

You have to implement the builder pattern to create an assignment. Each assignment is of a subject; it has a level meaning it is either easy, medium, or hard, and it has a due date. The announcement function given to you displays all this information. You have to figure out where to put this function’s definition and how to build the assignment step-by-step.

Input

The provided partial code

Output

Complete implementation of code and the result after calling the announcement method

Sample input

mathAssignment.announcement(); 

Sample output

"Your Math assignment is hard and due on 12th June, 2020."

Challenge

Take a close look and design a step-by-step solution before jumping on to the implementation. This problem is designed for your practice, so try to solve it on your own first. If you get stuck, you can always refer to the provided solution. Good Luck!

Press + to interact
//write-your-code-implementation-here
//figure out where you need to put this method
this.announcement = function(){
console.log(`Your ${this.subject} assignment's difficulty level is: ${this.level}. It is due on ${this.dueDate}.`)
}
try{
var assignment = new Assignment();
var assignmentBuilder = new AssignmentBuilder("Math","Hard","12th June, 2020");
var mathAssignment = assignment.make(assignmentBuilder);
mathAssignment.announcement();
}catch(e){
console.log(e);
}

Let’s look at the solution in the next lesson.