30% compalted

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

@ -108,35 +108,51 @@ 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 userExists = users.some((user) => user._id === newuser._id);
// if (userExists) {
// console.log('User already exists!')
// return;
// }
// else{
// users.push(newuser)
// console.log('User added successfully!')
// }
for (const user of users ){ // const signUp = (newuser) => {
if(user._id === newuser._id){
console.log('User already exists!') // //solution1
return; // const userExists = users.some((user) => user._id === newuser._id);
// if (userExists) {
// console.log('User already exists!')
// return;
// }
// else{
// users.push(newuser)
// console.log('User added successfully!')
// }
// // solution 2
// for (const user of users ){
// if(user._id === newuser._id){
// 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