只是试图打印h1.name
到控制台,但我收到一个ReferenceError: h1 is not defined
错误。不管我输入 1、2 还是 3,仍然是同样的错误。我究竟做错了什么?
function Hand(name, sChips) {
this.name = name;
this.sChips = sChips;
}
function start() {
var nHands = prompt("How many hands do you want to play?(1,2, or 3)");
var nHands = Number(nHands);
if (0 < nHands < 4 ) {
if (nHands === 1) {
var h1 = new Hand("First Hand", 150000);
}
else if (nHands === 2) {
var h1 = new Hand("First Hand", 75000);
var h2 = new Hand("Second Hand", 75000);
}
else if (nHands === 3) {
var h1 = new Hand("First Hand", 50000);
var h2 = new Hand("Second Hand", 50000);
var h3 = new Hand("Third Hand", 50000);
}
else {
start();
}
}
};
start();
console.log(h1.name)