-1

我在 javascript 中创建了一个每周事件管理器。但出了点问题。代码不工作。请有人解决故障。有什么问题吗??????

var plan=prompt("Hello , Made a week plan. Type the week name to add a event");
var week = ["saturday" , "sunday" , "monday" , "tuesday"];
var saturday;
var sunday;
var monday;
var tuesday;

if( plan == "saturday" ) {

var saturday=prompt("What will you do in saturday?");

} else if ( plan == "sunday") {

var sunday=prompt("What will you do in sunday?");

} else if (plan == "monday") {

var monday=prompt("var getknow=prompt(""What will you do in monday?");

} else if (plan == "tuesday" ) {

var tuesday=prompt("What will you do in tuesday?");

} 


var getknow=prompt("Do you want to cheack the schedule? Type the week name");


if ( getknow == saturday) {

alert(saturday);

} else if (getknow == sunday ) {

alert(sunday); 
} else if (getknow == monday) {

alert(monday); 

} else if (getknow == tuesday) {

alert(tuesday);

}

没有这些代码行,现在一切正常

var getknow=prompt("Do you want to cheack the schedule? Type the week name");

if ( getknow == saturday) {

alert(saturday);

} else if ( getknow == sunday ) {

alert(sunday); 

} else if ( getknow == monday ) {

alert(monday); 

} else if ( getknow == tuesday ) {

alert(tuesday);

}
4

2 回答 2

2

嗯,你有一些错误,但继续学习,随着时间的推移,你不会犯很多错误。阅读下面的评论,同时检查这段代码,它应该可以正常工作。

我将在下面列出错误。第一个是:

var monday=prompt("var getknow=prompt(""What will you do in monday?");

然后我看到你两次声明了相同的变量,你不需要这样做:

var sunday=prompt("What will you do in sunday?");
var tuesday=prompt("What will you do in tuesday?");
var sunday=prompt("What will you do in sunday?");

稍后您将用户的答案与变量进行比较,它应该是一个字符串:

    if ( getknow == saturday) {

alert(saturday);

} else if (getknow == sunday ) {

alert(sunday); 
} else if (getknow == monday) {

alert(monday); 

} else if (getknow == tuesday) {

alert(tuesday);

}

此代码应该可以工作:

var plan = prompt("Hello , Made a week plan. Type the week name to add a event").toLowerCase(),
    week = ["saturday" , "sunday" , "monday" , "tuesday"],
    saturday,
    sunday,
    monday,
    tuesday;

if( plan === "saturday" ) {

    saturday = prompt("What will you do in saturday?");

} 

else if ( plan === "sunday") {

    sunday = prompt("What will you do in sunday?");

} 

else if (plan === "monday") {
    //ERROR var monday=prompt("var getknow=prompt(""What will you do in monday?");
    monday = prompt("What will you do in monday?");

} 

else if (plan === "tuesday" ) {

    tuesday = prompt("What will you do in tuesday?");

} 


var getknow = prompt("Do you want to cheack the schedule? Type the week name");

// Also here, the prompt will be a sting not a variable
if ( getknow === "saturday") {

alert(saturday);

} 

else if (getknow === "sunday" ) {

alert(sunday); 
} 

else if (getknow === "monday") {

alert(monday); 

} 

else if (getknow === "tuesday") {

alert(tuesday);
}
于 2013-05-09T13:39:36.043 回答
1

这条线绝对是个问题。字符串中有两个 " 符号。可能您在其中复制了一些您不想复制的内容。

var monday=prompt("var getknow=prompt(""What will you do in monday?");
于 2013-05-09T13:27:51.577 回答