2014-02-27 16 views
0

什麼,我需要做的: 我需要建立一個程序,它會要求用戶輸入他們的牌號爲 1)分配1 - 25points 2)assignment2 - 25points 3)assignment3 - 25points 4 )assighment4 - 25points 5)exam1 - 100分 6)最終考試 - 100分 7)最後的項目 - 100分的Javascript分配有我難倒

總點數爲所有的指配的是由此400點

不允許用戶輸入負分數,而他們不是允許輸入高於可能的任務總分限制的分數。在輸入所有分數後,我將以百分比和字母等級顯示分數。

目前爲止的工作內容: 該計劃不會接受否定結果或任何高於可能的任務設定限制的等級。我無法獲得「輸入有效分數(0-max)」消息,因此我放棄了該功能,而是在輸入適當的值之前程序纔會向前移動。另外我可以顯示百分比。但是一旦你看了代碼,你會發現程序實際上並沒有計算百分比,它只是計算(總和/總數)* 100後來我做了一個document.writeln,我只是簡單地添加一個「%」符號。我發現這樣更容易。

我無法上班: 我無法得到該死的信等級。我知道,因爲我將字母等級設置爲特定的範圍(例如93.9%-90%是A-),所以我應該使用if語句,但我不確定我是否做得對,我還設置了一個名爲「letter」的變量,我試圖給出A,A,B +,B,B-等等的值,這取決於學生跌倒的範圍。我無法得到這個工作。

這是我的代碼,任何幫助將不勝感激。

我在這裏有一點問題。

我可以得到程序來總結所有的成績,然後除以總數,從而給我一個百分比,並在運行程序時顯示出來。我似乎無法做到的是顯示字母等級。

到目前爲止,我有if語句和一個名爲letter的變量,我試圖插入到代碼中看到的第一個document.writeln中,但是當我嘗試使用此變量並運行程序時屏幕變白。沒有任何提示輸入分數,什麼也沒有,只是變成了白色。

我以爲這是一個問題,我做了if語句,但我不知道。

這裏是我的代碼,一些幫助,將不勝感激

<!DOCTYPE html> 
<html> 
    <head> 
     <meta charset = "utf-8"> 
     <Title>Final Grade Calculation</Title> 
     <script type = "text/javascript"> 
      var assignment1; 
      var assignment2; 
      var assignment3; 
      var assignment4; 
      var exam1; 
      var finalexam; 
      var finalproject; 
      // the above variables represent the assignments, exams, and project. 
      // the following lines of code will ask the user to enter their scores. We will also try 
      // to make sure that the user is not entering negative numbers, or numbers above the max set of points possible for each 
      //assignment. Eash assignment is worth 25 points 
      //exams are 100 
      //and the final project is 100 as well, the total points possible should then be no more than 400 
      //before we begin to prompt the user to enter their scores we will also declare a few more variables 
      var a1; //assignment 1 
      var a2; //assignment 2 
      var a3; //assignment 3 
      var a4; //assignment 4 
      var e1; //exam1 
      var ef; //final exam 
      var fp; //final project 
      var g; //is going to be ((a1+a2+...fp)/tp) 
      var tp = 400; //total possible points 
      var letter; 
      //the following loops ensure that the user can only enter scores that fall withing the acceptable range for each respective assignment 
      //assignments have a min of 0, and a max of 25 
      //exam1 has a min of 0, and a max of 100 
      //finalexam has a min of 0 and a max of 100 
      //final project has a min of 0 and a max of 100 
      //if there is no score entered into the prompt then the variable for the respective assignment is 0 by default. 


      do 
      { 
       assignment1=window.prompt("Enter your score for assignment 1"); 
       a1=parseInt(assignment1); 
       //window.alert("Invalid Score entered"); 
      } 
      while (a1 < 0 || a1 > 25) 
      if (assignment1=null) 
      a1=0 


      do 
      { 
       assignment2=window.prompt("Enter your score for assignment 2"); 
       a2=parseInt(assignment2); 
       //window.alert("Invalid Score entered"); 
      } 
      while (a2 < 0 || a2 > 25) 
      if (assignment2=null) 
      a2=0 

      do 
      { 
       assignment3=window.prompt("Enter your score for assignment 3"); 
       a3=parseInt(assignment3); 
       //window.alert("Invalid Score entered"); 
      } 
      while (a3 < 0 || a3 > 25) 
      if (assignment1=null) 
      a3=0 

      do 
      { 
       assignment4=window.prompt("Enter your score for assignment 4"); 
       a4=parseInt(assignment4); 
       //window.alert("Invalid Score entered"); 
      } 
      while (a4 < 0 || a4 > 25) 
      if (assignment4=null) 
      a4=0 

      do 
      { 
       exam1=window.prompt("Enter your score for exam 1"); 
       e1=parseInt(exam1); 
       //window.alert("Invalid Score entered"); 
      } 
      while (e1 < 0 || e1 > 100) 
      if (exam1=null) 
      e1=0 

      do 
      { 
       finalexam=window.prompt("Enter your score for the final exam"); 
       ef=parseInt(finalexam); 
       //window.alert("Invalid Score entered"); 
      } 
      while (ef < 0 || ef > 100) 
      if (finalexam=null) 
      ef=0 

      do 
      { 
       finalproject=window.prompt("Enter your score for the final project"); 
       fp=parseInt(finalproject); 
       //window.alert("Invalid Score entered"); 
      } 
      while (fp < 0 || fp > 100) 
      if (finalproject=null) 
      fp=0 

      // g is the variable which will be representing the final grade. 
      //is will give us a decimal as an answer 
      g = ((a1+a2+a3+a4+e1+ef+fp)/tp)*100 
      document.writeln("<h1>Your final score is " + g.toFixed(2) +"%</h>"); //we convert the decimal into a percentage, not really though 
      //the percentage displayed is only superficial, to be honest I was getting frustrated trying to find a way to make real percents 
      //the following if's will assign letter grades to a range of decimals. 



      if (g>=94) 
      {letter="A"} 
      else if (g>=93.90 || g<=90.00) 
      {letter="A-"} 
      else if (g>=89.90 || g<=87.00) 
      {letter="B+"} 
      else if (g>=86.90 || g<=84.00) 
      {letter="B"} 
      else if (g>=83.90 || g<=80.00) 
      {letter="B-"} 
      else if (g>=79.90 || g<=77.00) 
      {letter="C+"} 
      else if (g>=76.90 || g<=74.00) 
      {letter="C"} 
      else if (g>=73.90 || g<=70.00) 
      {letter="C-"} 
      else if (g>=69.90 || g<=67.00) 
      {letter="D+"} 
      else if (g>=63.90 || g<=60.00) 
      {letter="D-"} 
      else 
      {letter="F"}; 

      document.writeln("<h1> Your grade is " + letter "</h1>"); 
     </script>  
    </head> 
</html> 
+0

文件。writeln(「

你的成績是」+字母「

」);在字母和結束標記之間缺少一個+號。即document.writeln(「

你的等級是」+字母+「

」); –

回答

0

你錯過了+來連接字符串

document.writeln("<h1> Your grade is " + letter "</h1>"); 

應該比

document.writeln("<h1> Your grade is " + letter + "</h1>"); 

其他它工作正常:http://jsfiddle.net/fqv9t/(document.write取代提琴小提琴)

+0

感謝您的反饋,我添加了+和我的工作,現在我只是需要它來顯示適當的字母等級..不能得到任何東西比A-我想我的If語句都搞砸了。 – internetmexican