在這裏我有兩個「班」做卡和卡。卡基本上是與特定的一組方法:爲什麼不能運行此JavaScript?
- 附加卡
- 取出存儲卡
- 排序和洗牌
卡被用於保持西裝的值並輸出字符串拼接對象都。
我在這裏的問題是試圖運行這個代碼,即按鈕單擊setup()
。 我發現當我剛創建一張卡時,它仍然運行。我知道這是因爲輸出仍然會變成hello world。
但是,當我嘗試將卡片添加到卡片類或卡組時。腳本停止運行。我不知道這是爲什麼,我有一種感覺,它不喜歡我如何使用陣列。
這就是問題之一。
我的第二個問題是,當我
var temp= new card('c','2');
alert(temp.getvalue());
這也將失敗。
任何有關我在這裏做錯了什麼的洞察將有助於和讚賞。
function setup() {
var temp = new card('c', '2');
var textbox = document.getElementById("output");
textbox.value = "Hello, world!";
};
Array.prototype.shuffle = function() {
for (var i = this.length - 1; i > 0; i--) {
var j = Math.floor(Math.random() * (i + 1));
var tmp = this[i];
this[i] = this[j];
this[j] = tmp;
}
return this;
}
function card(s, v) {
this.suit = s;
this.value = v;
this.getvalue = function() {
return (suit.toString() + value.toString());
};
this.getSortOrder = function() {
var factor;
if (this.suit == 'c') {
factor = 0;
}
else if (this.suit == 'd') {
factor = 1;
}
else if (this.suit == 'h') {
factor = 2;
}
else if (this.suit == 's') {
factor = 3;
}
else {
factor = -2;
}
return (this.value + 13 * factor);
};
};
function Cards() {
this.list = new Array();
this.Addcard = function (c) {
list.push(c);
};
this.removeCard = function (c) {
list.splice(list.indexOf(c), 1);
};
this.lookat = function (i) {
return list[i];
};
this.sort = function() {
list.sort();
};
this.shuffle = function() {
list.shuffle();
};
this.prototype;
};
您在javascript開發控制檯中看到錯誤嗎? – Matt
請每個問題提出一個問題。 – 0x499602D2
Stackoverlow用戶不是調試器。 – gdoron