# Posted By

stavelin on 01/06/12

# Statistics

Viewed 578 times
Favorited by 0 user(s)

# swtich with range in javascript

/ Published in: JavaScript

na

Copy this code and paste it in your HTML
1. function GetOpacity(value)
2. {
3. var result;
4. switch (true)
5. {
6. case (value == 0):
7. result = 0;
8. break;
9. case ((value >= 0) && (value <= 1)): // "Between 1 and 25."
10. result = 0.1;
11. break;
12. case ((value >= 1) && (value <= 2)): // "Between 1 and 25."
13. result = 0.2;
14. break;
15. case ((value >= 2) && (value <= 3)): // "Between 1 and 25."
16. result = 0.25;
17. break;
18. case ((value >= 3) && (value <= 4)): // "Between 1 and 25."
19. result = 0.3;
20. break;
21. case ((value >= 5) && (value <= 10)): //"Between 26 and 50."
22. result = 0.5;
23. break;
24. case ((value >= 10) && (value <= 15)): //"Between 26 and 50."
25. result = 0.6;
26. break;
27. case ((value >= 16) && (value <= 50)): //"Between 26 and 50."
28. result = 0.7;
29. break;
30. case ((value >= 51) && (value <= 75)): // "Between 51 and 75."
31. result = 0.8;
32. break;
33. case ((value >= 76) && (value <= 100)): //"Between 76 and 100."
34. result = 1;
35. break;
36. default:
37. result = 0;
38. break;
39. }
40. return result;
41. }