Advertisement
Guest User

Untitled

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