I am busy creating a program which is an email Simulation. I am struggling to be able to make a function where it takes the contents and address of the email to make a new email object and push this into the inbox function. I am also struggling with a function that will mark the emails as read individually.
// An Email Simulation
class Email{
constructor(hasBeenRead, emailContents, isSpam, fromAddress){
this.hasBeenRead = hasBeenRead;
this.emailContents = emailContents;
this.isSpam = isSpam;
this.fromAddress = fromAddress;
}
getHasBeenRead(){
return this.hasBeenRead;
}
getEmailContents(){
return this.emailContents;
}
getIsSpam(){
return this.isSpam;
}
getFromAddress(){
return this.fromAddress;
}
markAsRead(){
this.hasBeenRead = true;
}
markAsSpam(){
this.isSpam = true;
}
}
const email1 = new Email(false, "Good day sir, I was unaware that i was late in submitting one of my tasks. Please forgive me", false, "[email protected]")
const email2 = new Email(false, "Hello bud, How are you today", false, "[email protected]")
const email3 = new Email(false, "I am sorry for the late reply but thank you very much for the flowers", false, "[email protected]")
const email4 = new Email(false, "I have your package and I am on my way to deliver", false, "[email protected]")
const emailRecieved = new Email(false, "This is the recieved email needed to make a new object", false, "[email protected]")
let inbox = [email1, email2, email3, email4];
console.log(inbox)
function addEmail(arr, val1){
const newEmail = new Email(false, val1.getEmailContents(), false, val1.getFromAddress())
arr.push(newEmail);
}
console.log(addEmail(inbox, emailRecieved))
userChoice = "";
while(userChoice != "7"){
userChoice = prompt("What would you like to do:n 1. Read emailn 2. Mark spamn3. Send emailn4. Delete emailn5. View spam emailsn6. View unread emailsn7. quit?");
if(userChoice == "1"){
console.log(email1.getHasBeenRead())
console.log(email2.getHasBeenRead())
console.log(email3.getHasBeenRead())
console.log(email4.getHasBeenRead())
}else if(userChoice == "2"){
console.log
}else if(userChoice == "3"){
}else if(userChoice == "4"){
}else if(userChoice == "5"){
}else if(userChoice == "6"){
console.log(email1.getEmailContents())
console.log(email2.getEmailContents())
console.log(email3.getEmailContents())
console.log(email4.getEmailContents())
}else if(userChoice == "7"){
console.log("Goodbye");
}else{
console.log("Oops - incorrect input");
}
}