最重要的是,我正在为运行的不和谐机器人编写一些代码。我自己完成了所有操作,因此很抱歉。主要问题是我在运行它时遇到了前面提到的“ typeerror math.random不是一个函数”。如果其他具有非常相似的代码的类看起来不完全相同且无法完美运行,则可以。
我已经在代码中搜索任何缺少的分号或放错位置的位。但是,正如我指定的那样,此代码可以在其他相似和几乎相同的类上完美运行。
这是代码中最重要的部分。其余的通常只是将所有消息发送出去比什么都重要。
//list of general weather conditions
var fallcondition = ["light rainfall", "Cloudy skies", "Sunny skies"];
var windy = ["North", "West", "East", "South"];
var bounty = Math.floor(Math.random() * 50);
// gets the length of each list
var fallLen = fallcondition.length;
var windlen = windy.length;
//randomly genorates temperatures for each season based on the max, all but winter should within a certain range
//FAR stands for farienheit
var randfalltemp = Math.floor(Math.random() (17 - 4 + 1) + 4);
var fallFAR = (randfalltemp * 9/5) + 32;
//Gets random wind speed
var windspd = Math.floor(Math.random() * 20);
//Genorates all the random weather conditions based on length
var randnumfall = Math.floor(Math.random() * fallLen);
var randwind = Math.floor(Math.random() * windlen);
//puts random number values into lists
var windDir = windy[randwind];
如果您很好奇,这就是工作代码的样子。正如我所说的,除了名称和新的赏金变量之外,其他都是相同的
//list of general weather conditions
var summercondition = ["Cloudy skies", "partly cloudy skies", "Sunny skies"];
var windy = ["North", "West", "East", "South"];
// gets the length of each list
var summerlen = summercondition.length;
var windlen = windy.length;
//randomly genorates temperatures for each season based on the max, all but winter are within a certain range
//FAR stands for farienheit
var randsumtemp = Math.floor(Math.random() * (35 - 20 + 1) + 20);
var sumFAR = (randsumtemp * 9/5) + 32;
//Gets random wind speed
var windspd = Math.floor(Math.random() * 12.4);
//Genorates all the random weather conditions based on length
var randnumsum = Math.floor(Math.random() * summerlen);
var randwind = Math.floor(Math.random() * windlen);
//puts random number values into lists
var windDir = windy[randwind];
该程序的最终结果是应该发送消息。到目前为止,它只发送错误报告,而不发送应该显示的消息(以后会有一个if语句,取决于值)
如果还有其他意见或其他建议,我将不胜感激。