【发布时间】:2016-11-17 06:34:17
【问题描述】:
我试图弄清楚如何从一组数据中获取两个最高变量和变量名。到目前为止,这是我试图获得第一高的想法。
var one = 5
var two = 6
var three = 5
var four = 10
var five = 2
(或作为数组:var array = [一、二、三、四、五]
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
}
如果可能的话,我还试图找到第二高的分数和 var 名称。
感谢您的建议!
【问题讨论】:
-
数组在哪里
-
试试
Math.max... -
@rassar 解决了值但是我如何获得相应的var名称?
-
这听起来像是一个 XY 问题。你能描述一下你面临的整个问题吗?为什么要第二高分和 var 名称?
-
@AndrewLeonardi 为什么你首先将它们作为单独的变量来做?只需使用一个数组。
标签: javascript jquery html arrays