I need to create a function where it takes in the contents and email address from the received email to make a new Email object and push the new object into the inbox(the array).
// 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]")
let inbox = [email1, email2, email3, email4];
console.log(inbox)
//THIS IS WHERE I NEED HELP
function addEmail(arr, val1, val2){
const newObject = new Email(false, getEmailContents(val1), false, getFromAddress(val2))
arr.push(newObject)
}
console.log(addEmail(inbox, email1, email3))
console.log(inbox)