如何使用以下说明创建javascript级计算器? [英] How do I create a javascript grade calculator using the directions below?

查看:54
本文介绍了如何使用以下说明创建javascript级计算器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用要求(在评论中)在js中创建一个成绩计算器,但我被卡住了。在审查了一些工作并收集了一些有用的反馈后,我取得了一些进展。



如何让程序询问每个年级,然后在所有成绩后停止输入了吗?



如何将每个等级推入阵列(我有一个推送声明,但我不知道当等级为此时未知)。



提前致谢。



我尝试过:



I'm trying to create a grade calculator in js using the requirements (in comments), but I'm stuck. I've made some progress, after reviewing some work and incorporating some useful feedback.

How can I get the program to ask for each grade and then stop after all grades are entered?

How do I get it to push each grade into the array (I have one push statement but I don't know how this works when the grades are unknown at this point).

Thanks in advance.

What I have tried:

var grades = [];

document.writeln("Welcome to the grade calculator!");

var numClasses = prompt("How many classes are you taking?");

//use a for loop to iterate, one for each class. Prompt for their grade. Store the response in the array grades. Use push method to add the new item to the array.

for (var i = 0; i < numClasses.length; i++){
console.log (numClasses[i]);
}
var question = prompt ("What was your grade in class " + i + "?");

grades.push(i);


//Once all of the grades have been entered and stored in the array, calculate the average grade. First use another for loop to calculate the sum of all grades, then dividing that sum by the number of classes to get the average.

for ( var j = 0; j < grades.length; j ++){
    var avg = (grades[j] / grades.length) * grades.length
}

if (avg < 60) {
document.writeln("Keep studying! Review your notes and work every night.");
}

else if (avg >=60 && < 80) {
document.writeln("Be sure to review your work; you can do it!");
}
else {
document.writeln("Way to go! Keep up the good work."):
}

推荐答案

错误报告:

替换:

Bug report:
replace:
var question = prompt (What was your grade in class " + i + "?")

;

with:

;
with:

var question = prompt ("What was your grade in class " + i + "?");


JavaScript教程 [ ^ ]。


这篇关于如何使用以下说明创建javascript级计算器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆