简体   繁体   English

在“我的石头,纸,剪刀,射击游戏”中单击一个按钮后,我收到一条错误消息,声称未定义功能,但实际上是

[英]Upon Clicking a Button In My Rock, Paper, Scissors, Shoot Game, I recieve an error claiming the function is not defined, but it is

For some reason, the html code does not show up when I paste it, So I will provide a pastebin link. 出于某种原因,粘贴时html代码不会显示,因此我将提供一个pastebin链接。 When I click any of the 3 buttons, I get an error stating that the function is not defined. 当我单击这三个按钮中的任何一个时,都会显示一条错误消息,指出该函数未定义。 I am new to java script and have spent and have spent about an hour of googling and debugging, yet it still doesn't work. 我是Java脚本的新手,并且花了大约一个小时来进行谷歌搜索和调试,但仍然无法正常工作。 The game asks what mode you would like, then chooses if it lets you win, lose, or randomizes it. 游戏会问您想要哪种模式,然后选择是否让您获胜,失败或将其随机化。 It should then execute a set of logic tests to see who won. 然后,它应该执行一组逻辑测试以查看谁赢了。 This is when it gives an error saying the variable PlayerGameImput is undefined. 这是当它给出错误消息,说明变量PlayerGameImput未定义时。 Thanks in advance for the help, Justin 预先感谢您的帮助,贾斯汀

Pastebin Link: http://pastebin.com/ACR5zpd3 粘贴链接: http//pastebin.com/ACR5zpd3

PlayerGameInput is a local variable because you are defining it in each function. PlayerGameInput是一个局部变量,因为您要在每个函数中对其进行定义。

You need to put 你需要放

var PlayerGameInput;

outside the functions then 然后在功能之外

PlayerGameInput = "Rock";

Inside the function. 在函数内部。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM