Advertisement
Guest User

Untitled

a guest
Jan 24th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width">
  6. <title>JS Bin</title>
  7. </head>
  8. <body>
  9.  
  10. <script id="jsbin-javascript">
  11. function celsToFahr(celsTemp) {
  12. return celsTemp * 1.8 + 32;
  13. }
  14.  
  15. function fahrToCels(fahrTemp) {
  16. return (fahrTemp - 32) / 1.8;
  17. }
  18.  
  19.  
  20.  
  21. /* From here down, you are not expected to
  22. understand.... for now :)
  23.  
  24.  
  25. Nothing to see here!
  26.  
  27. */
  28.  
  29.  
  30.  
  31. // tests
  32.  
  33. function testConversion(fn, input, expected) {
  34. if (fn(input) === expected) {
  35. console.log('SUCCESS: `' + fn.name + '` is working');
  36. return true;
  37. }
  38. else {
  39. console.log('FAILURE: `' + fn.name + '` is not working');
  40. return false;
  41. }
  42. }
  43.  
  44. function testConverters() {
  45. var cel2FahrInput = 100;
  46. var cel2FahrExpect = 212;
  47. var fahr2CelInput = 32;
  48. var fahr2CelExpect = 0;
  49.  
  50. if (testConversion(celsToFahr, cel2FahrInput, cel2FahrExpect) &&
  51. testConversion(fahrToCels, fahr2CelInput, fahr2CelExpect)) {
  52. console.log('SUCCESS: All tests passing');
  53. }
  54. else {
  55. console.log('FAILURE: Some tests are failing');
  56. }
  57. }
  58.  
  59. testConverters();
  60. </script>
  61.  
  62.  
  63.  
  64. <script id="jsbin-source-javascript" type="text/javascript">function celsToFahr(celsTemp) {
  65. return celsTemp * 1.8 + 32;
  66. }
  67.  
  68. function fahrToCels(fahrTemp) {
  69. return (fahrTemp - 32) / 1.8;
  70. }
  71.  
  72.  
  73.  
  74. /* From here down, you are not expected to
  75. understand.... for now :)
  76.  
  77.  
  78. Nothing to see here!
  79.  
  80. */
  81.  
  82.  
  83.  
  84. // tests
  85.  
  86. function testConversion(fn, input, expected) {
  87. if (fn(input) === expected) {
  88. console.log('SUCCESS: `' + fn.name + '` is working');
  89. return true;
  90. }
  91. else {
  92. console.log('FAILURE: `' + fn.name + '` is not working');
  93. return false;
  94. }
  95. }
  96.  
  97. function testConverters() {
  98. var cel2FahrInput = 100;
  99. var cel2FahrExpect = 212;
  100. var fahr2CelInput = 32;
  101. var fahr2CelExpect = 0;
  102.  
  103. if (testConversion(celsToFahr, cel2FahrInput, cel2FahrExpect) &&
  104. testConversion(fahrToCels, fahr2CelInput, fahr2CelExpect)) {
  105. console.log('SUCCESS: All tests passing');
  106. }
  107. else {
  108. console.log('FAILURE: Some tests are failing');
  109. }
  110. }
  111.  
  112. testConverters();
  113. </script></body>
  114. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement