Question: Compulsory Task 1 In this task, were going to be simulating an email message. Some of the logic has been filled out for you in
Compulsory Task 1 In this task, were going to be simulating an email message. Some of the logic has been filled out for you in the email.js file.
Open the file called email.js.
Create a class definition for an Email that has four attributes.: hasBeenRead, emailContents, isSpam, and fromAddress.
The constructor should initialise the senders email address and the email contents.
The constructor should also initialise hasBeenRead and isSpam to false.
Create a function in this class called markAsRead which should change hasBeenRead to true.
Create a function in this class called markAsSpam which should change isSpam to true.
Create an empty array called inbox to store all emails (note that you can have an array of objects). Then create the following functions::
addEmail - which takes in the contents and email address from the received email to make a new Email object and push this object into the inbox.
getCount - returns the number of messages in the store in the inbox.
getEmail - returns the contents of an email in the inbox. For this, allow the user to input an index i.e. get_email(i) returns the email stored at position i in the inbox. Once this has been done, has_been_read should now be true.
getUnreadEmails - should return a list of all the emails that havent been read.
getSpamEmails - should return a list of all the emails that have been marked as spam.
delete - deletes an email in the inbox. Allow the user to enter an index on the email that he wants to delete and remove that object from the inbox list. Now that you have these set up, lets get everything working! Fill in the rest of the logic for what should happen when the user inputs the number from the menu list on the template. Some of it has been done for you.
here is the js. template provided:
// An Email Simulation
/* create your email class here */
userChoice = ""; while(userChoice != "7"){ userChoice = prompt("What would you like to do: 1. Read email 2. Mark spam 3. Send email 4. Delete email 5. View spam emails 6. View unread emails 7. quit?");
if(userChoice == "1"){
// Place your logic here
}else if(userChoice == "2"){
// Place your logic here
}else if(userChoice == "3"){
// Place your logic here
}else if(userChoice == "4"){
// Place your logic here
}else if(userChoice == "5"){
// Place your logic here
}else if(userChoice == "6"){
// Place your logic here
}else if(userChoice == "7"){
console.log("Goodbye");
}else{ console.log("Oops - incorrect input");
} }
Please fill in only the neccessary code in javascript
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
