javascript - How do I alert the result in this case statement? -


i realize has case thing how fix or suggest better way final product want nice

function main()  {      var a;     var answer;     = prompt("test score 1 out of 20", a);     var b;     b = prompt("test score 2 out of 20", b);     var c;     c = prompt("test score 3 out of 20", c);     answer = parseint(a,10) + parseint(b,10) + parseint(c,10);     switch(answer)     {         case "answer >= 52":             alert("you got a");             break;         case "answer >= 42":             alert("you got b");             break;         case "answer >= 33":             alert("you got c");             break;         case "answer <= 32":             alert("you got d");             break;           default:             alert("failed");             break;     } } 

instead of strange switch block, use

if (answer >= 52) {    alert("you got a"); } else if (answer >= 42) {    alert("you got b"); } else if ... 

there many other ways it, example array storing thresholds, 1 works , simple.


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -