- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这里的问题是,当代码运行时,它开始运行函数newJob
,然后它告诉我intelligence
is undefined
,我将其定义为 colleageChoice == 5
,或 1
和 5
之间的任何内容,但似乎没有定义它。如果任何人都可以诊断为什么它没有被定义,那将会有很大帮助。
提前致谢!
如果您需要更多信息,请告诉我!
诊断/修复问题所需的代码:
var transactionSubVar = 0
function transaction() {
transactionSubVar = prompt("Here's a bank transaction. Put in a positive number to deposit, or a negative to withdrawl. if your deposit will give you a negative pocketMoney, the bank won't allow it.")
transactionSubVar = parsefloat(transactionSubVar)
if((pocketMoney - transactionSubVar) < 0) {
confirm("The bank won't allow this transaction, sorry.")
}
if((pocketMoney - transactionSubVar) > 0) {
bankMoney = bankMoney + (transactionSubVar - (transactionSubVar * 0.09))
pocketMoney = pocketMoney - (transactionSubVar - (transactionSubVar * 0.09))
}
round()
alert("Your bank Money is now $" +bankMoney +randomVariable3 +pocketMoney)
}
function parsefloat(number) {
var numberNoCommas = number.replace(/,/g, "");
return parseFloat(numberNoCommas);
}
function random(high,low) {
return Math.floor((Math.random()*((high + 1) - low)) + low)
}
var job = "Unemployed"
function round() {
bankMoney = Math.ceil(bankMoney * 100) / 100;
pocketMoney = Math.ceil(pocketMoney * 100) / 100;
}
function intrest() {
if(bankMoney > 0) {
positiveIncome(0)
}
if(bankMoney < 0) {
negativeIncome(0)
}
round()
}
function payDay() {
bankMoney = bankMoney + (salary - (salary * 0.05))
intrest()
propertyIncome()
round()
alert("You have been paid,and your bank account has been given intrest. your new bank balance is: $" +bankMoney)
}
payDay()
transaction()
function colleage() {
var currentColleagePrice = random(300000,75000)
alert("The current average price for colleage is: $" +currentColleagePrice +" Keep this in mind when choosing a colleage.")
var colleage1Price = random(10000,100) + currentColleagePrice
var colleage2Price = currentColleagePrice - random(5000,-1000)
var colleage3Price = random(25000,1000) + currentColleagePrice
var colleage4Price = random(10000,-2000) + currentColleagePrice
var colleageChoice = prompt("Choose a colleage. (As always, put in the number, not the name.) \n (Remember, the average price currently is: $" +currentColleagePrice +"/n1) $" +colleage1Price +"\n 2) $" +colleage2Price +"\n 3) $" +colleage3Price +"\n 4) $" +colleage4Price +"\n 5) No colleage")
colleageChoice = parseFloat(colleageChoice)
if(colleageChoice == 1) {
bankMoney = bankMoney - colleage1Price
var colleage = true
}
else if(colleageChoice == 2) {
bankMoney = bankMoney - colleage2Price
var colleage = true
}
else if(colleageChoice == 3) {
bankMoney = bankMoney - colleage3Price
var colleage = true
}
else if(colleageChoice == 4) {
bankMoney = bankMoney - colleage4Price
var colleage = true
}
else {
var colleage = false
}
if(colleage == true) {
alert("Welcome to colleage " +colleageChoice +"!. For coming here, you have earned 5,000 intelligence. This can be used to earn better jobs later on.")
var intelligence = 5000
}
if(colleage == false) {
alert("We're sorry you choose not to go to colleage, but for your troubles a team of people taught you some basic job skills. You earned 500 intelligence from them. Intelligence can be used to earn better jobs later on.")
var intelligence = 500
}
}
colleage()
transaction()
function newJob() {
var newjob = ""
alert("Choose a job. (You can always put in 0 to keep your current one.)\n(Remember to put in the number instead of the job title.)")
if(intelligence > 25000) {
newjob = prompt("0: "+job +"salary: " +salary +"\n1: Hosiptial doctor. \n2: Vetrenarian \n3: Dentist ")
newjob = parsefloat(newjob)
if(newjob > 3) {
newjob = random(1,3)
}
if(newjob < 0) {
newjob = random(1,3)
}
if(newjob == 1) {
salary = 2500
job = "Hospital doctor"
}
if(newjob == 2) {
salary = 2000
job = "Vetrenarian"
}
if(newjob == 3) {
salary = 3000
job = "Dentist"
}
}
if(25000 > intelligence > 10000) {
newjob = prompt("0: "+job +"salary: " +salary +"\n1: Engineer \n2: Nurse \n3: Accountant")
newjob = parsefloat(newjob)
if(newjob > 3) {
newjob = random(1,3)
}
if(newjob < 0) {
newjob = random(1,3)
}
if(newjob == 1) {
salary = 1750
job = "Engineer"
}
if(newjob == 2) {
salary = 1500
job = "Nurse"
}
if(newjob == 3) {
salary = 1250
job = "Accountant"
}
}
if(intelligence < 10000) {
newjob = prompt("0: "+job +"salary: " +salary +"\n1: Waitor/waitress \n2: Janitor \n3: Radio station operator")
newjob = parsefloat(newjob)
if(newjob > 3) {
newjob = random(1,3)
}
if(newjob < 0) {
newjob = random(1,3)
}
if(newjob == 1) {
salary = 750
job = "Waitor/Waitress"
}
if(newjob == 2) {
salary = 200
job = "Janitor"
}
if(newjob == 3) {
salary = 550
job = "Raido talk host"
}
}
}
newJob()
payDay()
最佳答案
您的var Intelligence
仅位于方法colleage()
的范围内。如果你想在其他方法中引用var
,那么你需要在外部创建intelligence
:
var intelligence;
function colleage() {
...
if(colleage == true) {
alert("Welcome to colleage " +colleageChoice +"!. For coming here, you have earned 5,000 intelligence. This can be used to earn better jobs later on.");
intelligence = 5000;
}
if(colleage == false) {
alert("We're sorry you choose not to go to colleage, but for your troubles a team of people taught you some basic job skills. You earned 500 intelligence from them. Intelligence can be used to earn better jobs later on.");
intelligence = 500;
}
}
您还可以返回变量:
function colleage() {
...
if(colleage == true) {
alert("Welcome to colleage " +colleageChoice +"!. For coming here, you have earned 5,000 intelligence. This can be used to earn better jobs later on.");
return 5000;
}
if(colleage == false) {
alert("We're sorry you choose not to go to colleage, but for your troubles a team of people taught you some basic job skills. You earned 500 intelligence from them. Intelligence can be used to earn better jobs later on.");
return 500;
}
//it shouldn't reach here but make sure to handle this case if it does
}
var intelligence = colleage();
关于javascript - 未捕获的语法错误 : x is not defined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27236251/
我正在尝试添加 ace editor到我的应用程序。我从 github 下载它,将“ace/lib/ace”目录放到我的应用程序目录中,包括: " 在我的正文标签中: editor = ace.edi
如果有人能介绍一下 TypeScript 1.8 模块,我将不胜感激。 我有 SomeClass.ts 文件: export class SomeClass { } 然后,在我的 app.ts 中导入
今天,当我阅读php内核代码时,在目录:php5.3/Zend/Zend.h中,有一行代码让我很困惑。 代码如下: /* overloaded elements data types */ #defi
今天看php的内核代码,在php5.3/Zend/Zend.h目录下,有一行代码搞得我一头雾水。 代码如下: /* overloaded elements data types */ #define
我有一个相当大的项目,我试图将所有 JS 文件连接到一个文件中。我已经能够做到这一点,但我在实际将这两个文件实现到代码中时遇到了麻烦。 我的 Gruntfile 有一个执行串联的任务: require
1在以下示例中似乎没有必要(并且可能具有误导性),但是在用于检查 #ifdef 时我已经多次看到这种情况s: #ifndef __NEWLIB_H__ #define __NEWLIB_H__ 1 使
感谢您提供的任何帮助。我有一个 Grails 项目,我正在尝试将 Karma 安装到其中。但是,当我运行时 ./gradlew 构建 我收到以下错误: [x-10-105-56-234]SENG519
我从 Frontend Developer Interview Coding Questions 得到了这个问题.为什么下面的代码片段会打印它打印的内容?我最初认为它会抛出一个 ReferenceEr
之前的问题描述有歧义,所以我在下面修改了一些东西。谢谢。 我想像这样实现一些宏: #define AddVariable(x) \ #define x (++counter) class Ba
我知道我正试图朝自己的腿开枪 ;) 但是,它可以让我使其余(大量)代码更小且更易读。 有什么技巧可以在另一个预处理器宏中创建预处理器宏吗? 这是我正在寻找的示例。我的真实场景更复杂 // That's
在 Microsoft 的 WinDef.h 中引入了几个用于回调的#defines: #ifdef _MAC #define CALLBACK PASCAL #define WINAPI
我知道我想在腿上开枪;)但是,它可以让我使其余(大量)代码更小且更具可读性。 在另一个预处理器宏中创建预处理器宏有什么棘手的方法吗? 这是我正在寻找的示例。我的真实场景更复杂 // That's wh
当我使用这段代码时: #include #define STR(x) #x int main(void) { printf(__FILE__ STR(__LINE__) "hello!\n"
今天的问候, 您好,我是使用 vb 6.0 的初学者。我正在使用以下代码并获得“用户定义类型未定义”。代码在下面。我得到错误的行被突出显示。请帮助。我应该添加一些引用或组件吗?如果是这样,它会是什么。
当我尝试编译此代码时,在 VB6 中出现编译错误“用户定义的类型未定义”。谁能告诉我需要做什么来解决这个错误?以下是我收到错误的行: Public Conn As ADODB.Connection P
我最近将我的应用程序从 Ember 1.3 升级到了 Ember 2.4.2。然而,在使用 ember build --env production 将其部署到我的生产环境后,我注意到了一些问题。 第
这个问题在这里已经有了答案: Getting user-defined type not defined error when running code (2 个回答) 3年前关闭。 我在运行程序以通
在我的一个项目中,我最近进行了重构并重命名了很多。完成此步骤后,一切正常,所有单元测试都通过了,但是我遇到了以下问题。 当我在VBE中执行“编译”时,确实出现了“用户定义的类型未定义”错误,并出现两种
所以我的 Visual Studio 将 tag1 和 tag2 都声明为未定义,但它们的定义很清楚,我不能根据另一个定义一个吗? #define push 99 #de
在 Excel 2007 中,我有以下非常简单的 VBA 代码: Public Type specType sb As Long End Type Private Sub MyButton_C
我是一名优秀的程序员,十分优秀!