简体   繁体   English

javascript中提示框出现问题

[英]Trouble with prompt boxes in javascript

I am new to Javascript and I am having trouble with my assignment. 我是Java语言的新手,我在分配作业时遇到麻烦。 I was told to create a simple "Grade Calculator" using prompt boxes It was fairly easy to make this "Grade Calculator" but the problem I am facing is that I was told to create this "Grade Calculator" in a manner that if someone fails in a subject they fail in all subjects(No Grade) and if someone scores passing marks(50) on all subjects they should be able to see their grade so the problem is that I get the overall result two times like if someone passes in all subjects it works just fine but if someone fails in one subject it shows that the person has failed(NO GRADE) and then shows that they have passed and shows their grade. 有人告诉我使用提示框创建一个简单的“成绩计算器”制作此“成绩计算器”非常容易,但是我面临的问题是,有人告诉我要以一种失败的方式创建“成绩计算器”在某个科目中,他们在所有科目中均不及格(无成绩),并且如果某人在所有科目中均获得及格分数(50),则他们应该能够看到其成绩,因此问题是我两次获得总体成绩,就像某人在所有科目中都通过主题,它工作得很好,但是如果某人在某门学科上不及格,则表明该人已经失败了(没有成绩),然后表明他们已经通过并显示了其成绩。 I hope I explained it correctly. 我希望我能正确解释。 Thanks PS: I can only use prompt boxes and sorry for my bad grammar/punctuation. 谢谢PS:我只能使用提示框,对不起我的语法/标点符号不好。

<!doctype html> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> </head> <body> <script>
var sub1 = parseInt( prompt("Insert Your sub1 Marks") );
var sub2 = parseInt( prompt("Insert Your sub2 Marks") );
var sub3 = parseInt( prompt("Insert Your sub3 Marks") );
var sub4 = parseInt( prompt("Insert Your sub4 Marks") );
var sub5 = parseInt( prompt("Insert Your sub5 Marks") );
var tot = parseInt(sub1+sub2+sub3+sub4+sub5);
 var per = parseInt(((tot)/500)*100)
 alert('Total: ' + tot + ' Out Of 500');
 alert('Percentage: ' + per + '%' );
 if(sub1<=49){
 alert('Fail --NO GRADE--');
 }
 if(sub2<=49){
 alert('Fail --NO GRADE--');
 }
 if(sub3<=49){
 alert('Fail --NO GRADE--');
 }
 if(sub4<=49){
 alert('Fail --NO GRADE--');
 }
 if(sub5<=49){
 alert('Fail --NO GRADE--');
 }
 else if(per >=50 && per <60) {
 alert('Pass --D Grade--');
 }
 else if(per >=60 && per <70) {
 alert('Pass --C Grade--');
 }
 else if(per >=70 && per <80) {
 alert('Pass --B Grade--');
 }
 else if(per >=80 && per <90) {
 alert('Pass --A Grade--');
 }
 else if(per >=90 && per <100) {
 alert('Pass --A* Grade--');
 }
</script> </body> </html>

I am not sure what you use to work with JavaScript, to test your solutions, but JSFiddle is great. 我不确定您使用JavaScript来测试解决方案的方式,但是JSFiddle很棒。 Here is your working solution . 这是您的工作解决方案

if(sub1<=49 || sub2<=49 || sub3<=49 || sub4<=49 || sub5<=49){
 alert('Fail --NO GRADE--');
 }
 else if(per >=50 && per <60) {

Another way is to use SO code snippets, see below. 另一种方法是使用SO代码段,请参见下文。

 var sub1 = parseInt( prompt("Insert Your sub1 Marks") ); var sub2 = parseInt( prompt("Insert Your sub2 Marks") ); var sub3 = parseInt( prompt("Insert Your sub3 Marks") ); var sub4 = parseInt( prompt("Insert Your sub4 Marks") ); var sub5 = parseInt( prompt("Insert Your sub5 Marks") ); var tot = parseInt(sub1+sub2+sub3+sub4+sub5); var per = parseInt(((tot)/500)*100) alert('Total: ' + tot + ' Out Of 500'); alert('Percentage: ' + per + '%' ); if(sub1<=49 || sub2<=49 || sub3<=49 || sub4<=49 || sub5<=49){ alert('Fail --NO GRADE--'); } else if(per >=50 && per <60) { alert('Pass --D Grade--'); } else if(per >=60 && per <70) { alert('Pass --C Grade--'); } else if(per >=70 && per <80) { alert('Pass --B Grade--'); } else if(per >=80 && per <90) { alert('Pass --A Grade--'); } else if(per >=90 && per <100) { alert('Pass --A* Grade--'); } 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM