gpt4 book ai didi

Javascript If then else 语句

转载 作者:行者123 更新时间:2023-11-28 15:47:39 25 4
gpt4 key购买 nike

我正在尝试使用 If then else 语句调用警报中的变量。

我正在页面加载时创建全局变量 currentmonth。我测试了一个值正在加载到当前月份并且它正在工作。

我还在页面加载时创建全局变量(一月日期到十二月日期)。我还测试了这些值,它们正在发挥作用。

基本上我想要做的是获取当前月份并将其与数组中的值进行比较并在警报中显示消息。例如,一月份的信息是“迷你高尔夫 - 高尔夫可能是迷你的,但竞争将很激烈。胜利者将获得战利品!”二月的信息是“远足——重要的不是目的地,而是旅程。”

下面是我为此创建的函数,但我无法让它工作。我错过了什么?

    <script>
function dateMonth()
{
var currentdate = "";
if (currentmonth == "January")
{
currentdate = datejanuary;
}
else if (currentmonth == "February")
{
currentdate = datefebruary;
}
else if (currentmonth == "March")
{
currentdate = datemarch;
}
else if (currentmonth == "April")
{
currentdate = dateapril;
}
else if (currentmonth == "May")
{
currentdate = datemay;
}
else if (currentmonth == "June")
{
currentdate = datejune;
}
else if (currentmonth == "July")
{
currentdate = datejuly;
}
else if (currentmonth == "August")
{
currentdate = dateaugust;
}
else if (currentmonth == "September")
{
currentdate = dateseptember;
}
else if (currentmonth == "October")
{
currentdate = dateoctober;
}
else if (currentmonth == "November")
{
currentdate = datenovember;
}
else
{
currentdate = datedecember;
}
{
vex.dialog.alert(currentdate);
}
</script>

最佳答案

简单地说:

var messages = [
"Mini Golf – the golf may be mini, the competition will be big. To the winner go the ..",
"Hike – it’s not about the destination, it’s about the journey.",
"..."
];

alert( messages[new Date().getMonth()] );

(一月的getMonth() == 0)

关于Javascript If then else 语句,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21708449/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com