30% compalted

pull/420/head
Fitsumhelina 10 months ago
parent 6fd93adf68
commit 21e73f5f85

@ -108,9 +108,12 @@ const products = [
email: 'johndoe@johndoe.com', email: 'johndoe@johndoe.com',
password: '123456', password: '123456',
createdAt: '08/01/2020 10:15 AM', createdAt: '08/01/2020 10:15 AM',
isLoggedIn: false, isLoggedIn: null,
}; };
const signUp = (newuser) => {
// const signUp = (newuser) => {
// //solution1
// const userExists = users.some((user) => user._id === newuser._id); // const userExists = users.some((user) => user._id === newuser._id);
// if (userExists) { // if (userExists) {
// console.log('User already exists!') // console.log('User already exists!')
@ -121,22 +124,35 @@ const products = [
// console.log('User added successfully!') // console.log('User added successfully!')
// } // }
for (const user of users ){ // // solution 2
if(user._id === newuser._id){ // for (const user of users ){
console.log('User already exists!') // if(user._id === newuser._id){
return; // console.log('User already exists!')
// return;
// }
// else{
// users.push(newuser)
// console.log('User added successfully!')
// break;
// }
// }
// }
// signUp(newuser);
// b. Create a function called signIn which allows user to sign in to the application
const signIn = (newuser) => {
const exists = users.find(user => user._id === newuser._id);
if (exists){
exists.isLoggedIn = true;
console.log ("user signIn success")
} }
else{ else{
users.push(newuser) exists.isLoggedIn = false;
console.log('User added successfully!') console.log ("account does not exist")
break;
} }
}
}
signUp(newuser);
// 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.
// a. Create a function called rateProduct which rates the product // a. Create a function called rateProduct which rates the product

Loading…
Cancel
Save