【发布时间】:2019-07-09 01:17:56
【问题描述】:
我正在尝试使用自某个日期以来的天数作为密码创建一个页面。唯一有效的密码是静态的并用“”包围。我希望能够使用我每天的结果作为密码。我该怎么做?
在写有“if (pass1 == "abcde") {”的行上,我尝试将“abcde”更改为我的函数的名称 daysSince 以及我从该函数获得的最终 var。
function passWord() {
var testV = 1;
var pass1 = prompt('Please Enter Your Password to see deez burgerz','Password ');
while (testV < 3) {
if (!pass1)
history.go(-1);
if (pass1 == "abcde") {
alert('Lucky guess...');
window.open('http://bowenpowell.com');
break;
}
testV+=1;
var pass1 =
prompt('Access Denied - Password Incorrect, ur dumb.','Password');
}
if (pass1.toLowerCase()!="password" & testV ==3)
history.go(-1);
return " ";
}
此后几天我的功能:
function dateFunction() {
var currentDate = new Date(),
m = currentDate.getMonth() +1,
d = currentDate.getDate(),
y = currentDate.getFullYear();
var current = y + "/" + m + "/" + d;
var date2 = '2018/9/4';
current = current.split('/');
date2 = date2.split('/');
current = new Date(current[0], current[1], current[2]);
date2 = new Date(date2[0], date2[1], date2[2]);
current_unixtime = parseInt(current.getTime() / 1000);
date2_unixtime = parseInt(date2.getTime() / 1000);
var timeDifference = current_unixtime - date2_unixtime;
var timeDifferenceInHours = timeDifference / 60 / 60;
var timeDifferenceInDays = timeDifferenceInHours / 24 + 2;
document.getElementById("demo").innerHTML = timeDifferenceInDays;
}
我试过了
if (pass1 == timeDifferenceInDays) {
if (pass1 == dateFunction()) {
if pass1 == timeDifferenceInDays {
if pass1 == dateFunction() {
if pass1 == 'timeDifferenceInDays' {
if pass1 == 'dateFunction()' {
【问题讨论】:
-
首先,您在最终的
if声明中缺少&,应该是&&。 -
显示您尝试过但不起作用的代码,以便我们告诉您您做错了什么。
-
当您将
"abcde"替换为函数名称时,您是否将()放在函数名称之后?您需要这样做才能调用该函数。 -
@Barmar 我已经用我尝试过的方法更新了代码
-
dateFunction()不返回任何内容。
标签: javascript variables passwords key var