Skip to content

day-8, level 3 exercises q2 #666

Discussion options

You must be logged in to vote

function signUp(username, email, password) {

//Check if the user already exists
const existingUser = users.find(user => user.email === email);
if (existingUser) {
  console.log('User with this email already exists!');
  return;
}
// Create a new user object with a unique ID and current time as createdAt
const newUser = {
  _id: Math.random().toString(36).substring(2),
  username,
  email,
  password,
  createdAt: new Date().toLocaleString(),
  isLoggedIn: false
};
// Add the new user to the array
users.push(newUser);
console.log('User successfully signed up:', newUser);

}

function signIn(email, password) {
// Find the user with the given email and password
const user = users.find(user =>…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@KhuramShahzad-5335
Comment options

Answer selected by KhuramShahzad-5335
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants