我的JavaScript代码不想工作

时间:2013-07-23 20:36:24

标签: javascript

我是新手好吗?我只是不知道我的代码有什么问题,如果有人能解决它,请向我解释......

代码:

<script>
var userMoney:10;
var userChoice = prompt("Okay young lad, you've got 3 choices, either you choose box 1,      2 or 3");
if(userChoice==="1"){
confirm("Wow. You're just that lucky, you've got 10$ added to your account");
}
if(confirm("Wow. You're just that lucky, you've got 10$ added to your account"){
userMoney:10+10;
}
var yesno = prompt("Would you like to see how much money you've got lad?");
if(yesno==="yes"){
confirm(userMoney)
} else {
confirm("Well lad I Guess that's the end of the game.");
}
if(userChoice==="2"){
confirm("Oi, bad luck Brian better luck next time");
}
if(userChoice==="3"){
confirm("Oi, bad luck Brian better luck next time");
}
</script>

3 个答案:

答案 0 :(得分:3)

var userMoney:10;

应为var userMoney = 10;

userMoney:10+10;

可以是:userMoney = userMoney + 10;userMoney += 10;

答案 1 :(得分:2)

您的第一行应为:

var userMoney=10;

你在几个地方使用过:而不是=。

此外,将来还可以使用像http://jsfiddle.net/这样的工具来审核您的脚本

答案 2 :(得分:0)

更改userMoney = 10 + 10; 并且也改变了 userMoney = 10