second option added

pull/420/head
Fitsumhelina 10 months ago
parent 4982ad8b25
commit 6fd93adf68

@ -103,7 +103,7 @@ const products = [
// Imagine you are getting the above users collection from a MongoDB database. // Imagine you are getting the above users collection from a MongoDB database.
// a. Create a function called signUp which allows user to add to the collection. If user exists, inform the user that he has already an account. // a. Create a function called signUp which allows user to add to the collection. If user exists, inform the user that he has already an account.
const newuser = { const newuser = {
_id: 'abc123', _id: 'eedfcf',
username: 'John Doe', username: 'John Doe',
email: 'johndoe@johndoe.com', email: 'johndoe@johndoe.com',
password: '123456', password: '123456',
@ -111,18 +111,31 @@ const products = [
isLoggedIn: false, isLoggedIn: false,
}; };
const signUp = (newuser) => { const signUp = (newuser) => {
const userexist = users.find((user) => user._id === newuser._id) // const userExists = users.some((user) => user._id === newuser._id);
if (userexist) { // if (userExists) {
// console.log('User already exists!')
// return;
// }
// else{
// users.push(newuser)
// console.log('User added successfully!')
// }
for (const user of users ){
if(user._id === newuser._id){
console.log('User already exists!') console.log('User already exists!')
return; return;
} }
else{ else{
users.push(newuser) users.push(newuser)
console.log('User added successfully!') console.log('User added successfully!')
break;
}
} }
} }
signUp(newuser); signUp(newuser);
// b. Create a function called signIn which allows user to sign in to the application // b. Create a function called signIn which allows user to sign in to the application
// The products array has three elements and each of them has six properties. // The products array has three elements and each of them has six properties.

Loading…
Cancel
Save