widerstandsrechner.js 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. var values = ["0", "0", "0", "0", "5"];
  2. function set_number(num, val)
  3. {
  4. values[num] = val;
  5. set_color(num, val);
  6. calculate();
  7. }
  8. function set_color(num, val)
  9. {
  10. var id;
  11. switch(num)
  12. {
  13. case 0:
  14. id = "num1";
  15. break;
  16. case 1:
  17. id = "num2";
  18. break;
  19. case 2:
  20. id = "num3";
  21. break;
  22. case 3:
  23. id = "full_exp";
  24. break;
  25. case 4:
  26. id = "toleranz1";
  27. break;
  28. }
  29. if (num != 4)
  30. {
  31. switch(val)
  32. {
  33. case 0:
  34. document.getElementById(id).className = "black";
  35. break;
  36. case 1:
  37. document.getElementById(id).className = "brown";
  38. break;
  39. case 2:
  40. document.getElementById(id).className = "red";
  41. break;
  42. case 3:
  43. document.getElementById(id).className = "orange";
  44. break;
  45. case 4:
  46. document.getElementById(id).className = "yellow";
  47. break;
  48. case 5:
  49. document.getElementById(id).className = "green";
  50. break;
  51. case 6:
  52. document.getElementById(id).className = "blue";
  53. break;
  54. case 7:
  55. document.getElementById(id).className = "purple";
  56. break;
  57. case 8:
  58. document.getElementById(id).className = "gray";
  59. break;
  60. case 9:
  61. document.getElementById(id).className = "white";
  62. break;
  63. }
  64. }
  65. else
  66. {
  67. switch(val)
  68. {
  69. case 1:
  70. document.getElementById(id).className = "brown";
  71. break;
  72. case 2:
  73. document.getElementById(id).className = "red";
  74. break;
  75. case 5:
  76. document.getElementById(id).className = "gold";
  77. break;
  78. case 10:
  79. document.getElementById(id).className = "silver";
  80. break;
  81. }
  82. }
  83. }
  84. function calculate()
  85. {
  86. document.getElementById("num1").innerHTML = values[0];
  87. document.getElementById("num2").innerHTML = values[1];
  88. document.getElementById("num3").innerHTML = values[2];
  89. document.getElementById("exp").innerHTML = values[3];
  90. document.getElementById("toleranz1").innerHTML =
  91. document.getElementById("toleranz2").innerHTML =
  92. document.getElementById("toleranz3").innerHTML =
  93. document.getElementById("toleranz4").innerHTML =
  94. values[4] + "%";
  95. var num = parseInt(values[0].toString() + values[1].toString() + values[2].toString());
  96. var result = num * Math.pow(10, values[3]);
  97. document.getElementById("result_ohm").innerHTML = result;
  98. document.getElementById("result_kohm").innerHTML = result / 1000;
  99. document.getElementById("result_mohm").innerHTML = result / 1000000;
  100. }