脚本产生我找不到的错误
最终目的是返回一个显示以下句子的页面
从前,有一个名为 NAME
的性别,他有一个名为 PET NAME 的宠物。
<SCRIPT language="JavaScript">
var heroGender, heroName, petType, petName;
heroGender = window.prompt('Is the hero female or male? Enter F or M', 'F');
heroName = window.prompt('What is the hero\'s name?','');
petType = window.prompt('What type of pet does the hero have?','');
petName = window.prompt('What is name of the pet?','');
document.write('Once upon a time there was a ');
if (heroGender == ('F'))
{
document.write('girl');
}
else
{
document.write('boy');
}
document.write('Once upon a time there was a ' + heroGender + ' named ' + heroName '.''<BR>' +
heroName + ' had a ' + petType + ' called ' + petName + '.');
</SCRIPT>
The ultimate aim is to return a page displaying the following sentence
Once upon a time there was a GENDER named NAME
who had a PET named PET NAME.
<SCRIPT language="JavaScript">
var heroGender, heroName, petType, petName;
heroGender = window.prompt('Is the hero female or male? Enter F or M', 'F');
heroName = window.prompt('What is the hero\'s name?','');
petType = window.prompt('What type of pet does the hero have?','');
petName = window.prompt('What is name of the pet?','');
document.write('Once upon a time there was a ');
if (heroGender == ('F'))
{
document.write('girl');
}
else
{
document.write('boy');
}
document.write('Once upon a time there was a ' + heroGender + ' named ' + heroName '.''<BR>' +
heroName + ' had a ' + petType + ' called ' + petName + '.');
</SCRIPT>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
在等待书籍时!
从 Mozilla 开发者中心!
示例:
示例
固定版本
损坏的版本
您缺少
+
符号。尝试使用
监视任何错误消息。
如果这太费力,那么请尝试
这是一个“改进的”更符合标准的版本。 示例链接!
HTML:
JavaScript:
上面的代码在 IE8 或更低版本下会崩溃:(。让 JavaScript 跨浏览器工作是一件痛苦的事。
所以你可以阅读浏览器的文档
但这些文档不容易阅读或导航。跨浏览器脚本编写的一个很好的视觉指南是 visibone BrowserBook。
它将显示跨浏览器支持(红色是 firefox,蓝色是 IE):
给它几个月的时间,您就会知道如何舒适地使用所有这些。
While your waiting for the books!
Learn from Mozilla Developer Centre !
An Example:
Example
Fixed version
Broken version
You were missing to
+
symbols.Try using
To watch for any error messages.
If that's too much effort then try
Here's an "improved" more standards compliant version. Example Link!
HTML:
JavaScript:
The above code will break for IE8 or less :(. Making JavaScript work cross browser is a right pain.
So I you could read the documentation for browsers at
But those are not easy to read or navigate. A great visual guide for cross browser scripting is the visibone BrowserBook.
It will show cross browser support (red is firefox, blue is IE) :
Give it a few months and you'll know how to use all that comfortably.
我认为您的最终 document.write 中有一些拼写错误。您在 HeroName 之后缺少一个“+”...并且您有一些重复的 document.writes。
我认为这应该是您的最终代码:
I think you had some typos in your final document.write.You're missing a '+' after heroName... and you've got some duplicative document.writes.
Here's what I believe should be your final code:
此行中有一个语法错误:
具体而言,此处:
如果将其更改为此,则应该按预期工作:
请注意,我还删除了该短语第一部分中的冗余,因为您已经将其包含在“if”之前“F”,然后是“女孩””声明。
There is a syntax error in this line:
specifically, here:
If you change it to this, your should work as expected:
Notice that I also removed the redundancy from the first part of the phrase, since you already included it before your "if 'F', then 'girl'" statement.
太多引号和缺少的加号
应该是
http://jsfiddle.net/mplungjan/zHGsD/
Too many quotes and a missing plus
should be
http://jsfiddle.net/mplungjan/zHGsD/
我通过添加包裹在
**
中的两个+
来运行它I got it to run by adding the two
+
that I've wrapped in**
问题出在你的最后一行。更正如下
The problem is on your last line. Corrected as follow