该如何解决我的问题?我是javascript的新手,任何建议或建议都可能对我有所帮助。
var user = {
username: "Andrey",
password: "JavaScript"
},
{
username: "Max",
password: "12345"
},
{
username: "Pasha",
password: "OWL"
};
var database = [user];
var newsfeed = [
{
username: "Bobby",
timeline: "DOOOOOOG!",
},
{
username: "Max",
timeline: "CAAAAT!",
},
{
username: "Lida",
timeline: "John Ceeeenaaaa!",
}
];
var userNamePrompt = prompt("Your Username?");
var passwordPrompt = prompt("Your password?");
function isUserValid(Name, Pass){
for (var i=0; i<database.length; i++){
if (database[i].username === Name &&
database[i].password === Pass) {
return true;
}
}
return false;
}
function SignIn (Name, Pass){
if (isUserValid(Name, Pass)) {
console.log(newsfeed);
}
else {
alert("Sorry smt went wrong!");
}
}
SignIn (userNamePrompt, passwordPrompt);
如果代码正常运行,我应该返回一个带有新闻源的数组,但是我得到了: 无效的销毁分配目标
答案 0 :(得分:0)
您写道:var user = { property }{ property }{ property }
无效。这可能就是您的意思(也跳过了var database = [ user ];
分配):
var database = [
{
username: "Andrey",
password: "JavaScript"
},
{
username: "Max",
password: "12345"
},
{
username: "Pasha",
password: "OWL"
};
]