首页 > 解决方案 > why does javascript load before html? i put the body's content before the script but it still does'nt work

问题描述

<!DOCTYPE html>
<html>
<head>
    <title>facebook</title>
</head>
<body>
    <h1>facebook</h1>
    <script type="text/javascript" src="face.js"></script>
</body>
</html>

and here is my js code:

var database = [
    {
        username: "yotythepro",
        password: "1234"
    },
    {
        username: "ravit012",
        password: "3314"
    }
];
var newsfeed = [
    {
        username: "Bobby",
        timeline: "So tired from all that learning!"
    },
    {
        username: "Sally",
        timeline: "Javascript is sooooo cool!"
    },
    {
        username: "Mitch",
        timeline: "Javascript is preeetyy cool!"
    }
];
var signName = prompt("username?");
var signPass = prompt("password?");

function signIn(name, pass) {
    database.forEach(function(user, i){ 
        if (name === database[i].username && pass === database[i].password) {
            console.log(newsfeed);
        } else if (i === database.length - 1) {
            alert("username or password are incorrect!");
        }
    })
}
signIn(signName,signPass);

this is my code can anyone please tell me why does the h1 not load before the alerts finish even though the script tag is at the end of the body? i am new to javascript so i might have missed something super obvious.

标签: javascripthtml

解决方案



推荐阅读