为什么在这个逻辑问题中我总是得到错误的答案?

时间:2019-06-04 17:12:18

标签: javascript

我需要在Uri Online Judge网站上解决此逻辑问题:

enter image description here

提交的代码以“ var lineParts”开头,我使用var行来处理输入示例:

var lines = ["2.0 4.0 7.5 8.0 6.4"]
/**
 * Code your solution here
 */
var lineParts = lines[0].split(" ");
var n1 = parseFloat(lineParts[0]);
var n2 = parseFloat(lineParts[1]);
var n3 = parseFloat(lineParts[2]);
var n4 = parseFloat(lineParts[3]);
var media = ((n1 * 2) + (n2 * 3) + (n3 * 4) + (n4 * 1)) / 10;

if (media >= 7.0) {
   console.log("Media: " + media);
   console.log("Aluno aprovado.");
} else if (media >= 5.0 && media <= 6.9) {
    console.log("Media: " + media);
    console.log("Aluno em exame.");
    n5 = parseFloat(lineParts[4]);
    console.log("Nota do exame: " + n5);
    novamedia = (media + n5) / 2;
if (novamedia >= 5.0) {
    console.log("Aluno aprovado.");
} else {
    console.log("Aluno reprovado.");
}
    console.log("Media final: " + novamedia);
} else if (media < 5.0) { 
    console.log("Media: " + media);
    console.log("Aluno reprovado.");
}

当我提交此内容时: enter image description here 我得到:答案错误(5%) enter image description here

0 个答案:

没有答案