I have the following code, and want to express the max points result in parallel with the winners names (i.e the two couples who got 7), What do i need to do to amend this code at the bottom?
Code:
var contestantNamesArray = ['bob and pete', 'tim and jon', 'mick and alun', 'van and brad', 'chez and jaz'];
var judgesPointsArray = [2,1,5,4,3];
var audiencePointsArray = [4,5,2,3,1];
var combinedPointsArray = new Array (5);
for (var points = 0; points < judgesPointsArray.length; points++)
{
combinedPointsArray[points] = judgesPointsArray[points] + audiencePointsArray[points];
}
var maxPoints = combinedPointsArray[0]
for (var points = 0; points < judgesPointsArray.length; points++)
{
if (combinedPointsArray[points] > maxPoints)
{
maxPoints = combinedPointsArray[points];
}
}
document.write('The maximum number of points was ' + maxPoints + '<BR>')
document.write('The couple(s) scoring the maximum were:' + '<BR>')
{
document.write(contestantNamesArray[maxPoints] );
}
<script type="text/javascript">
var contestantNamesArray = ['bob and pete', 'tim and jon', 'mick and alun', 'van and brad', 'chez and jaz'];
var judgesPointsArray = [2,1,5,4,3];
var audiencePointsArray = [4,5,2,3,1];
var combinedPointsArray = new Array (5);
for (var points = 0; points < judgesPointsArray.length; points++)
{
combinedPointsArray[points] = judgesPointsArray[points] + audiencePointsArray[points];
}
var maxPoints = combinedPointsArray[0];
var winners = [];
for (var points = 0; points < judgesPointsArray.length; points++)
{
if (combinedPointsArray[points] >= maxPoints)
{
if(combinedPointsArray[points] > maxPoints) {winners.length = 0;} // empty array, new max points
winners.push(points); // save the winner
maxPoints = combinedPointsArray[points];
}
}
document.write('The maximum number of points was ' + maxPoints + '<BR>')
document.write('The couple(s) scoring the maximum were:' + '<BR>')
for(var i=0; i<winners.length; i++) {
document.write(contestantNamesArray[winners[i]], '<br>' );
}
</script>
At least 98% of internet users' DNA is identical to that of chimpanzees
<script type="text/javascript">
var contestantNamesArray = ['bob and pete', 'tim and jon', 'mick and alun', 'van and brad', 'chez and jaz'];
var judgesPointsArray = [2,1,5,4,3];
var audiencePointsArray = [4,5,2,3,1];
var maxPoints = 0;
var winners = [];
for (var points = 0; points < judgesPointsArray.length; points++)
{
var temp = judgesPointsArray[points] + audiencePointsArray[points];
if (temp >= maxPoints)
{
if(temp > maxPoints) {winners.length = 0;} // empty array, new max points
winners.push(points); // save the winner
maxPoints = temp;
}
}
document.write('The maximum number of points was ' + maxPoints + '<BR>')
document.write('The couple(s) scoring the maximum were:<BR>')
for(var i=0; i<winners.length; i++) {
document.write(contestantNamesArray[winners[i]], '<br>' );
}
</script>
At least 98% of internet users' DNA is identical to that of chimpanzees
Bookmarks