我們試圖用生產日期(在實際日期)使用javascript數組來存儲信息。Javascript If語句
我們有三個數組,一個存儲日期,月份和人員。
所以這裏是我們現在有:
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/main.css">
<!--
Look Into Connectors
28 JANUARY 2015
Assignment 1
Author:
Date:
This is the index/ homepage of the website. It is the main page that a user should land on.
Filename: webpage
supporting files:
-->
<title>A Look Into IT</title>
</head>
<meta charset="UTF-8">
<meta name="description" content="This is a website that offers free information on IT">
<body>
<script type="text/javascript">
<!--
var bmonth = ["4","4","4","4", "4", "4", "4"]
var bday = ["8","6","27","22", "23", "23", "9"]
var person = ["Jesse", "john","billy" , " Buddy Dyer", "John Morgan", "Will Smith", "Jonny"]
var currentTime = new Date()
var month = currentTime.getMonth() + 1
var day = currentTime.getDate()
var year = currentTime.getFullYear()
document.write(month + "/" + day + "/" + year)
for(i=0; i<=6; i++){
if (month = bmonth[i]){
if(day = bday[i]){
document.write(person[i])
}
}else{
document.write("There are no birthdays today")
}
}
//-->
</script>
</body>
</html>
這裏是輸出: 4月22日/ 2015JessejohnbillBuddyDyerJohnMorganWillSmithjonny
它只是打印所有的陣列信息。
您確實需要更改問題標題。這不是關於if語句(動詞),而是關於爲什麼你的代碼沒有按預期工作 – AmmarCSE
而不是硬編碼你的'for'循環停止在'6',你可能想要考慮添加更多的人/生日,所以你的代碼是靈活的。也許有'數組'的一些屬性,我不知道它是否包含它所包含的項目的數量,因此您可以將其存儲在變量中? ;)正如其他人指出的,看看賦值與平等:'='vs'=='還是'==='。 – mc01