Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

124
Visualizações
Stuck on extracting information from an array in javascript

I have been able to create the array and average but I am running into roadblocks extracting information from the array.

I need to: Loop and find students that failed. Find the student with the highest mark

var numStu = 0;
 
numStu = parseInt(prompt("Please enter the number of students enrolled in the class.")); 

var stuInfo = Array();  
stuInfo[0] = Array(); //  holds student's names
stuInfo[1] = Array(); //  holds marks
stuInfo[2] = Array(); 

for (g = 0; g < numStu; g++) {
    stuInfo[0][g] = prompt("Enter the name of student number " + g + ".");
   stuInfo[1][g] = parseFloat(prompt("Enter the Mult 114 grade " + stuInfo[0][g] + "."));
 
}
    
document.writeln("<table border='1' width='50%'>")
document.writeln("<tr><th>Name</th><th>Chem</th></tr>")
 
for (row = 0; row < numStu; row++) {
    document.writeln("<tr>");
    document.writeln("<td>");
    document.writeln(stuInfo[0][row]); //Student names
    document.writeln("</td>");
    document.writeln("<td>");
    document.writeln(stuInfo[1][row]); //Student marks
    document.writeln("</td>");
      
}
 
document.writeln("</table>")  

var sum = 0;  
for (mult = 0; mult < numStu; mult++) {
    sum = sum + stuInfo[1][mult];  
}
var avg1 = sum / numStu; // Calculate chem averages
document.writeln("<p>The class average: " + avg1 + " percent.");

I was trying to add code as below to extract - but it crashes on me. Any assistance would be greatly appreciated.

var gradeVal = 0;

var gradeIndex = -1;


for (var i = 0; i <= stuInfo.length; i++) {

  if(stuInfo[i] > gradeVal) {
  
  gradeVal = stuInfo[i];
  gradeIndex = i;
  }
  else {

    }
}

document.writeln("the highest score is " + gradeVal +);
document.writeln("the student is " + stuInfo[gradeIndex] +);

Thanks

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Maximum value

const maxScore = (data) => {
    let max = data.length > 0 ? data[0] : unedfined;

    for (let i = 1; i < data.length; i++) {
        if (data[i] > max) max = data[i];
    }

    return max;
};

Minimum value

const minScore = (data) => {
    let min = data.length > 0 ? data[0] : unedfined;

    for (let i = 1; i < data.length; i++) {
        if (data[i] < min) min = data[i];
    }

    return min;
};
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda