swati-jagtap / javascript-practice

0 stars 0 forks source link

8.3.2(b)--Create a function called signIn which allows user to sign in to the application #97

Open swati-jagtap opened 3 years ago

swati-jagtap commented 3 years ago

const users = [ { _id: 'ab12ex', username: 'Alex', email: 'alex@alex.com', password: '123123', createdAt:'08/01/2020 9:00 AM', isLoggedIn: false }, { _id: 'fg12cy', username: 'Asab', email: 'asab@asab.com', password: '123456', createdAt:'08/01/2020 9:30 AM', isLoggedIn: true }, { _id: 'zwf8md', username: 'Brook', email: 'brook@brook.com', password: '123111', createdAt:'08/01/2020 9:45 AM', isLoggedIn: true }, { _id: 'eefamr', username: 'Martha', email: 'martha@martha.com', password: '123222', createdAt:'08/01/2020 9:50 AM', isLoggedIn: false }, { _id: 'ghderc', username: 'Thomas', email: 'thomas@thomas.com', password: '123333', createdAt:'08/01/2020 10:00 AM', isLoggedIn: false } ];

const products = [ { _id: 'eedfcf', name: 'mobile phone', description: 'Huawei Honor', price: 200, ratings: [ { userId: 'fg12cy', rate: 5 }, { userId: 'zwf8md', rate: 4.5 } ], likes: [] }, { _id: 'aegfal', name: 'Laptop', description: 'MacPro: System Darwin', price: 2500, ratings: [], likes: ['fg12cy'] }, { _id: 'hedfcg', name: 'TV', description: 'Smart TV:Procaster', price: 400, ratings: [{ userId: 'fg12cy', rate: 5 }], likes: ['fg12cy'] } ]

function signIn(Name,p) { let s=0; for(let i=0;i<users.length;i++) { var obj=users[i]; if(obj["username"]==Name)var a=true; if(obj["password"]==p)var b=true; if(a && b) { document.write(Signed In "\n" Welcome To Our Site) console.log("Signed in"); s=1; return true; break; } if(s==0) { document.write("Invalid username or password"); console.log("Invalid username or password"); } }

swati-jagtap commented 3 years ago
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Sign In</title>
    <script src="8.js"></script>
    <style>
        body{
            background-color: blueviolet;
            margin:auto;
            width:500px;
            height:500px;
        }
        button{
           padding:10px;
           margin: 300px 50%;
           text-align: center;
          width:100px;
           border-radius: 5px;
        }
    </style>
</head>
<body>
    <script>
       var Name= window.prompt("Enter username");
        var p=window.prompt("Enter password");
        if(onclick==true)
        {
            window.alert("Signed In")
        }
    </script>
    <button onclick=signIn(Name,p)>Sign In</button>

</body>
</html>

output

image image image image