(i am new to JS and i am facing a problem with getting user input in one of the functions)
i am writing a code where i have three classes (book, donor, bookCatalog)
class ‘book’ and ‘donor’ have only constructors while ‘bookCatalog’ have some functions like addbook(), addDonor() etc.
in one of the functions (in bookCatalog) i’m supposed to change the donor’s information, the function receives the donor id then search in a list of donors with that id and updates the donor attributes (like name,phone etc.)
i am supposed to test these methods in a new file but the problem is i dont know how to get the input from the user
i tried using prompt but i got an error “prompt is not defined”
Q. should the prompt be in the test file or inside ‘updateDonor’ function?
class bookCatalog:
export class BookCatalog{
constructor(books, donors) {
this.books = []
this.donors = []
}
updateDonor(donorId){
const Id = prompt("enter donor ID: ")
const firstname = prompt("enter first name: ")
const lastname = prompt("enter lastname: ")
const phone = prompt("enter phone number: ")
const street = prompt("enter street: ")
const city = prompt("enter city: ")
const email = prompt("enter email: ")
const password = prompt("enter password: ")
this.donors = this.donors.map(d =>{
if(d.donorId === donorId){
return {...d,
donorId: Id,
firstname: firstname,
lastname: lastname,
phone: phone,
street: street,
city: city,
email: email,
password: password
}
}
return d
})
}
}
test file:
import {BookCatalog} from "./BookCatalog.js";
import {Donor} from "./Donor.js";
let catalog = new BookCatalog();
let donor1 = new Donor(0.1,"alex","A",726836,"st","chicago","[email protected]","123456")
catalog.addDonor(donor1)
console.log("donor 1 information after updating: ")
console.log(catalog.updateDonor(0.1))