2016-10-05 62 views
-4

所以我必須從提示中獲得成績,然後生成一個警告框,用switch語句說明關於成績的一些信息。這是我迄今爲止,但它只是告訴我,回來我給它,如果我在底部開關語句的等級Javascript

var grade = prompt("What grade did you get for the assessment?"); 

switch(grade) { 
    case 0: "A" = ("Excellent"); break; 
    case 1: "B" = "Very Good"; break; 
    case 2: "C" = "Good"; break; 
    case 3: "D" = "Pass"; break; 
    case 4: "E" = "Almost a pass"; break; 
    case 5: "F" = "Fail"; break; 
    default : "Please enter a grade from A-F"; 
} 
+0

而你的問題是? – j08691

+0

你的問題是什麼? – Andy

+0

您似乎無法理解switch語句的語法。谷歌它並查找它。 – Xufox

回答

0

你的switch語句添加一個警告框檔次有點搞砸了。

我不會發布完整的代碼給你。我總是覺得打字,而不是複製/粘貼有助於學習和記憶保持,雖然你要尋找更多的東西像這樣的小:

var grade = prompt("What grade did you get for the assessment?"); 
var result; // this will hold a result from our switch 

switch(grade){ 
case "A": // this is what will be typed (case sensitive) 
    result = "Excellent"; // assign some text to result - no brackets 
    break; 
case "B": // this is what will be typed (case sensitive) 
    result = "Very good"; 
    break; 
default: 
    result = "please enter.." //something wasn't matched 
} 
console.log(result); // spits out the result var 

打破開關向下:

switch(yourVar) 

你yourVar傳遞給開關進行評估

case "D": 
// 
break; 

yourVar ==「d」盡一切情況,並打破

之間
default: 
//.. 

當沒有匹配使用默認情況下的任何內容。

0
var grade = prompt("What grade did you get for the assessment?"); 

var message; 

switch (grade) { 
    case "A": 
     message = "Excellent"; 
     break; 

    case "B": 
     message = "Very Good"; 
     break; 

    case "C": 
     message = "Good"; 
     break; 

    case "D": 
     message = "Pass"; 
     break; 

    case "E": 
     message = "Almost a pass"; 
     break; 

    case "F": 
     message = "Fail"; 
     break; 

    default: 
     message = "Please enter a grade from A-F"; 
} 

alert(message);