-1
獲得最高兩位變量值和名字,我試圖找出如何從一組數據中得到最高的兩個變量,變量名。這是我爲了獲得第一名而迄今爲止所提出的。從陣列
var one = 5
var two = 6
var three = 5
var four = 10
var five = 2
(或作爲數組:var數組= [一,二,三,四,五]
if (one > two && three && four && five) {
console.log('One Highest')
}
if (two > one && three && four && five) {
console.log('Two Highest')
}
if (three > one && two && four && five) {
console.log('Three Highest')
}
if (four > one && three && two && five) {
console.log('Four Highest')
}
if (five > one && two && four && three) {
console.log('Five Highest')
}
一旦我知道這是最高的我需要能夠把點添加到基於贏家另一個變量...
例子:
if var one is the greatest value {
// add points to var one items
thingOne +50
thingTwo +50
}
if var two is the greatest value {
// add points to var two items
thingThree +50
thingFour +50
}
如果可能的話我也想能夠找到SE cond最高分和var名稱。
感謝您的任何建議!
哪裏陣列 – rlemon
嘗試'Math.max' ... – rassar
@rassar這解決的價值,但我怎麼得到相應的變量名稱? – AndrewLeonardi