From 21e73f5f85e1e81d6623cd9cd851be31b9a7f985 Mon Sep 17 00:00:00 2001 From: Fitsumhelina Date: Fri, 22 Nov 2024 10:54:48 +0300 Subject: [PATCH] 30% compalted --- Exercises/day-1/object-exercise-3.js | 62 +++++++++++++++++----------- 1 file changed, 39 insertions(+), 23 deletions(-) diff --git a/Exercises/day-1/object-exercise-3.js b/Exercises/day-1/object-exercise-3.js index c66c54b..32ad81e 100644 --- a/Exercises/day-1/object-exercise-3.js +++ b/Exercises/day-1/object-exercise-3.js @@ -108,35 +108,51 @@ const products = [ email: 'johndoe@johndoe.com', password: '123456', 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 ){ - if(user._id === newuser._id){ - console.log('User already exists!') - return; +// const signUp = (newuser) => { + +// //solution1 +// 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{ - users.push(newuser) - console.log('User added successfully!') - break; + exists.isLoggedIn = false; + console.log ("account does not exist") } + } - } - 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. // a. Create a function called rateProduct which rates the product