-2
我正在做一個程序是你在不同的蘇打水寫並將它們與得分率,我掙扎得到它多少分後排序的數組中蘇打水得到了。
的Html
<!DOCTYPE html>
<html>
<head>
<script src = "Assignment08.js"></script>
<meta charset = "utf-8">
</head>
<body>
<h1>Innlevering 8</h1>
<img src="julebrus.jpg" alt="Julebrus" style="width:304px;height:228px;"><br>
Brustype: <input id = "brustype" /><br>
Poeng: <input id = "poeng" /><br>
<input type = "button" value = "Legg til brus" onclick = "leggTilBrus()" />
<b><br>Liste over brus:</b>
<div id = "brusliste"></div>
</body>
</html>
的Javascript
var brusliste = [];
function Brus(sodatype, points) { // Brus = Soda (English)
this.brustype = sodatype;
this.poeng = points;
this.sodainfo = function() {
return this.brustype + " " + this.poeng;
}
}
function leggTilBrus(){
var sodatype = document.getElementById("brustype").value;
var points = document.getElementById("poeng").value;
var sodas = new Brus (sodatype, points);
brusliste.push(sodas);
visArray();
}
function sortFunction(tall1,tall2){
return tall1.verdi-tall2.verdi;
}
function visArray() {
document.getElementById("brusliste").innerHTML = "";
for (var i = 0; i < brusliste.length; i++){
document.getElementById("brusliste").innerHTML += brusliste[i].sodainfo() + "<br />";
}
}
function init() {
var b = new Brus(" ", " ");
console.log(b);
console.log(b.sodainfo());
document.getElementById("brusliste").innerHTML = b.brustype + " <br />";
brusliste.sort(sortFunction);
//brusliste.sort(sorteringsFunksjon());
}
window.onload = init;
我需要寫一些更獲得那個職位是接受X),無論如何,任何幫助將不勝感激。這件事正在讓我的大腦扭曲。
使用算術運算可能會給出錯誤的值。而是使用三元運算符:'a.prop> b.prop? 1:a.prop
Rajesh
'verdi'屬性從哪裏來? – Xufox
verdi屬性來自哪裏?我不確定,只是嘗試在課堂上做的事情。但是當時並沒有真正理解它,所以我現在正在崩潰和燃燒,因爲它現在 – Zuflus